#!/bin/bash #******************************************************************************************* # Author Henry Jin # test example source-codes with C, C++ and Fortran compilers # set in comp_* variables. # Additions 2021-07-30 Kent Milfeld # Command line entry of files to be tested. # Automatic compiler determination # Automatic version (DATE/NUMBER) determination # Automatic Backdown for deprecation if compiler is not 5.1 # (masked->master,primary->master, *lock_hint*->*sync_hint*) # Automatic -c compiler flag for "linkable=no" metadata # save command line option to save preprocessed files (have exmpl_ prefix) # Utilities file, test_utils, created for clean coding #******************************************************************************************* DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )" #location of test_cases BASE_DIR=$(dirname $DIR) #Top level directory source test_utils # Hard code Compiler names and flags here: comp_c, comp_cpp, comp_f, omp_flag, fpp_flag # Keep comp_c="" to automatically determine compiler parameters # Specifying compiler system (amd,cray,gnu,ibm,intel) on command line, or # setting env. var. COMP (to AMD,CRAY,GNU,IBM,INTEL), # will override specifying compiler here, and auto detection.. comp_c="" comp_cpp="" comp_f="" omp_flag="" fpp_flag="" #COMP=GNU #(or AMD,CRAY,IBM,INTEL) forces one of these compiler systems (list in test_utils) #Compiler version DATE (e.g. 202011) and version NUMBER (e.g. 5.1) #Function below will set these for you. #If you set them here, auto detection function will not be called. VER_DATE="" VER_NUM="" NA_VER_NUMS=() #export OMP_DEBUG=1 #you can set this outside of test_cases printf "\n **** text_code ONLY tests compilation, and linking (when linkable=yes). ****" printf "\n **** text_code does NOT validate examples. It just compiles them. ****\n\n" #=========================== No need to change code below =================================== # command line option aopt=2 #default(auto), 0:no-omp, 1:with-omp while (($#)); do case "$1" in no-omp | -no-omp ) aopt=0 ;; with-omp | -with-omp) aopt=1 ;; auto | -auto ) aopt=2 ;; save | -save ) save_pp_files=on ;; help | -h |-help) echo "USAGE: test_codes [options] options: meaning -no-omp : no OpenMP compilation flag -with-omp : with OpenMP compilation flag -auto : (default) auto-detection based on include files -save : save preprocessed files : one or more example codes to test " exit ;; amd | AMD | oacc | OACC ) COMP=AMD comp_c="" ;; #comp_c="" => call get_compiler_commands_and_omp_flag cray | CRAY | cce | CCE ) COMP=CRAY comp_c="" ;; gnu | GNU ) COMP=GNU comp_c="" ;; ibm | IBM | pwr | PWR ) COMP=IBM comp_c="" ;; intel | INTEL ) COMP=INTEL comp_c="" ;; #These will override auto detection, and comp_x setting below. *.f* ) FILES+=($1) ;; *.c* ) FILES+=($1) ;; esac shift done # Set Compiler comp_c, comp_cpp, comp_f, omp_flag, fpp_flag # *** If comp_c is set, it is assumed all above comp_x/x_flag are set [[ -z $comp_c ]] && get_compiler_commands_and_omp_flag [[ -z $VER_DATE ]] && get_compiler_version_date # can set as env. var. for testing [[ -z $NA_VER_NUMS ]] && get_compiler_version_number # get VER_NUMs which compiler doesn't support (NA) [[ ! -z $NA_VER_NUMS ]] && REPLACE=ON echo -e " >>> TESTING: ${FILES[@]}\n" # function to test one code ($f) test_one_code() { local link_opt inc_suffix inc_opt comment fort_opts tested="compile & link" f_base=`basename $f` ef=exmpl_${f_base} ext=$1 \cp -f $f $ef opts="" if [ $aopt -eq 1 ]; then opts=" $copt" elif [ $aopt -ne 0 ]; then sstr=omp.h if [ "$ext" == "f" -o "$ext" == "f90" ]; then sstr="use omp_lib|omp_lib.h" #Can non-header files require copt? fi #Why not always have copt? KM egrep "$sstr" $ef > /dev/null 2>&1 && opts=" $copt" fi grep -ie '@@linkable\s*:\s*.*no' $ef &>/dev/null [[ $? == 0 ]] && link_opt="-c" && tested="compile only" grep -ie '@@\s*requires\s*:\s*.*preprocessing' $ef &>/dev/null [[ $? == 0 ]] && fort_opts="$fpp_flag" #JIC fpp needed for any reason if [[ $REPLACE == ON ]]; then for no in ${NA_VER_NUMS[@]}; do ver_date=${VNUM2DATE[$no]} grep -e '\s*#if\s*_OPENMP\s*<\s*'${ver_date}'\s*' $ef &>/dev/null if [[ $? == 0 ]]; then [ "$ext" == "f" -o "$ext" == "f90" ] && fort_opts="$fpp_flag" echo " -> Backing down from $no on $f_base code" #uncomment lines if they are commented out-- What about unwanted version #sed 's@\s*'$comment'\s*\(#\(if\|define\|endif\)\($\|\s\).*\)@\1@' $ef fi done fi spaces=" " eval EVAL=$f short_f=$(echo $EVAL | sed s@$BASE_DIR@\$OMP_BASE_DIR@) printf " >>> %-36s %-50s " \ "$comp $omp_flag $inc_opt $fort_opts $link_opt" "$short_f${spaces:40}" | tee -a $logf $comp $omp_flag $inc_opt $fort_opts $link_opt $ef >> $logf 2>&1 if [ $? -ne 0 ]; then printf "***" >> $logf printf " [FAILED]\n" | tee -a $logf (( cntfail = cntfail + 1 )) else printf " %-25s\n" "[PASSED: $tested]" fi \rm -f *.o *.mod [[ ! ( $REPLACE == ON && $save_pp_files == on) ]] && \rm -f $ef printf " ------------------------------------------------------\n\n" } # start testing copt=$omp_flag cntc=0 cntcpp=0 cntf=0 cntffree=0 cntfail=0 logf=test_codes.log # SELECTED FILE PROCESSING if [[ ! -z $FILES ]]; then for ff in ${FILES[@]}; do f=$BASE_DIR/*/sources/$ff if [[ $f =~ .c$ ]]; then comp=$comp_c (( cntc = cntc + 1 )) test_one_code c fi if [[ $f =~ .cpp$ ]]; then comp=$comp_cpp (( cntcpp = cntcpp + 1 )) test_one_code cpp fi if [[ $f =~ .f$ ]]; then comp=$comp_f (( cntf = cntf + 1 )) test_one_code f fi if [[ $f =~ .f90$ ]]; then comp=$comp_f f=$BASE_DIR/*/sources/$ff (( cntffree = cntffree + 1 )) test_one_code f90 fi done exit #No need for bulk processing information fi # BULK PROCESSING if [[ -z $FILES ]]; then comp=$comp_c for f in ../*/sources/*.c; do (( cntc = cntc + 1 )) test_one_code c done comp=$comp_cpp for f in ../*/sources/*.cpp; do (( cntcpp = cntcpp + 1 )) test_one_code cpp done comp=$comp_f for f in ../*/sources/*.f; do (( cntf = cntf + 1 )) test_one_code f done for f in ../*/sources/*.f90; do (( cntffree = cntffree + 1 )) test_one_code f90 done fi # print summary stats echo " C compiler = $comp_c C++ compiler = $comp_cpp Fortran compiler = $comp_f OpenMP flag = $omp_flag Total number of C examples : $cntc Total number of C++ examples : $cntcpp Total number of F-fixed examples: $cntf Total number of F-free examples : $cntffree Total number of failed examples : $cntfail" | tee -a $logf