title: Setup torque/moab cluster to use multiple cores per node with a single loop
body: <p>This is a followup on [<a href="https://stackoverflow.com/questions/17288379/how-to-set-up-dosnow-and-sock-cluster-with-torque-moab-scheduler/17299302?noredirect=1#comment44364759_17299302]">How to set up doSNOW and SOCK cluster with Torque/MOAB scheduler?</a></p>
  
  <p>I have a memory limited script that only uses 1 <code>foreach</code> loop but I'd like to get 2 iterations running on node1 and 2 iterations running on node2. The above linked question allows you to start a SOCK cluster to each node for the outer loop and then MC cluster for the inner loop and I think doesn't make use of the multiple cores on each node.
  I get the warning message 
  <code>Warning message:
  closing unused connection 3 (&lt;-compute-1-30.local:11880)</code></p>
  
  <p>if I do <code>registerDoMC(2)</code> if I do this after <code>registerDoSNOW(cl)</code>
  Thanks.</p>
  
  <p>EDIT: The solution from the previous question works fine for the problem asked. see my example below for what I want.</p>
  
  <p>starting an interactive job with 2 nodes and 2cores per processor:</p>
  
  <pre><code>qsub -I -l nodes=2:ppn=2
  </code></pre>
  
  <p>after starting R:</p>
  
  <pre><code>library(doParallel)
  f &lt;- Sys.getenv('PBS_NODEFILE')
  nodes &lt;- unique(if (nzchar(f)) readLines(f) else 'localhost')
  print(nodes)
  </code></pre>
  
  <p>here are the two nodes I"m running on:</p>
  
  <pre><code>[1] "compute-3-15" "compute-1-32"
  </code></pre>
  
  <p>start the sock cluster on these two nodes:</p>
  
  <pre><code>cl &lt;- makePSOCKcluster(nodes, outfile='')
  </code></pre>
  
  <p>i'm not sure why they both seem to be on <code>compute-3-15</code> .... ?</p>
  
  <pre><code>starting worker pid=25473 on compute-3-15.local:11708 at 16:54:17.048
  starting worker pid=14746 on compute-3-15.local:11708 at 16:54:17.523
  </code></pre>
  
  <p>but register the two nodes and run a single foreach loop:</p>
  
  <pre><code>registerDoParallel(cl)
  r=foreach(i=seq(1,6),.combine='c') %dopar% { Sys.info()[['nodename']]}
  print(r)
  </code></pre>
  
  <p>output of r indicates that both nodes were used though:</p>
  
  <pre><code> [1] "compute-3-15.local" "compute-1-32.local" "compute-3-15.local"
   [4] "compute-1-32.local" "compute-3-15.local" "compute-3-15.local"
  </code></pre>
  
  <p>now, what I'd really like is for that foreach loop to run on 4 cores, 2 on each node.</p>
  
  <pre><code>library(doMC)
  registerDoMC(4)
  r=foreach(i=seq(1,6),.combine='c') %dopar% { Sys.info()[['nodename']]}
  print(r)
  </code></pre>
  
  <p>the output indicates that only 1 node was used, but presumably both cores on that one node.</p>
  
  <pre><code>[1] "compute-3-15.local" "compute-3-15.local" "compute-3-15.local"
  [4] "compute-3-15.local" "compute-3-15.local" "compute-3-15.local"
  </code></pre>
  
  <p>How do I get a SINGLE foreach loop to use multiple cores on multiple nodes?</p>