I have a submit script that does several things in a sequential manner (at least that is how I tried to write it). but when I run my script the final operation behaves according to the completion order of the previous operation. attached is a part of the script.
#!/bin/bash
#SBATCH --job-name=cff_cg
#SBATCH --nodes=1 --ntasks=20
#SBATCH --time=0-06:00:00
#SBATCH --mem-per-cpu=4gb
#SBATCH --constraint=avx512
#SBATCH --partition=sixhour
#SBATCH --output=1_%a.out
#SBATCH --array=1-100
.
.
.
.
.
.
.
.
if [[ -f $main_path/surf_$fold/data.lammps ]] ; then
echo 'EXISTS'
check=$(awk 'FNR == 21 {print $2}' $main_path/surf_$fold/data.lammps)
echo "$check"
if [[ $check == '1' ]] ; then
awk 'f{print $3; f=0} /Energy/{f=1}' $main_path/surf_$fold/log.lammps > $main_path/surf_$fold/min_energy.dat
awk '/Energy/{ if (secondline==0) { secondline=1; next; } else { getline; print $3; } }' $main_path/surf_$fold/log.lammps > $main_path/surf_$fold/min_energy_$fold.dat
fi
fi
wait
cat $main_path/surf_$fold/min_energy_$fold.dat >> $main_path/energy_final_new.dat
exit 0
the way I should be getting the final output file "energy_final_new.dat" is according to the order of the array, i.e, values in the order of 001,002,003,004 but instead I get values with a mixed order (once i got like 002,004,003,001 etc.) I believe this happened in the order of each job finishes but I need them in the order of the array_id. can someone help me with this? P.S - SBATCH makes the script run in parallel.
SBATCH
thing runs multiple instances of the script in parallel? If so, you need to describe that. Notice also that$main_path
and$fold
are not defined in your script.