小编911*_*303的帖子

GPU 上的 foreach doparallel

我有这段代码可以并行编写我的结果。我在 R 中使用foreachdoParallel库。

    output_location='/home/Desktop/pp/'
    library(foreach)
    library(doParallel)
    library(data.table)

    no_cores <- detectCores()
    registerDoParallel(makeCluster(no_cores))
    a=Sys.time()

    foreach(i=1:100,.packages = c('foreach','doParallel')
    ,.options.multicore=mcoptions)%dopar% 
    {result<- my_functon(arg1,arg2)
    write(result,file=paste(output_location,"out",toString(i),".csv"))
    gc()
    }
Run Code Online (Sandbox Code Playgroud)

现在它在 CPU 中使用 4 个内核,因此使用此代码编写所需的时间非常少。但我想要使用 GPU 进行 foreach-doparallel。是否有任何方法可以在 GPU 上处理foreach doParallel循环。gputools,gpuR是一些支持 R 的 GPU 包。但它们主要用于数学计算,如 gpuMatMult()、gpuMatrix() 等。我正在寻找在 GPU 上运行循环。任何帮助或指导都会很棒。

foreach gpu r doparallel

4
推荐指数
1
解决办法
1767
查看次数

通过传递参数从 python 代码调用 R 函数

rtest = function(input ,output) {
  a <- input
  b <- output 
  outpath <- a+b
  print(a+b)
  return(outpath)
}
Run Code Online (Sandbox Code Playgroud)

我刚刚返回这个 R 代码作为获取两个数字之和的函数。我尝试使用 subprocess 通过传递 2 个数字作为参数来从我的 python 代码运行此函数。但它不返回总和值作为返回输出。你知道在 python3 中通过传递函数参数来实现这一点的方法吗?

我使用子进程的Python代码是:

args=['3','10'] # (i tried to pass aruments like this) 
command="Rscript" 
path2script = '/...path/rtest.R' 
cmd = [command, path2script] +args 
x = subprocess.check_output(cmd, universal_newlines=True) 
print(x)
Run Code Online (Sandbox Code Playgroud)

但 x 返回 ' ' 空值

r python-3.x

3
推荐指数
1
解决办法
6448
查看次数

所有多线程程序都在 GPU 上运行吗?

import numpy as np
np.random.seed(1)
import rpy2.robjects as ro
import time
import threading
filename='your/filename'
path='specify/path'

output_location='specify/output/location'


def function1(arg1,arg2):
    r=ro.r
    r.source(path+"analysis.R")  #invoking R program
    p=r.analysis(arg1,arg2) #calling the R function
    return p


threads=[]


  for i in range(100):
      t1=threading.Thread(target=function1,name='thread{}'.format(i),args=(arg1,arg2))
      t1.start()
      threads.append(t1)
      print('{} has started \n'.format(t1.name))

for i in threads:   # to know threads used
    i.join()
Run Code Online (Sandbox Code Playgroud)

rpy2 用于通过 python 调用我的 R 代码。现在它使用 100 个线程。这个多线程进程是否使用GPU?我认为目前它正在CPU上运行。这可以从系统监视器中识别出来。但是如果我使用 1000 个线程,那么它使用 CPU 还是 GPU?

python multithreading gpu python-3.x

3
推荐指数
1
解决办法
3440
查看次数

如何通过传递参数从 C++ 调用 R 函数

我正在尝试从 C++ 程序调用我的 R 函数。

rtest = function(input ,output) {
  a <- input
  b <- output 
  outpath <- a+b
  print(a+b)
  return(outpath)
}
Run Code Online (Sandbox Code Playgroud)

这是我的 R 函数。我需要找到一种通过传递参数从 C 调用此函数的方法。通过传递参数从 python 代码调用 R 函数。这里我做了类似的方法从Python调用R。所以我需要指定 R 脚本的路径和函数的名称,并且还能够通过 python 传递参数。我正在C中寻找类似的方法,但没有得到结果。这可能是一件简单的事情。任何帮助表示赞赏。

c c++ r

1
推荐指数
1
解决办法
1967
查看次数

标签 统计

r ×3

gpu ×2

python-3.x ×2

c ×1

c++ ×1

doparallel ×1

foreach ×1

multithreading ×1

python ×1