Child pages
  • Slurm - job array
Skip to end of metadata
Go to start of metadata

ntasks-node

#!/bin/sh
# The base of this code is from https://help.rc.ufl.edu/doc/SLURM_Job_Arrays
#SBATCH --job-name=mega_array-ntasks-per-node   # Job name
#SBATCH --mail-type=ALL                          # Mail events (NONE, BEGIN, END, FAIL, ALL)
#SBATCH --mail-user=<user_id>@rit.edu   # Where to send mail
#SBATCH --nodes=11                                 # Use one node
##SBATCH --ntasks=1                                # Run a single task
#SBATCH --ntasks-per-node=1                  # Request that ntasks be invoked on each node.
#SBATCH --mem-per-cpu=1gb                   # Memory per processor
#SBATCH --time=0-0:10:00                        # Time limit days-hrs:min:sec
#SBATCH --output=array_%A-%a.out        # Standard output and error log
##SBATCH --array=1-5                              # Array range
#SBATCH --account=<account name>      # Charge resources used by this job to specified account
#SBATCH --partition=tier3                          # Request a specific partition for the resource allocation
 
# This is an example script that combines array tasks with
# bash loops to process many short runs. Array jobs are convenient
# for running lots of tasks, but if each task is short, they
# quickly become inefficient, taking more time to schedule than
# they spend doing any work and bogging down the scheduler for
# all users.
 
pwd; hostname; date
 
 
#Set the number of runs that each SLURM task should do
PER_TASK=2
 
# Calculate the starting and ending values for this task based
# on the SLURM task and the number of runs per task.
START_NUM=1 #$(( ($SLURM_ARRAY_TASK_ID - 1) * $PER_TASK + 1 ))
END_NUM=10 #$(( $SLURM_ARRAY_TASK_ID * $PER_TASK ))
 
# Print the task and run range
echo This is task $SLURM_ARRAY_TASK_ID, which will do runs $START_NUM to $END_NUM
 
# Run the loop of runs for this task.
for (( run=$START_NUM; run<=END_NUM; run++ )); do
      echo This is SLURM task $SLURM_ARRAY_TASK_ID, run number $run
        #your code goes here
                spack load r-doparallel
                touch test.r
                echo "library(doParallel)" > test.r
                # example from blog.aicry.com"
                echo "system.time(foreach(i=1:100000)%do%sum(tanh(1:i))) #sequential foreach loop" >> test.r
                                echo $HOSTNAME
                srun  < test.r --no-save
                rm test.r

#your code goes here
        done
        
        
        date


ntasks-per-node

#!/bin/sh
# The base of this code is from https://help.rc.ufl.edu/doc/SLURM_Job_Arrays
#SBATCH --job-name=mega_array-ntasks-per-node   # Job name
#SBATCH --mail-type=ALL                                      # Mail events (NONE, BEGIN, END, FAIL, ALL)
#SBATCH --mail-user=<user_id>@rit.edu              # Where to send mail    
#SBATCH --ntasks-per-node=1                              # Request that ntasks be invoked on each node
#SBATCH --mem-per-cpu=1gb                              # Memory per processor
#SBATCH --time=0-0:10:00                                   # Time limit days-hrs:min:sec
#SBATCH --output=array_%A-%a.out                   # Standard output and error log
#SBATCH --array=1-5                                           # Array range
#SBATCH --account=<account name>                 # Charge resources used by this job to specified account
#SBATCH --partition=tier3                                    # Request a specific partition for the resource allocation
 
# This is an example script that combines array tasks with
# bash loops to process many short runs. Array jobs are convenient
# for running lots of tasks, but if each task is short, they
# quickly become inefficient, taking more time to schedule than
# they spend doing any work and bogging down the scheduler for
# all users.
 
pwd; hostname; date
 
 
#Set the number of runs that each SLURM task should do
PER_TASK=1
 
# Calculate the starting and ending values for this task based
# on the SLURM task and the number of runs per task.
START_NUM=$(( ($SLURM_ARRAY_TASK_ID - 1) * $PER_TASK + 1 ))
END_NUM=$(( $SLURM_ARRAY_TASK_ID * $PER_TASK ))
 
# Print the task and run range
echo This is task $SLURM_ARRAY_TASK_ID, which will do runs $START_NUM to $END_NUM
 
# Run the loop of runs for this task.
for (( run=$START_NUM; run<=END_NUM; run++ )); do
      echo This is SLURM task $SLURM_ARRAY_TASK_ID, run number $run
        #your code goes here
        spack load r-doparallel
        touch test.r
        echo "library(doParallel)" > test.r
        # example from blog.aicry.com"
        echo "system.time(foreach(i=1:100000)%do%sum(tanh(1:i))) #sequential foreach loop" >> test.r
        R < test.r --no-save
        rm test.r
         
        done
        
        
        date


  • No labels