title: How to force idle workers to take jobs in parallel R?
body: <p>I am new to posting here--I searched and couldn't find an answer to my question.  I have run the following R parallelized code (from a <a href="http://librestats.com/2012/03/15/a-no-bs-guide-to-the-basics-of-parallelization-in-r/" rel="nofollow noreferrer">blog</a> on parallel computing in R) using the <code>parallel</code> package on two different machines and yet get very different process time results.   The first machine is a Lenovo laptop with Windows 8, 8GB RAM, Intel i7, 2 cores/4 logical processors.   The second machine is a Dell desktop, Windows 7, 16GB RAM, Intel i7, 4 cores/8 logical processors.  The code sometimes runs much slower on the second machine.  I believe the reason is that the second machine is not using the worker nodes to complete the task.  When I use the function snow.time() from the <code>snow</code> package to check node usage, the first machine is using all available workers to complete the task.  However, on the more powerful machine, it never uses the workers--the entire task is handled by the master.  Why is the first machine using workers, but the second is not with the exact same code?  And how do I 'force' the second machine to use the available workers so that the code is truly parallelized and the processing time is sped up?  The answers to these would help me tremendously with other work I am doing.  Thanks in advance.  The graphs from the function <code>snow.time()</code> are below as well as the code I used:
  <a href="https://i.stack.imgur.com/LsBB1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LsBB1.jpg" alt="Laptop CPU Usage"></a>
  <a href="https://i.stack.imgur.com/T994z.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T994z.jpg" alt="PC CPU Usage"></a></p>
  
  <pre><code>runs &lt;- 1e7
  manyruns &lt;- function(n) mean(unlist(lapply(X=1:(runs/4), FUN=onerun)))
  
  library(parallel)
  cores &lt;- 4
  cl &lt;- makeCluster(cores)
  
  # Send function to workers
  tobeignored &lt;- clusterEvalQ(cl, {
      onerun &lt;- function(.){ # Function of no arguments
          doors &lt;- 1:3
          prize.door &lt;- sample(doors, size=1)
          choice &lt;- sample(doors, size=1)
          if (choice==prize.door) return(0) else return(1) # Always switch
      }
      ; NULL
  })
  
  # Send runs to the workers
  tobeignored &lt;- clusterEvalQ(cl, {runs &lt;- 1e7; NULL})
  runtime &lt;- snow.time(avg &lt;- mean(unlist(clusterApply(cl=cl, x=rep(runs, 4), fun=manyruns))))
  stopCluster(cl)
  
  plot(runtime)
  </code></pre>