在linux服务器中对R语言中for循环设置多核运行

1 问题

在R中构建了for循环,由于循环过多,运行速度过慢,且不同循环之间是并行关系,拟通过多核运行可以解决此问题。

2 代码设置

2.1 shell脚本中的设置

b.sh

export OPENBLAS_NUM_THREADS=8

Rscript ./..._1.R \

2.2 R代码中的设置

library(parallel)
fun <- function(i){
  a  <- coordinate_file[i,4]
  }

detectCores(logical = F)  
mc <- getOption("mc.cores", 70)  # 设置核数,根据需要设置70
mclapply(1:37987, fun, mc.cores = mc)
stopCluster(mc)

2.3 shell脚本运行

应以nohup运行,防止网络断掉

nohup sh b.sh >out 2>err &

在这里插入图片描述

参考

多核运行:
1、https://www.cnblogs.com/ywliao/articles/6681781.html/
2、https://blog.csdn.net/u012252959/article/details/116201536

OPENBLAS_NUM_THREAD
1、https://blog.csdn.net/u012110870/article/details/106115577
2、https://cloud.tencent.com/developer/article/1880367

kill nohup进程
1、https://blog.csdn.net/geol200709/article/details/91539025

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

紫霄zixiao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值