Easiest way to run SLURM on multiple files

I have a Python script that processes approximately 10,000 FITS files one by one. For each file, the script generates an output in the same directory as the input files and creates a single CSV file to record statistics about the processed files.

Previously, I parallelized the script using async with multiprocessing pools, but now I have access to a SLURM cluster and would like to run it using SLURM.

What is the simplest way to achieve this?
All the files are stored in the same directory, and there’s no specific order in which they need to be processed.
EDIT: I also need to activate conda enviroment before running python script. Python should accept filename and start running code. Usually I send filename via args.
Thanks

******** EDIT update:
I managed to make it work.
First, I created bash script for submitting jobs:

#!/bin/bash

# Define the directory containing FITS files
INPUT_DIR="input_dir"
LOG_DIR="${INPUT_DIR}/logs"

# Ensure the logs directory exists
mkdir -p "$LOG_DIR"

# List all FITS files and write their paths to a temporary file
find "$INPUT_DIR" -name "*.fits" > file_list.txt

# Loop through each FITS file and submit a SLURM job
while IFS= read -r filepath; do
    sbatch run2.sh "$filepath"
done < file_list.txt

So, that script is calling run2.sh script which contains following:

#!/bin/bash
#SBATCH -p long
#SBATCH -J test
#SBATCH -n 1
#SBATCH -t 00:05:00
#SBATCH --output=file.out
#SBATCH --error=file.err


source miniconda3/bin/activate my_env

# Define variables
# EVENT_PATH="directory_path"

# Run Python script
python3 -u my_python_code.py "$1" "False" 3

My next concern is that in this way I am creating 10k jobs, because I have 10k images to analyse, although analyzing each image only takes few seconds.
Maybe there is smarter way to do it.

1

I had a similar requirement some time ago and below is the script I used to solve it. What you need are SLURM array jobs, where each job will get its own set of resources and can run on a different file.

Below, I used used the $SLURM_ARRAY_TASK_ID environment variable as a python argument (sys.argv[2]) to decide which file to operate on. It is essentially the index of the job within the job array, as defined in the link to docs above. The %a in the --job-name and --output is also replaced by this index to generate unique names for each job/output. You can pass additional parameters to the slurm script, and then to the python script, like the arg1 -> $1 -> sys.argv[1]

Ofcourse your core/memory/time requirements will be different.

#!/bin/bash
# use as:
# sbatch --job-name=name_%a --output=out_%a.txt --array=1-nFiles testslurm.sh arg1
#-------------------------------------------------------------
#-------------------------------------------------------------
#
#
#Number of CPU cores to use within one node
#SBATCH -c 12
#
#Define the number of hours the job should run. 
#Maximum runtime is limited to 10 days, ie. 240 hours
#SBATCH --time=24:00:00
#
#Define the amount of RAM used by your job in GigaBytes
#In shared memory applications this is shared among multiple CPUs
#SBATCH --mem=64G
#Do not export the local environment to the compute nodes
#unset SLURM_EXPORT_ENV
#
#Set the number of threads to the SLURM internal variable
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK
#
#load the respective software module you intend to use
#module load YourModuleHere
#
#run the respective binary through SLURM's srun
conda init bash
conda activate suite2p

srun --cpu_bind=verbose  python  batchfunc.py  ~/codes/data/$1 $SLURM_ARRAY_TASK_ID

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật