title: Preferred approach for running one script over multiple directories in SLURM
body: <p>My most typical use case is running a single script over multiple directories (usually R or Matlab). I have access to a high-performance computing environment (SLURM-based). From my research so far, it is unclear to me which of the following approaches would be preferred to make most efficient use of the CPUs/cores available. I also want to make sure I'm not unnecessarily taking up system resources so I'd like to double check which of the following two approaches is most suitable.</p>
  
  <p><strong>Approach 1:</strong></p>
  
  <ol>
  <li>Parallelize code within the script (MPI).</li>
  <li>Wrap this in a loop that applies the script to all directories.</li>
  <li>Submit this as a single MPI job as a SLURM script.</li>
  </ol>
  
  <p><strong>Approach 2:</strong></p>
  
  <ol>
  <li>Parallelize code within the script (MPI).</li>
  <li>Create an MPI job array, one job per directory, each running the script on the directory.</li>
  </ol>
  
  <p>I'm still new to this so if I've mixed up something here or you need more details to answer the question please let me know.</p>