From 6ba01c420f0423b6992a65b414fc98a8aa81a751 Mon Sep 17 00:00:00 2001 From: Enol Fernandez <enolfc@ifca.unican.es> Date: Mon, 9 Dec 2013 08:52:19 +0100 Subject: [PATCH] use awk for getting unique lines instead of sort. --- modules/schedulers/condor/condor.scheduler | 9 +++------ modules/schedulers/lsf/lsf.scheduler | 12 ++++++------ modules/schedulers/pbs/pbs.scheduler | 9 +++------ modules/schedulers/slurm/slurm.scheduler | 7 +++---- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/modules/schedulers/condor/condor.scheduler b/modules/schedulers/condor/condor.scheduler index e2e7ea6..b9befe1 100755 --- a/modules/schedulers/condor/condor.scheduler +++ b/modules/schedulers/condor/condor.scheduler @@ -56,16 +56,13 @@ scheduler_get_machinefile () { export MPI_START_HOST_SLOTS_FILE=$MPI_START_TEMP_FILE sort -n < $CONDOR_CONTACT_FILE | awk '{print $2}' > $MPI_START_MACHINEFILE # assume CONDOR allocation of machines is "sane" - cat $MPI_START_MACHINEFILE | sort | uniq -c | tr -s " " | + awk '!x[$0]++' $MPI_START_MACHINEFILE | tr -s " " | # this is a subshell, variables changes here are not changed outside! - while read line; do - slots=`echo $line | cut -f1 -d" "` - host=`echo $line | cut -f2 -d" "` + while read host; do + slots=`grep -c "$host" $MPI_START_MACHINEFILE` echo $host >> $MPI_START_HOSTFILE echo $host $slots >> $MPI_START_HOST_SLOTS_FILE done - # this only works in bash - # < <( cat $MPI_START_MACHINEFILE | sort | uniq -c | tr -s " " ) export MPI_START_NHOSTS=`cat $MPI_START_HOSTFILE | wc -l` export MPI_START_NSLOTS_PER_HOST=`cat $MPI_START_HOST_SLOTS_FILE | cut -f2 -d" " | sort -n | head -1` export MPI_START_NSLOTS=`cat $MPI_START_MACHINEFILE | wc -l` diff --git a/modules/schedulers/lsf/lsf.scheduler b/modules/schedulers/lsf/lsf.scheduler index 2d7321c..2d1107c 100755 --- a/modules/schedulers/lsf/lsf.scheduler +++ b/modules/schedulers/lsf/lsf.scheduler @@ -43,16 +43,14 @@ build_lsb_hosts () { for host in $LSB_HOSTS; do echo $host >> $MPI_START_MACHINEFILE done - cat $MPI_START_MACHINEFILE | sort | uniq -c | tr -s " " | + awk '!x[$0]++' $MPI_START_MACHINEFILE | tr -s " " | # this is a subshell, variables changes here are not changed outside! - while read line; do - slots=`echo $line | cut -f1 -d" "` - host=`echo $line | cut -f2 -d" "` + while read host; do + slots=`grep -c "$host" $MPI_START_MACHINEFILE` echo $host >> $MPI_START_HOSTFILE echo $host $slots >> $MPI_START_HOST_SLOTS_FILE done export MPI_START_NHOSTS=`cat $MPI_START_HOSTFILE | wc -l` - export MPI_START_NSLOTS_PER_HOST=`cat $MPI_START_HOST_SLOTS_FILE | cut -f2 -d" " | sort -n | head -1` export MPI_START_NSLOTS=`cat $MPI_START_MACHINEFILE | wc -l` return 0 } @@ -88,7 +86,6 @@ build_lsb_mcpu_hosts () { done export MPI_START_NHOSTS=$total_hosts export MPI_START_NSLOTS=$total_slots - export MPI_START_NSLOTS_PER_HOST=`cat $MPI_START_HOST_SLOTS_FILE | cut -f2 -d" " | sort -n | head -1` return 0 } @@ -104,5 +101,8 @@ scheduler_get_machinefile () { else build_lsb_mcpu_hosts fi + st=$? + export MPI_START_NSLOTS_PER_HOST=`cat $MPI_START_HOST_SLOTS_FILE | cut -f2 -d" " | sort -n | head -1` + return $st } diff --git a/modules/schedulers/pbs/pbs.scheduler b/modules/schedulers/pbs/pbs.scheduler index 8e63842..ad61269 100755 --- a/modules/schedulers/pbs/pbs.scheduler +++ b/modules/schedulers/pbs/pbs.scheduler @@ -36,16 +36,13 @@ scheduler_get_machinefile () { mpi_start_mktemp export MPI_START_HOST_SLOTS_FILE=$MPI_START_TEMP_FILE cat $PBS_NODEFILE > $MPI_START_MACHINEFILE - cat $MPI_START_MACHINEFILE | sort | uniq -c | tr -s " " | + awk '!x[$0]++' $MPI_START_MACHINEFILE | tr -s " " | # this is a subshell, variables changes here are not changed outside! - while read line; do - slots=`echo $line | cut -f1 -d" "` - host=`echo $line | cut -f2 -d" "` + while read host; do + slots=`grep -c "$host" $MPI_START_MACHINEFILE` echo $host >> $MPI_START_HOSTFILE echo $host $slots >> $MPI_START_HOST_SLOTS_FILE done - # this only works in bash - # < <( cat $MPI_START_MACHINEFILE | sort | uniq -c | tr -s " " ) export MPI_START_NHOSTS=`cat $MPI_START_HOSTFILE | wc -l` export MPI_START_NSLOTS_PER_HOST=`cat $MPI_START_HOST_SLOTS_FILE | cut -f2 -d" " | sort -n | head -1` export MPI_START_NSLOTS=`cat $MPI_START_MACHINEFILE | wc -l` diff --git a/modules/schedulers/slurm/slurm.scheduler b/modules/schedulers/slurm/slurm.scheduler index 6dce747..593d77d 100755 --- a/modules/schedulers/slurm/slurm.scheduler +++ b/modules/schedulers/slurm/slurm.scheduler @@ -51,11 +51,10 @@ scheduler_get_machinefile () { return 13 fi fi - cat $MPI_START_MACHINEFILE | sort | uniq -c | tr -s " " | + awk '!x[$0]++' $MPI_START_MACHINEFILE | tr -s " " | # this is a subshell, variables changes here are not changed outside! - while read line; do - slots=`echo $line | cut -f1 -d" "` - host=`echo $line | cut -f2 -d" "` + while read host; do + slots=`grep -c "$host" $MPI_START_MACHINEFILE` echo $host >> $MPI_START_HOSTFILE echo $host $slots >> $MPI_START_HOST_SLOTS_FILE done -- GitLab