首页 > 解决方案 > 使用 SLURM bash 脚本进行并行化和资源分配

问题描述

我有可能在 HPC 环境中进行处理,其中任务管理和资源分配由 SLURM 批处理作业系统控制。但是,我还没有找到正确的配置来有效地利用 R 中分配的资源。我尝试使用 R 中未来包的 plan(multicore) 功能在 SLURM 中为一项任务分配 20 个 CPU。在分配不同数量的 CPU 的情况下运行测试运行后,效率统计表明,使用这些设置只分配了一个 CPU在测试运行期间使用。

Slurm bash 脚本如下所示

#!/bin/bash
#SBATCH --job-name=pointsToRaster
#SBATCH --account=project_num
#SBATCH --time=00:10:00
#SBATCH --output=output_%j.txt
#SBATCH --error=error_%j.txt
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --cpus-per-task=20
#SBATCH --mem-per-cpu=15G
#SBATCH --partition=small

#A 10 MINUTE LONG TEST RUN

#load module
module load r-env-singularity

# Bind threads to individual cores
export OMP_PROC_BIND=true

#Run script
srun singularity_wrapper exec Rscript --no-save pointClouds.R

此 bash 脚本分配资源并执行脚本 pointClouds.R。在 R 脚本中,availableCores() 确保找到保留的 CPU,supportsMulticore() 确保环境和设置支持多核处理。脚本内容如下所示。

#set working directory
setwd(dir = "/scratch/project_2001456/lasFiles")

#load packages
library(sf)
library(sp)
library(raster)
library(rgdal)
library(lidR)
library(future)

####### SET COMPUTATIONAL CONFIGURATIONS ##########

# Parallelization settings:
print(availableCores()) #ensure that reserved CPU's are found
print(supportsMulticore())#ensure that environment and settings support multicore-processing
plan(multicore) #strategy to for resolving a future.

#From here on out, I have split one .las file to multiple chunks by their spatial extent. Aim to process all the chunks utilizing parallel processing, but process seems to utilize only one of the allocated CPUs.

有关如何使用 SLURM bash 脚本正确分配资源并在 R 中并行处理有效利用它们的任何帮助?

标签: rparallel-processingslurm

解决方案


HPC 服务提供商发现了问题。由于未知原因OMP_PLACES=cores,应该将线程/进程绑定到特定内核的变量似乎仅在运行多核 R 作业时才将所有进程绑定到单个内核。问题已通过重建 r-environmentsingularity-container 得到解决。


推荐阅读