Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-21 23:14:25

0001 #!/bin/bash
0002 
0003 ##########################
0004 ## Global Configuration ##
0005 ##########################
0006 
0007 ## Instruction sets defined with "make" command line settings
0008 export SSE3="CPPUSERFLAGS+=\"-march=core2\" CXXUSERFLAGS+=\"-march=core2\" VEC_GCC=\"-march=core2\" VEC_ICC=\"-march=core2\""
0009 export AVX=""
0010 export AVX2="AVX2:=1"
0011 export AVX512="AVX_512:=1"
0012 
0013 ## Output options
0014 export tmp_ext="log"
0015 export ext="txt"
0016 
0017 ## Tmp output labels
0018 export nth_label="nTH"
0019 export nev_label="nEV"
0020 export njob_label="nJOB"
0021 export ncore_label="nCORE"
0022 export nproc_label="nPROC"
0023 export nloop_label="nLOOP"
0024 
0025 ######################
0026 ## N Physical Cores ##
0027 ######################
0028 
0029 function GetNCore ()
0030 {
0031     local nth=${1}
0032     local maxcore=${2}
0033 
0034     if (( ${nth} <= ${maxcore} ))
0035     then
0036         local ncore="${nth}"
0037     else
0038         local ncore="${maxcore}"
0039     fi
0040  
0041     echo "${ncore}"
0042 }
0043 export -f GetNCore
0044 
0045 ####################
0046 ## Core Test Loop ##
0047 ####################
0048 
0049 function MkFitLoop ()
0050 {
0051     local min_duration=${1}
0052     local test_exe=${2}
0053     local nproc=${3}
0054     local njob=${4}
0055     
0056     local start_time=$( date +"%s" )
0057     local end_time=$(( ${start_time} + ${min_duration} ))
0058     
0059     ## compute number of events to process per job
0060     local nproc_per_job=$(( ${nproc} / ${njob} ))
0061 
0062     ## global variable to be read back in main loop to keep track of number of times processed
0063     nloop=0
0064 
0065     ## run stress test for min min_duration with an emulated do-while loop: https://stackoverflow.com/a/16491478
0066     while
0067 
0068     ## launch jobs in parallel to background : let scheduler put jobs all around
0069     for (( ijob = 0 ; ijob < ${njob} ; ijob++ ))
0070     do
0071         ## want each mkFit job to process different events, so compute an offset
0072         local start_event=$(( ${nproc_per_job} * ${ijob} ))
0073 
0074         ## run the executable
0075         ${test_exe} --num-events ${nproc_per_job} --start-event ${start_event} &
0076     done
0077 
0078     ## wait for all background processes to finish --> non-ideal as we would rather "stream" jobs launching
0079     wait
0080     
0081     ## increment nloop counter
0082     ((nloop++))
0083 
0084     ## perform check now to end loop : if current time is greater than projected end time, break.
0085     local current_time=$( date +"%s" )
0086     (( ${current_time} <= ${end_time} ))
0087     do
0088         continue
0089     done
0090 }
0091 export -f MkFitLoop
0092 
0093 ########################################
0094 ## Dump Info about Test into Tmp File ##
0095 ########################################
0096 
0097 function AppendTmpFile ()
0098 {
0099     local tmp_output_file=${1}
0100     local ncore=${2}
0101     local nproc=${3}
0102     local nloop=${4}
0103 
0104     echo "${ncore_label} ${ncore}" >> "${tmp_output_file}"
0105     echo "${nproc_label} ${nproc}" >> "${tmp_output_file}"
0106     echo "${nloop_label} ${nloop}" >> "${tmp_output_file}"
0107 }
0108 export -f AppendTmpFile
0109 
0110 ####################################
0111 ## Dump Tmp Output into Main File ##
0112 ####################################
0113 
0114 function DumpIntoFile ()
0115 {
0116     local tmp_output_file=${1}
0117     local output_file=${2}
0118 
0119     ## get wall-clock time, split 
0120     read -ra time_arr < <(grep "real" "${tmp_output_file}")
0121     local tmp_time=${time_arr[1]}
0122 
0123     local mins=$( echo "${tmp_time}" | cut -d "m" -f 1 )
0124     local secs=$( echo "${tmp_time}" | cut -d "m" -f 2  | cut -d "s" -f 1 )
0125     
0126     local total_time=$( bc -l <<< "${mins} * 60 + ${secs}" )
0127         
0128     ## get physical cores used
0129     local ncore=$( grep "${ncore_label}" "${tmp_output_file}" | cut -d " " -f 2 )
0130 
0131     ## compute total events processed per core
0132     local nloop=$( grep "${nloop_label}" "${tmp_output_file}" | cut -d " " -f 2 )
0133     local nproc=$( grep "${nproc_label}" "${tmp_output_file}" | cut -d " " -f 2 )
0134 
0135     local total_proc=$(( ${nloop} * ${nproc} )) 
0136     local total_proc_per_core=$( bc -l <<< "${total_proc} / ${ncore}" )
0137 
0138     ## divide time by total events processed per core 
0139     local norm_time=$( bc -l <<< "${total_time} / ${total_proc_per_core}" )
0140 
0141     ## dump result into final output file
0142     echo "${test_label} ${norm_time}" >> "${output_file}"
0143 }
0144 export -f DumpIntoFile