如何确定在哪个点在Python脚本一步内存SLURM突破(How to determine at w

2019-09-30 22:21发布

我有一个python ,我是一个上运行脚本SLURM为多个输入文件集群:

#!/bin/bash

#SBATCH -p standard
#SBATCH -A overall 
#SBATCH --time=12:00:00
#SBATCH --output=normalize_%A.out
#SBATCH --error=normalize_%A.err
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=20
#SBATCH --mem=240000

HDF5_DIR=...
OUTPUT_DIR=...
NORM_SCRIPT=...

norm_func () {
  local file=$1
  echo "$file"
  python $NORM_SCRIPT -data $file -path $OUTPUT_DIR
}

# Doing normalization in parallel
for file in $HDF5_DIR/*; do norm_func "$file" & done
wait

该Python脚本只是加载数据集( scRNAseq ),做它的正常化,并保存为.csv文件。 在它的代码一些主要线路有:

        f = h5py.File(path_to_file, 'r')
        rawcounts = np.array(rawcounts)

        unique_code = np.unique(split_code)
        for code in unique_code:
            mask = np.equal(split_code, code)
            curr_counts = rawcounts[:,mask]

            # Actual TMM normalization
            mtx_norm = gmn.tmm_normalization(curr_counts)

            # Writing the results into .csv file
            csv_path = path_to_save + "/" + file_name + "_" + str(code) + ".csv"
            with open(csv_path,'w', encoding='utf8') as csvfile:
                writer = csv.writer(csvfile, delimiter=',')
                writer.writerow(["", cell_ids])
                for idx, row in enumerate(mtx_norm):
                    writer.writerow([gene_symbols[idx], row])

我不断收到step memory exceeded为高于数据集的错误10Gb ,我不知道为什么。 我怎样才能改变我的.slurm脚本或python代码,以减少其内存使用情况? 我怎样才能真正确定是什么原因导致的memory问题,有没有在这种情况下,调试存储的一种特殊的方式? 任何建议将不胜感激。

Answer 1:

您可以通过使用得到精制的信息srun启动Python脚本:

srun python $NORM_SCRIPT -data $file -path $OUTPUT_DIR

然后SLURM将创建根据您的Python脚本实例一个“一步”,并报告了独立的每一步会计,您可以用询问的信息(错误,返回代码,内存使用等) sacct命令。

如果由管理员配置,使用--profile选项来获得每一步的内存使用情况的时间表。

在你的Python脚本可以使用memory_profile模块得到您的脚本的内存使用情况的反馈。



文章来源: How to determine at which point in python script step memory exceeded in SLURM