5

I have this code for writing my results in parallel. I am using foreach and doParallel libraries in R.

    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()
    }

Now it uses 4 cores in the CPU and thus the writing takes very less time using this code.But i want foreach-doparallel using GPU. Is there any method for processing the foreach doParallel loop on GPU. gputools,gpuR are some GPU supporting R packages. But they are mainly for mathematical computations like gpuMatMult(),gpuMatrix() etc. I am looking for running the loop on GPU. Any help or guidance will be great.

9113303
  • 852
  • 1
  • 16
  • 30

1 Answers1

5

Parallelization with foreach or similar tools works because you have multiple CPUs (or a CPU with multiple cores), which can process multiple tasks at once. A GPU also has multiple cores, but these are already used to process a single task in parallel. So if you want to parallelize further, you will need multiple GPUs.

However, keep in mind that GPUs are faster than CPUs only for certain types of applications. Matrix operations with large matrices being a prime example! See the performance section here for a recent comparison of one particular example. So it might make sense for you to consider if the GPU is the right tool for you.

In addition: File IO will always go via the CPU.

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75