1
1
openmpi/ompi/tools/mpisync/ompi_timing_post

55 строки
1.3 KiB
Plaintext
Исходник Обычный вид История

#!/bin/bash
#
# Copyright (c) 2014 Artem Polyakov <artpol84@gmail.com>
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#####################################################################
# Evaluate a floating point number expression.
function float_eval(){
float_scale=9
local stat=0
local result=0.0
if [[ $# -gt 0 ]]; then
result=$(echo "scale=$float_scale; $*" | bc -q 2>/dev/null)
stat=$?
if [[ $stat -eq 0 && -z "$result" ]]; then
stat=1;
fi
fi
echo $result
return $stat
}
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Need the name of a timing file and the output file"
exit 0
fi
thefile=$1
postfile=$2
sed '/^$/d' $thefile > ${thefile}_tmp
sort ${thefile}_tmp > ${postfile}
read line < ${postfile}
first_ts=`echo $line | awk '{ print $1 }' | sed -e 's/s//'`
prev_ts=$first_ts
echo $first_ts
while read line ; do
cur_ts=`echo $line | awk '{ print $1 }' | sed -e 's/s//'`
dif1=`float_eval "$cur_ts - $first_ts"`
dif2=`float_eval "$cur_ts - $prev_ts"`
newline=`echo $line | sed -e "s/$cur_ts/$dif1:$dif2/"`
prev_ts=$cur_ts
echo $newline
done < ${postfile} > ${thefile}_tmp
cat ${thefile}_tmp > ${postfile}
rm -f ${thefile}_tmp