title: Whether to use the detectCores function in R to specify the number of cores for parallel processing?
body: <p>In the <a href="https://stat.ethz.ch/R-manual/R-devel/library/parallel/html/detectCores.html" rel="noreferrer">help</a> for <code>detectCores()</code> it says:</p>
  
  <blockquote>
    <p><strong>This is not suitable for</strong> use directly for the mc.cores argument of
    mclapply nor <strong>specifying the number of cores in makeCluster</strong>. First
    because it may return NA, and second because it does not give the
    number of allowed cores.</p>
  </blockquote>
  
  <p>However, I've seen quite a bit of sample code like the following:</p>
  
  <pre><code>library(parallel)
  k &lt;- 1000
  m &lt;- lapply(1:7, function(X) matrix(rnorm(k^2), nrow=k))
  
  cl &lt;- makeCluster(detectCores() - 1, type = "FORK")
  test &lt;- parLapply(cl, m, solve)
  stopCluster(cl)
  </code></pre>
  
  <p>where <code>detectCores()</code> is used to specify the number of cores in <code>makeCluster</code>.</p>
  
  <p>My use cases involve running parallel processing both on my own multicore laptop (OSX) and running it on various multicore servers (Linux). So, I wasn't sure whether there is a better way to specify the number of cores or whether perhaps that advice about not using <code>detectCores</code> was more for package developers where code is meant to run over a wide range of hardware and OS environments. </p>
  
  <p>So in summary:</p>
  
  <ul>
  <li><strong>Should you use the <code>detectCores</code> function in R to specify the number of cores for parallel processing?</strong></li>
  <li><strong>What is the distinction mean between detected and allowed cores and when is it relevant?</strong></li>
  </ul>