forked from LLNL/Comb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsep_out.bash
executable file
·36 lines (31 loc) · 1.02 KB
/
sep_out.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# separates the output of each mpi rank into a different file
ARGS="$@"
ARGS_UNDERSCORE="$(sed s/\ /_/g <<<$ARGS)"
ARGS_UNDERSCORE="$(sed s-/-@-g <<<$ARGS_UNDERSCORE)"
ARGS_UNDERSCORE="$(echo $ARGS_UNDERSCORE | cut -c -192)"
# attempt to find the environment variable with the mpi rank of this process
if [[ ! "x" == "x$JSM_NAMESPACE_RANK" ]]; then
RANK=${JSM_NAMESPACE_RANK}
elif [[ ! "x" == "x$SLURM_PROCID" ]]; then
RANK=${SLURM_PROCID}
elif [[ ! "x" == "x$OMPI_COMM_WORLD_RANK" ]]; then
RANK=${OMPI_COMM_WORLD_RANK}
elif [[ ! "x" == "x$MPIRUN_RANK" ]]; then
RANK=${MPIRUN_RANK}
else
echo "sep_out.bash Could not find mpirank" 1>&2
exit 1
fi
# use args and rank to make file name
OUT_FILE="sepout.${ARGS_UNDERSCORE}.${RANK}"
if [ -f "$OUT_FILE" ]; then
echo "File already exists $OUT_FILE" 1>&2
exit 1
fi
# print the command to be executed for the 0th rank
if [[ "x0" == "x$RANK" ]]; then
echo "$ARGS &> $OUT_FILE"
fi
# execute the executable and redirect its output to a file
exec $ARGS &> $OUT_FILE