Skip to content
Prev 1971 / 2152 Next

I can do mpi.apply but not foreach with doMPI

Since you are running in batch, consider using the SLURM cluster the way
it was designed to be used: SPMD style. Below is a simple code inspired by
your examples that does a sort to find the bottom 10 numbers.

library(pbdMPI, quiet=TRUE)
init()

a <- sort(runif(1e7))[1:10]
comm.print(a, all.rank=TRUE)

b <- as.numeric(unlist(gather(a)))
c <- sort(b)[1:10]
comm.print(c)

finalize()

Here is how I run the code in serial:


-bash-4.1$ time Rscript bottomten.r
COMM.RANK = 0
 [1] 2.596062e-07 3.082678e-07 3.138557e-07 6.444753e-07 7.168856e-07
 [6] 7.280615e-07 1.073349e-06 1.138775e-06 1.226086e-06 1.244014e-06
COMM.RANK = 0
 [1] 2.596062e-07 3.082678e-07 3.138557e-07 6.444753e-07 7.168856e-07
 [6] 7.280615e-07 1.073349e-06 1.138775e-06 1.226086e-06 1.244014e-06


real	0m5.047s
user	0m4.734s
sys	0m0.157s

And now a parallel run on 8 cores:

-bash-4.1$ time mpirun -np 8 Rscript bottomten.r
COMM.RANK = 0
 [1] 1.641456e-07 2.663583e-07 7.601921e-07 1.008157e-06 1.064735e-06
 [6] 1.178822e-06 1.366483e-06 1.381151e-06 1.406297e-06 1.461012e-06
COMM.RANK = 1
 [1] 3.492460e-08 6.798655e-08 1.867302e-07 3.015157e-07 3.234018e-07
 [6] 3.348105e-07 4.756730e-07 5.729962e-07 5.888287e-07 6.936025e-07
COMM.RANK = 2
 [1] 1.094304e-07 1.136214e-07 2.984889e-07 3.867317e-07 6.183982e-07
 [6] 8.104835e-07 9.895303e-07 1.240522e-06 1.284061e-06 1.376960e-06
COMM.RANK = 3
 [1] 3.050082e-08 6.728806e-08 8.335337e-08 4.125759e-07 5.690381e-07
 [6] 6.437768e-07 1.186039e-06 1.340872e-06 1.558103e-06 1.562294e-06
COMM.RANK = 4
 [1] 4.889444e-09 1.490116e-08 1.576264e-07 1.578592e-07 1.718290e-07
 [6] 1.958106e-07 2.747402e-07 7.252675e-07 9.618234e-07 9.881333e-07
COMM.RANK = 5
 [1] 1.862645e-08 6.728806e-08 1.268927e-07 1.578592e-07 2.654269e-07
 [6] 3.289897e-07 3.348105e-07 6.000046e-07 6.633345e-07 7.471536e-07
COMM.RANK = 6
 [1] 1.394656e-07 2.512243e-07 2.977904e-07 3.096648e-07 3.606547e-07
 [6] 6.635674e-07 1.054723e-06 1.059147e-06 1.180219e-06 1.305714e-06
COMM.RANK = 7
 [1] 1.785811e-07 1.816079e-07 2.454035e-07 3.625173e-07 4.067552e-07
 [6] 4.153699e-07 4.447066e-07 4.516915e-07 4.768372e-07 5.601906e-07
COMM.RANK = 0
 [1] 4.889444e-09 1.490116e-08 1.862645e-08 3.050082e-08 3.492460e-08
 [6] 6.728806e-08 6.728806e-08 6.798655e-08 8.335337e-08 1.094304e-07


real	0m5.847s
user	0m40.735s
sys	0m2.358s

Note that real time barely increased even though we did about 8 times the
work. User time reflects the actual total CPU time added across the 8
cores. The communication operation is gather(), which gathers its argument
to rank 0 by default. See the pbdDEMO package for other examples.

George



-----Original Message-----
From: R-sig-hpc <r-sig-hpc-bounces at r-project.org> on behalf of Seija
Sirki? <seija.sirkia at csc.fi>
Date: Wednesday, August 26, 2015 at 4:12 AM
To: <r-sig-hpc at r-project.org>
Subject: [R-sig-hpc] I can do mpi.apply but not foreach with doMPI