Skip to Content

Problem with R running in parallel doMC, foreach, and multicore packages

I am conducting a simulation using R on a linux server with two 64-bit quad-core Intel Xeon (24 compute nodes) with doMC, multicore, and foreach packages to run R in parallel with following specifications in my programme

options(cores = 8)

I test my R programme with 10 runs using two ways

  1. interactivel mode (copy the programme and paste into R directly)

  2. batch mode (issuing a command source("simul.r"))

For interactive mode, the programme runs fine and produces all the results for 10 runs. But for the batch mode, the programme stops at the 9th run with the following error message in R.

I use cat("Working on simulation:",i,"\n") in theforeach loop to monitor the simulation run

Working on simulation:  7
Working on simulation:  1
Working on simulation:  8
Working on simulation:  3
Working on simulation:  4
Working on simulation:  6
Working on simulation:  2
Working on simulation:  5
Error in { : task 9 failed - "cannot open the connection"

If I were to reduce to 5 runs, the batch mode works fine.

I don't quite understand the nature of this error message. Any help would be much appreciated.