I'm getting the titular error:
mcfork(): Unable to fork: Cannot allocate memory
after trying to run a function with mcapply, but top
says I'm at 51%
This is on an EC2 instance, but I do have up-to-date R.
Does anyone know what else can cause this error?
Thanks,
-N
The issue might be exactly what the error message suggests: there isn't enough memory to fork and create parallel processes.
R essentially needs to create a copy of everything that's in memory for each individual process (to my knowledge it doesn't utilize shared memory). If you are already using 51% of your RAM with a single process, then you don't have enough memory to create a second process since that would required 102% of your RAM in total.
Try:
registerDoMC(2)
, for example, will set the number of parallel threads to 2 (if you are using the doMC
parallel backend). rm(my_big_object)
)