N=4
NCORE=64
for fac in 10 100 1000 10000; do
   if [ ! -f results/scf_f${fac}.mat ]; then
      (
      echo rescu -i scf_f${fac}.input
      mpiexec -n $((NCORE/N)) rescu --mpi -i scf_f${fac}.input
      ) &
      # allow only to execute $N jobs in parallel
      if [[ $(jobs -r -p | wc -l) -ge $N ]]; then
         # wait only for first job
         wait -n
      fi
   fi
done
