在SLURM中的多个目录上运行一个脚本的首选方法 [英] Preferred approach for running one script over multiple directories in SLURM

查看:70
本文介绍了在SLURM中的多个目录上运行一个脚本的首选方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最典型的用例是在多个目录(通常是R或Matlab)上运行单个脚本.我可以访问高性能计算环境(基于SLURM).到目前为止,从我的研究来看,我尚不清楚哪种方式可以更有效地利用可用的CPU/内核.我还想确保我不会不必要地占用系统资源,所以我想仔细检查以下两种方法中哪一种最合适.

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.

方法1:

  1. 在脚本(MPI)中并行化代码.
  2. 将其包装在将脚本应用于所有目录的循环中.
  3. 将其作为SLURM脚本作为单个MPI作业提交.

方法2:

  1. 在脚本(MPI)中并行化代码.
  2. 创建一个MPI作业数组,每个目录一个作业,每个作业在该目录上运行脚本.

我对此还是很陌生,所以如果我在这里混淆了一些东西,或者您需要更多详细信息来回答这个问题,请告诉我.

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.

推荐答案

如果您未在原始R或Matlab脚本中明确使用MPI,建议您完全避免使用MPI,而应使用

If you do not explicitly use MPI inside your original R or Matlab script, I suggest you avoid using MPI at all and use job arrays.

假设您有一个脚本 myscript.R 和一组子目录 data01 data02 ,..., data10 ,并且脚本将目录名称作为输入参数,您可以执行以下操作.

Assuming you have a script myscript.R and a set of subdirectories data01, data02, ..., data10, and the scripts takes the name of the directory as input parameter, you can do the following.

在数据目录的父目录中创建提交脚本:

Create a submission script in the directory parent of the data directories:

#!/bin/bash
#SBATCH --ntasks 1
#SBATCH --cpus-per-task 1
#SBATCH --mem-per-cpu=2G
#SBATCH --time 1-0
#SBATCH --array=1-10

DIRS=(data*/) # Create a Bash array with all data directories

module load R
Rscript myscript.R ${DIRS[$SLURM_ARRAY_TASK_ID]} # Feed the script with the data directory
                                                 # corresponding to the task ID in the array

此脚本将创建一个作业数组,其中每个作业将使用数据目录之一作为参数运行 myscript.R .

This script will create a job array where each job will run the myscript.R with one of the data directories as argument.

当然,您需要调整内存和时间的值,并调查每个作业使用一个以上的CPU是否对您有利.并根据您的情况将-array 参数调整为实际的目录数.

Of course you will need to adapt the values of the memory and time, and investigate whether or not using more than one CPU per job is beneficial in your case. And adapt the --array parameter to the actual number of directories in your case.

这篇关于在SLURM中的多个目录上运行一个脚本的首选方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆