You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Slurm集群中MATLAB parpool CPU占用过高疑似访问头节点求助

在Slurm集群中MATLAB parpool导致CPU占用过高的解决方法

问题原因分析

你遇到的CPU占用超过500%的问题,核心原因是MATLAB默认使用了Processes (Local Cluster)本地进程池,而非适配Slurm集群的配置。这种情况下,MATLAB可能无法严格遵循Slurm的资源分配规则,进而出现资源过载的情况。

解决方案

1. 修正Slurm提交脚本

首先补全Slurm脚本中缺失的分区参数,#SBATCH -p后需要填入你集群的有效分区名称(比如compute、general等),否则任务可能无法正确分配到计算节点:

#!/bin/bash
#SBATCH -J 9h_11h_6g_c_windowing_blur_overload
#SBATCH -o %x.o%j   # output file name
#SBATCH -e %x.e%j   # error file name
#SBATCH -p your_partition_name  # 替换为实际集群分区名称
#SBATCH -q standard
#SBATCH -n 8        # number of cores
#SBATCH -N 1        # number of nodes (use 1)
#SBATCH --mem=30G   # allocated memory
#SBATCH -t 07-00:00:00  # allocated wall time
#SBATCH --tmp=1GB   # allocated disk space
#SBATCH --mail-type=BEGIN,END   # notification type
#SBATCH --mail-user=your_email@example.com  # 补全邮箱地址

# load matlab module
module load matlab

# run matlab file
matlab -nodisplay -nodesktop -r "PulseReconstruction; exit;"

2. 修改MATLAB并行池代码

将MATLAB中默认的本地进程池替换为Slurm集群配置,确保Worker严格使用Slurm分配的资源:

% 获取Slurm集群配置对象
c = parcluster('Slurm');
% 从Slurm环境变量中动态获取分配的核心数
num_workers = str2double(getenv('SLURM_NTASKS'));

% 检查并创建符合资源限制的并行池
if isempty(gcp('nocreate'))
    parpool(c, num_workers);
end

disp(gcp('nocreate'));

3. 验证效果

修改后重新提交任务,查看并行池输出,应该显示类似以下内容,说明已使用Slurm集群:

Starting parallel pool (parpool) using the 'Slurm' profile ...
Connected to parallel pool with 8 workers.
 ClusterPool with properties: 
            Connected: true
           NumWorkers: 8
                 Busy: false
              Cluster: Slurm
        AttachedFiles: {}
    AutoAddClientPath: true
            FileStore: [1x1 parallel.FileStore]
           ValueStore: [1x1 parallel.ValueStore]
          IdleTimeout: 30 minutes (30 minutes remaining)
          SpmdEnabled: true

关键说明

  • 使用Slurm集群配置时,MATLAB会通过Slurm的srun命令启动Worker,完全遵守集群的资源调度规则,避免CPU过载。
  • 动态读取SLURM_NTASKS环境变量可以让代码适配不同的核心数分配,无需硬编码数值。

内容的提问来源于stack exchange,提问作者Murilo Tibana

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 22:31:04