4

I have tried using the parallel package to run a simple parallelization in R on my Windows 10 laptop, but when it gets to the makeCluster function it just hangs there. I tried running on the GUI, different number of cores, changing the settings on windows firewall and using the snow package, but to no avail.

This is the code I've been using:

library(doParallel) # basic parallelization package
ncore <- detectCores(logical = TRUE) # detect number of cores
cl <- makeCluster(ncore - 1, type = "PSOCK") # create clusters of ncore - 1

Does anyone that faced a similar problem know how to solve this? Thank you so much for the help!

Edit: As suggested, here is an excerpt of a log file for the running code. I tried looking into the error shown, but had no success:

=========================================================================
Log Path: ./log/script.log
Working Directory: 
User Name:
R Version: 4.1.2 (2021-11-01)
Machine: PC x86-64
Operating System: Windows >= 8 x64 build 9200
Log Start Time: 2021-11-14 16:28:41
=========================================================================

Testing makeCluster

NOTE: Log Print Time:  2021-11-14 16:28:41
NOTE: Elapsed Time in seconds: 0.00299715995788574

Error in makePSOCKcluster(names = spec, ...) : 
  Cluster setup failed. 3 of 3 workers failed to connect.


NOTE: Log Print Time:  2021-11-14 16:32:44
NOTE: Elapsed Time in seconds: 4.05511613289515

Error in print(x, ...) : object 'cl' not found


NOTE: Log Print Time:  2021-11-14 16:32:44
NOTE: Elapsed Time in seconds: 0.0109848976135254

=========================================================================
Log End Time: 2021-11-14 16:32:44
Log Elapsed Time: 0 00:00:04
=========================================================================
  • Can't duplicate the problem. Try reinstalling the `parallel` package. – Brian Montgomery Nov 13 '21 at 04:33
  • Have you tried the same with `detectCores(logical = FALSE)`? I've never had it hang, but I don't get much speed pickup with logical cores. – Brian Montgomery Nov 13 '21 at 04:35
  • Thank you for your reply! I tried your suggestions, but the problem persists. I have used this code on different computers and it works on most of them. I'm trying to figure out what is causing it to not work on only some of them (including mine). – Luis Henrique Linhares Nov 13 '21 at 12:34
  • Can you try setting a log file for `makeCluster`, it should be a keyword argument. With that output we might see what error is printed. – genauguy Nov 13 '21 at 17:39
  • I noticed makeCluster would hang for me if my working directory was on a network drive, but it would work fine if the working directory was local. I wonder if you're seeing the same thing? – Andreas Oct 18 '22 at 20:07

1 Answers1

0

I was experiencing the same problem in R 4.0.4. makeCluster(ncore - 1, type = "SOCK") function was just hanging there (type="PSOCK" does not work on R 4.0.4). Try replacing the code with parallel::makePSOCKcluster(ncore - 1). I hope that works in your code, too.

Mehmet Yildirim
  • 471
  • 1
  • 4
  • 17