Use all cores within a node via a loop
E.g. Given N jobs, with K cores, run jobs 1-K, wait for all to finish, then run K+1 - N
ncommands=22
nodesize=6
nodeuse=$(($nodesize ))
totjobs=$(( ($ncommands + $nodeuse - 1 ) / $nodeuse ))
for i in $(seq 1 1 $totjobs)
do
jstart=$((($i-1)*$nodesize +1))
jstop=$(($i*$nodesize))
min=$([ $ncommands -le $jstop ] && echo "$ncommands" || echo "$jstop")
jstop=$min
for j in $(seq $jstart 1 $jstop)
do
fileline=$(cat $genotype_loc | awk -v lineno=$j 'NR==lineno {print}')
chrom=$(echo $fileline | awk 'BEGIN {FS="_m"} {print $NF}')
echo "Using $fileline to make PRS for chromosome $chrom"
$plink2_loc --bfile $fileline --score $weights --q-score-file $threshold --q-score-range $range --out "$output_loc"/"$study"_"$sourcedat"_chr"$chrom" &
done
wait #wait for jobs to finish before starting next set
done