diff --git a/src/compile b/src/compile index 3e536ed16234e894adb58f9a0297c99edc902b31..f524b82d9864eac408ac63e2f0cda5987765a775 100755 --- a/src/compile +++ b/src/compile @@ -24,10 +24,12 @@ INC_DIR=../headers # # options that you need to compile # +#SYS=PAPI_LUMI_C #SYS=PAPI_LEONARDO_DCGP SYS=PAPI_MYLAPTOP -OPTS=" -std=c2x -DFILL=25 -D${SYS}" +# default generic options +OPTIONS_DFLT=" -std=c2x -DFILL=25 " # specific options # @@ -35,18 +37,20 @@ ASSERT_OFF=" -DNDEBUG " PAPI_OPT=" -DUSE_PAPI " PAPI_LIB=" -lpapi " -GCC_OPTS=" -O3 -march=native -mtune=native -ftree-vectorize -funroll-loops " -ICX_OPTS=" -O3 -xHost -vec -axCORE-AVX2,CORE-AVX512 " - +declare -A OPTIMIZATIONS +OPTIMIZATIONS[gcc]=" -O3 -march=native -mtune=native -ftree-vectorize -funroll-loops " +OPTIMIZATIONS[icx]=" -O3 -xHost -vec -axCORE-AVX2,CORE-AVX512 " +OPTIMIZATIONS[cc]=" -O3 " # variables that control the behaviour # -compiler=0 -gcc=1 -icx=2 +compiler=cc assert_on=0 support_papi=0 +optimization_given="none" +options_given="none" +debug_option= # # ================================================== @@ -54,44 +58,57 @@ support_papi=0 # parse the arguments # -CLOPTIONS="c:aph" +CLOPTIONS="Cc:O:o:gaph" if [[ $# -lt 1 ]]; then print_help; fi while getopts ${CLOPTIONS} opt; do - case ${opt} in - c) if [[ $OPTARG == [Gg][Cc][Cc] ]]; then - echo "compile with gcc" - compiler=$gcc - elif [[ "$OPTARG" == [Ii][Cc][Xx] ]]; then - echo "compile with icx" - compiler=$icx - else - echo "unsupported compiler" - exit 1 - fi - ;; - - g) OPTS="${OPTS} -g3 " - ;; - - a) assert_on=1 - echo "compile with asserts on" - ;; - - p) support_papi=1 - echo "compile with PAPI support" - ;; - - h) print_help - ;; - :) echo "option -${OPTARG} requires an argument" - ;; - - ?) echo "invalid option -${OPTARG}" - ;; - esac + case ${opt} in + + C) compiler=cc + echo "use generic compiler cc:" + cc --version + ;; + c) lcarg=$( echo ${OPTARG} | tr "[:upper:]" "[:lower]" ) + + if [[ ${lcarg} == "gcc" ]]; then + echo "compile with gcc" + compiler="gcc" + elif [[ "${lcarg}" == "icx" ]]; then + echo "compile with icx" + compiler="icx" + else + echo "unknown compiler, use generic compiler cc:" + cc --version + fi + ;; + + O) optimization_given=${OPTARG} + ;; + + o) options_given=${OPTARG} + ;; + + g) debug_option=" -g3 " + ;; + + a) assert_on=1 + echo "compile with asserts on" + ;; + + p) support_papi=1 + echo "compile with PAPI support" + ;; + + h) print_help + ;; + :) echo "option -${OPTARG} requires an argument" + ;; + + ?) echo "invalid option -${OPTARG}" + ;; + esac done @@ -100,21 +117,32 @@ done # # set-up things # - -if [ ${compiler} == ${gcc} ]; + +if [[ ${options_given} == "none" ]]; +then + OPTIONS=${OPTIONS_DFLT} +else + OPTIONS=${options_given} +fi + +if [[ ${optimization_given} == "none" ]]; then - suffix=.gcc - OPTIMIZATION=${GCC_OPTS} - cc=gcc + OPTIMIZATION=${OPTIMIZATIONS[${compiler}]} else - suffix=.icx - OPTIMIZATION=${ICX_OPTS} - cc=icx + OPTIMIZATION=${optimization_given} fi +if [[ ${support_papi} == 1 ]]; then +OPTIONS="${OPTIONS} -D${SYS}" +fi + +OPTIONS="${OPTIONS} ${debug_option}" +suffix=.${compiler} + + if [[ ${assert_on} -eq 0 ]]; then - OPTS="${OPTS} ${ASSERT_OFF} " + OPTIONS=${OPTIONS}" ${ASSERT_OFF} " fi if [[ ${support_papi} -eq 1 ]]; @@ -127,6 +155,11 @@ else ADD_PAPI_LIB="" fi +echo "compiler's command line is: " +echo -I${INC_DIR} ${OPTIONS} ${OPTIMIZATION} ${ADD_PAPI_OPT} ${ADD_PAPI_LIB} +echo "source folder is " ${SRC_DIR} + + # # =========================================== # @@ -134,8 +167,8 @@ fi # -${cc} ${OPTS} ${ADD_PAPI_OPT} -I${INC_DIR} ${OPTIMIZATION} -o ${X_DIR}/vect.1${suffix} ${SRC_DIR}/vect.1.c ${ADD_PAPI_LIB} 2> compile.log.out -${cc} ${OPTS} ${ADD_PAPI_OPT} -I${INC_DIR} ${OPTIMIZATION} -o ${X_DIR}/vect.1b${suffix} ${SRC_DIR}/vect.1b.c -lm ${ADD_PAPI_LIB} 2>> compile.log.out +${compiler} ${OPTIONS} ${ADD_PAPI_OPT} -I${INC_DIR} ${OPTIMIZATION} -o ${X_DIR}/vect.1${suffix} ${SRC_DIR}/vect.1.c ${ADD_PAPI_LIB} 2> compile.log.out +${compiler} ${OPTIONS} ${ADD_PAPI_OPT} -I${INC_DIR} ${OPTIMIZATION} -o ${X_DIR}/vect.1b${suffix} ${SRC_DIR}/vect.1b.c -lm ${ADD_PAPI_LIB} 2>> compile.log.out -${cc} ${OPTS} ${ADD_PAPI_OPT} -I${INC_DIR} ${OPTIMIZATION} -o ${X_DIR}/vect.2${suffix} ${SRC_DIR}/vect.2.c ${ADD_PAPI_LIB} 2>> compile.log.out -${cc} ${OPTS} ${ADD_PAPI_OPT} -I${INC_DIR} ${OPTIMIZATION} -o ${X_DIR}/vect.2b${suffix} ${SRC_DIR}/vect.2b.c -lm ${ADD_PAPI_LIB} 2>> compile.log.out +${compiler} ${OPTIONS} ${ADD_PAPI_OPT} -I${INC_DIR} ${OPTIMIZATION} -o ${X_DIR}/vect.2${suffix} ${SRC_DIR}/vect.2.c ${ADD_PAPI_LIB} 2>> compile.log.out +${compiler} ${OPTIONS} ${ADD_PAPI_OPT} -I${INC_DIR} ${OPTIMIZATION} -o ${X_DIR}/vect.2b${suffix} ${SRC_DIR}/vect.2b.c -lm ${ADD_PAPI_LIB} 2>> compile.log.out