[slurm超过了python多重处理的作业内存限制

问题描述 投票:1回答:1

我正在使用slurm来管理一些计算,但是有时作业会因为内存不足错误而被杀死,即使情况并非如此。这个奇怪的问题一直与使用多处理的python作业有关。

这是重现此行为的最小示例

#!/usr/bin/python

from time import sleep

nmem = int(3e7) # this will amount to ~1GB of numbers
nprocs = 200    # will create this many workers later
nsleep = 5      # sleep seconds

array = list(range(nmem))  # allocate some memory

print("done allocating memory")
sleep(nsleep)
print("continuing with multiple processes (" + str(nprocs) + ")")

from multiprocessing import Pool

def f(i):
    sleep(nsleep)

# this will create a pool of workers, each of which "seem" to use 1GB
# even though the individual processes don't actually allocate any memory
p = Pool(nprocs)
p.map(f,list(range(nprocs)))

print("finished successfully")

尽管这可能在本地运行良好,但粗略的内存分配似乎可以总结出每个进程的驻留内存,从而导致nprocs x 1GB的内存使用,而不是1GB(实际的mem使用)。我认为这不是应该做的事情,也不是操作系统正在做的事情,它似乎没有交换或任何内容。

这是输出,如果我在本地运行代码,则为>]

> python test-slurm-mem.py 
done allocation memory
continuing with multiple processes (0)
finished successfully

和htop的屏幕截图

htop showing a total mem use of 8GB with 200 processes of 1GB

这是如果我使用slurm运行相同的命令的输出

> srun --nodelist=compute3 --mem=128G python test-slurm-mem.py 
srun: job 694697 queued and waiting for resources
srun: job 694697 has been allocated resources
done allocating memory
continuing with multiple processes (200)
slurmstepd: Step 694697.0 exceeded memory limit (193419088 > 131968000), being killed
srun: Exceeded job memory limit
srun: Job step aborted: Waiting up to 32 seconds for job step to finish.
slurmstepd: *** STEP 694697.0 ON compute3 CANCELLED AT 2018-09-20T10:22:53 ***
srun: error: compute3: task 0: Killed
> $ sacct --format State,ExitCode,JobName,ReqCPUs,MaxRSS,AveCPU,Elapsed -j 694697.0
     State ExitCode    JobName  ReqCPUS     MaxRSS     AveCPU    Elapsed 
---------- -------- ---------- -------- ---------- ---------- ---------- 
CANCELLED+      0:9     python        2 193419088K   00:00:04   00:00:13 

我正在使用slurm来管理一些计算,但是有时作业会因为内存不足错误而被杀死,即使情况并非如此。 python ...

python memory-management python-multiprocessing slurm
1个回答
0
投票

对于其他人:如注释中含糊指出的,您需要更改文件slurm.conf。在此文件中,您需要将选项JobAcctGatherType设置为jobacct_gather/cgroup(完整行:JobAcctGatherType=jobacct_gather/cgroup)。

© www.soinside.com 2019 - 2024. All rights reserved.