-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'unit-tests' of github.uconn.edu:HPC/parallel-slurm into…
… HEAD
- Loading branch information
Showing
2 changed files
with
16 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
#!/bin/bash | ||
|
||
seed=$SLURM_JOB_ID | ||
ID=$1 | ||
|
||
prng () { | ||
# Use the linear conguential generator algorithm: | ||
# https://en.wikipedia.org/wiki/Random_number_generation#Computational_methods | ||
# | ||
# Set it with: | ||
# a = 1 | ||
# b = SLURM_JOB_ID | ||
# m = SLURM_NTASKS | ||
# | ||
# We seed b with the SLURM_JOB_ID so that we independently have | ||
# the same seed for all tasks for a given job. | ||
|
||
x_n=0 | ||
a=1 | ||
b=$SLURM_JOB_ID | ||
b=$seed | ||
m=$SLURM_NTASKS | ||
# Recur as many times as the task id to generate different numbers | ||
# for each SLURM task. | ||
for _ in 1..$SLURM_PROCID | ||
for i in $(seq 1 $ID) | ||
do | ||
x_n=$(( $(( a * $((x_n + b)) )) % m)) | ||
done | ||
echo $x_n | ||
} | ||
|
||
main () { | ||
# Randomly fail half of the tasks. | ||
"Task $SLURM_PROC_ID started..." | ||
random_int=$(prng) | ||
echo -n "Task $ID started (seed $seed, random number $random_int) ... " | ||
sleep "$random_int" | ||
if _=$(( random_int % 2 )) | ||
if (( $random_int % 4 == 0 )) | ||
then | ||
"Task $SLURM_PROC_ID failed!" | ||
exit 1 | ||
echo "succeeded!" | ||
exit 0 | ||
fi | ||
"Task $SLURM_PROC_ID succeeded!" | ||
echo "failed!" | ||
exit 1 | ||
} | ||
|
||
[ "$0" != "${BASH_SOURCE[0]}" ] || main "$@" |