--- MITgcm/tools/genmake2 2006/04/07 02:53:55 1.146 +++ MITgcm/tools/genmake2 2008/02/15 19:33:34 1.169 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.146 2006/04/07 02:53:55 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.169 2008/02/15 19:33:34 jmc Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -325,7 +325,7 @@ #================================================================ # look for possible C compilers - tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc" + tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc" p_CC= for c in $tmp ; do rm -f ./genmake_hello.c ./genmake_hello @@ -364,7 +364,7 @@ #================================================================ # look for possible FORTRAN compilers - tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 gfortran" + tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc ifort f90 f95 mpif77 mpf77 mpxlf95 gfortran g95" p_FC= for c in $tmp ; do rm -f ./hello.f ./hello @@ -587,16 +587,22 @@ -ts | --ts Produce timing information per timestep -papis | --papis - Produce summary MFlop/s with PAPI per timestep + Produce summary MFlop/s (and IPC) with PAPI per timestep + -pcls | --pcls + Produce summary MFlop/s etc. with PCL per timestep -foolad | --foolad Fool the AD code generator -papi | --papi Performance analysis with PAPI + -pcl | --pcl + Performance analysis with PCL -hpmt | --hpmt Performance analysis with the HPM Toolkit -gsl | --gsl Use GSL to control floating point rounding and precision + -devel | --devel + Add additional warning and debugging flags for development -mpi | --mpi Include MPI header files and link to MPI libraries @@ -740,7 +746,9 @@ *curtim = *curtim/1.E6; } EOF - make genmake_tc_1.o >> genmake_warnings 2>&1 + COMM="$CC $CFLAGS -c genmake_tc_1.c" + echo $COMM >> genmake_warnings + $COMM >> genmake_warnings 2>&1 RET_C=$? cat < genmake_tc_2.$FS program hello @@ -750,7 +758,9 @@ print *," HELLO WORLD", wtime end EOF - $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1 + COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" + echo $COMM >> genmake_warnings + $COMM >> genmake_warnings 2>&1 RET_F=$? test -x ./genmake_tc && ./genmake_tc >> genmake_warnings 2>&1 RETVAL=$? @@ -763,6 +773,9 @@ check_HAVE_SIGREG() { + if test ! "x$HAVE_SIGREG" = x ; then + return + fi get_fortran_c_namemangling cat < genmake_tc_1.c $FC_NAMEMANGLE @@ -794,7 +807,9 @@ return; } EOF - make genmake_tc_1.o >> genmake_warnings 2>&1 + COMM="$CC $CFLAGS -c genmake_tc_1.c" + echo $COMM >> genmake_warnings + $COMM >> genmake_warnings 2>&1 RET_C=$? cat < genmake_tc_2.$FS program hello @@ -820,6 +835,13 @@ check_HAVE_SETRLSTK() { + if test "x$HAVE_SETRLSTK" = xt ; then + DEFINES="$DEFINES -DHAVE_SETRLSTK" + return + fi + if test ! "x$HAVE_SETRLSTK" = x ; then + return + fi get_fortran_c_namemangling cat < genmake_tc_1.c $FC_NAMEMANGLE @@ -835,7 +857,9 @@ return; } EOF - make genmake_tc_1.o >> genmake_warnings 2>&1 + COMM="$CC $CFLAGS -c genmake_tc_1.c" + echo $COMM >> genmake_warnings + $COMM >> genmake_warnings 2>&1 RET_C=$? cat < genmake_tc_2.$FS program hello @@ -879,7 +903,9 @@ *nbyte = -1; } EOF - make genmake_tc_1.o >> genmake_tc.log 2>&1 + COMM="$CC $CFLAGS -c genmake_tc_1.c" + echo $COMM >> genmake_warnings + $COMM >> genmake_tc.log 2>&1 RET_C=$? cat < genmake_tc_2.$FS program hello @@ -930,9 +956,9 @@ cat genmake_tnc.F >> genmake_tnc.log echo "=== genmake_tnc.F ===" >> genmake_tnc.log RET_CPP=f - COMM="$CPP $DEFINES $INCLUDES genmake_tnc.F" + COMM="cat genmake_tnc.F | $CPP $DEFINES $INCLUDES" echo "$COMM" >> genmake_tnc.log - $COMM > genmake_tnc.$FS 2>/dev/null && RET_CPP=t + eval $COMM > genmake_tnc.$FS 2>/dev/null && RET_CPP=t if test "x$RET_CPP" = xf ; then echo " WARNING: CPP failed to pre-process the netcdf test." \ >> genmake_tnc.log @@ -940,9 +966,9 @@ >> genmake_tnc.log fi echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log - echo " && $LINK -o genmake_tnc.o $LIBS" >> genmake_tnc.log + echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc.o $LIBS" >> genmake_tnc.log $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \ - && $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1 + && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1 RET_COMPILE=$? cat genmake_tnc.log >> genmake_warnings @@ -958,17 +984,32 @@ else # try again with "-lnetcdf" added to the libs echo "try again with added '-lnetcdf'" > genmake_tnc.log - echo "$CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS \ " >> genmake_tnc.log + echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log echo " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log - echo " && $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log - $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null \ + echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log + cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null \ && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \ - && $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1 + && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1 RET_COMPILE=$? cat genmake_tnc.log >> genmake_warnings if test "x$RET_COMPILE" = x0 ; then LIBS="$LIBS -lnetcdf" HAVE_NETCDF=t + else + # try again with "-lnetcdff" added to the libs + echo "try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log + echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log + echo " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log + echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log + cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null \ + && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \ + && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf >> genmake_tnc.log 2>&1 + RET_COMPILE=$? + cat genmake_tnc.log >> genmake_warnings + if test "x$RET_COMPILE" = x0 ; then + LIBS="$LIBS -lnetcdff -lnetcdf" + HAVE_NETCDF=t + fi fi fi rm -f genmake_tnc* @@ -1004,6 +1045,7 @@ INCLUDES="-I. $INCLUDES" FFLAGS= FOPTIM= +FEXTRAFLAGS= CFLAGS= KFLAGS1= KFLAGS2= @@ -1016,10 +1058,13 @@ MPIPATH= TS= PAPIS= +PCLS= FOOLAD= PAPI= +PCL= HPMT= GSL= +DEVEL= HAVE_TEST_L= # DEFINES checked by test compilation or command-line @@ -1027,7 +1072,7 @@ HAVE_FDATE= FC_NAMEMANGLE= HAVE_CLOC= -HAVE_SETRLSTK= +# HAVE_SETRLSTK= HAVE_STAT= HAVE_NETCDF= HAVE_ETIME= @@ -1078,10 +1123,10 @@ # The following state can be set directly by command-line switches gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE" -gm_s2="FC CPP IEEE TS PAPIS PAPI HPMT GSL MPI JAM DUMPSTATE STANDARDDIRS" +gm_s2="FC CPP IEEE TS PAPIS PCLS PAPI PCL HPMT GSL DEVEL MPI JAM DUMPSTATE STANDARDDIRS" # The following state is not directly set by command-line switches -gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM " +gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM FEXTRAFLAGS" gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS" gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE" gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF" @@ -1108,12 +1153,6 @@ echo "=== Processing options files and arguments ===" gm_local="genmake_local" -for i in . $MODS ; do - if test -r $i/$gm_local ; then - . $i/$gm_local - break - fi -done printf " getting local config information: " if test -f $gm_local ; then echo "using $gm_local" @@ -1262,16 +1301,23 @@ TS=true ;; -papis | --papis) PAPIS=true ;; + -pcls | --pcls) + PCLS=true ;; -foolad | --foolad) FOOLAD=true ;; -papi | --papi) PAPI=true ;; + -pcl | --pcl) + PCL=true ;; -hpmt | --hpmt) HPMT=true ;; -gsl | --gsl) GSL=true ;; + -devel | --devel) + DEVEL=true ;; + -mpi | --mpi) MPI=true ;; -mpi=* | --mpi=*) @@ -1320,19 +1366,18 @@ if test -f ./.genmakerc ; then echo echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\"" - echo " file. This file format is no longer supported. Please see:" - echo + echo " file. This file format is no longer supported. For directions on" + echo " how to setup and use the new \"genmake2\" script, please see:" echo " http://mitgcm.org/devel_HOWTO/" - echo - echo " for directions on how to setup and use the new \"genmake2\" input" - echo " files and send an email to MITgcm-support@mitgcm.org if you want help." + echo " and send an email to MITgcm-support@mitgcm.org if you need help." + echo "WARNING: ignore \"./.genmakerc\" and continue." echo fi # Find the MITgcm ${ROOTDIR} if test "x${ROOTDIR}" = x ; then tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'` - if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then + if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesupp -a -d ../pkg ; then ROOTDIR=".." else for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do @@ -1522,6 +1567,7 @@ else DEFINES="$DEFINES -DTIME_PER_TIMESTEP" fi + PACKAGES="$PACKAGES showflops" fi if test ! "x$PAPIS" = x ; then echo " Turning on PAPI flop summary per timestep" @@ -1533,6 +1579,19 @@ fi INCLUDES="$INCLUDES $PAPIINC" LIBS="$LIBS $PAPILIB" + PACKAGES="$PACKAGES showflops" +fi +if test ! "x$PCLS" = x ; then + echo " Turning on PCL counter summary per timestep" + echo " Please make sure PCLINC, PCLLIB are defined" + if test ! "x$FOOLAD" = x ; then + DEFINES="$DEFINES -DUSE_PCL_FLOPS_SFP" + else + DEFINES="$DEFINES -DUSE_PCL_FLOPS" + fi + INCLUDES="$INCLUDES $PCLINC" + LIBS="$LIBS $PCLLIB" + PACKAGES="$PACKAGES showflops" fi if test ! "x$PAPI" = x ; then if test ! "x$PAPIS" = x ; then @@ -1546,10 +1605,25 @@ LIBS="$LIBS $PAPILIB" fi fi +if test ! "x$PCL" = x ; then + if test ! "x$PCLS" = x ; then + echo " PCL performance analysis and flop summary per timestep cannot co-exist!" + echo " Sticking with PCL flop summary per timestep!" + else + echo " Turning on performance analysis with PCL" + echo " Please make sure PCLINC, PCLLIB are defined" + DEFINES="$DEFINES -DUSE_PCL" + INCLUDES="$INCLUDES $PCLINC" + LIBS="$LIBS $PCLLIB" + fi +fi if test ! "x$HPMT" = x ; then if test ! "x$PAPI" = x ; then echo " PAPI and the HPM Toolkit cannot co-exist!" echo " Sticking with PAPI!" + else if test ! "x$PCL" = x ; then + echo " PCL and the HPM Toolkit cannot co-exist!" + echo " Sticking with PCL!" else echo " Turning on performance analysis with the HPM Toolkit" echo " Please make sure HPMTINC, HPMTLIB are defined" @@ -1557,6 +1631,7 @@ INCLUDES="$INCLUDES $HPMTINC" LIBS="$LIBS $HPMTLIB" fi + fi fi if test ! "x$GSL" = x ; then echo " Turning on use of GSL to control floating point calculations" @@ -1644,7 +1719,7 @@ printf " Can we unlimit the stack size using $FC... " check_HAVE_SETRLSTK -if test "x$HAVE_SETRLSTK" != x ; then +if test "x$HAVE_SETRLSTK" = xt ; then echo "yes" else echo "no" @@ -1653,7 +1728,7 @@ printf " Can we register a signal handler using $FC... " check_HAVE_SIGREG -if test "x$HAVE_SIGREG" != x ; then +if test "x$HAVE_SIGREG" = xt ; then echo "yes" else echo "no" @@ -1771,19 +1846,21 @@ fi fi -#same for exch2 -if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then - echo " Making source files in exch2 from templates" - ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1 - RETVAL=$? - if test "x${RETVAL}" = x0 ; then - rm -f make_exch2.errors - else - echo "Error: problem encountered while building source files in exch2:" - cat make_exch2.errors 1>&2 - exit 1 +#same for pkg/exch2 and pkg/regrid +for pdir in exch2 regrid ; do + if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then + echo " Making source files in pkg/${pdir} from templates" + ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE ) > make_${pdir}.errors 2>&1 + RETVAL=$? + if test "x${RETVAL}" = x0 ; then + rm -f make_${pdir}.errors + else + echo "Error: problem encountered while building source files in pkg/${pdir}:" + cat make_${pdir}.errors 1>&2 + exit 1 + fi fi -fi +done printf "\n=== Determining package settings ===\n" if test "x${PDEPEND}" = x ; then @@ -1894,8 +1971,8 @@ rm -f ./.tmp_pack echo " packages are: $PACKAGES" -# Check availability of NetCDF and then either build the MNC template -# files or delete mnc from the list of available packages. +# Check for package MNC: if NetCDF is available, then build the MNC +# template files ; otherwise, delete mnc from the list of packages. echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then @@ -1929,13 +2006,38 @@ fi fi +# Check for package PROFILES: if NetCDF is not available, +# then delete profiles from the list of available packages. +echo $PACKAGES | grep ' profiles ' > /dev/null 2>&1 +RETVAL=$? +if test "x$RETVAL" = x0 ; then + if test "x$HAVE_NETCDF" != xt ; then + cat < \$@ clean: - -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template + -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template + -rm -rf *.o + -rm -rf *.$FS Clean: @make clean @make cleanlinks -rm -f \$(SPECIAL_FILES) -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak + -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log CLEAN: @make Clean -find \$(EXEDIR) -name "*.meta" -exec rm {} \; -find \$(EXEDIR) -name "*.data" -exec rm {} \; -find \$(EXEDIR) -name "fort.*" -exec rm {} \; - -rm -f \$(EXECUTABLE) *.txt STD* *diagnostics.log datetime + -rm -f \$(EXECUTABLE) \$(EXE_AD) *.txt STD* *diagnostics.log datetime + -rm -f *_MIT_CE_000.opt0000 costfunction*0000 -rm -rf mnc_test_* #eh3 Makefile: makefile @@ -2489,9 +2597,9 @@ \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ .$FS.o: \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< -.F90.$FS90: - \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ -.$FS90.o: +.F.o: + \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< +.F90.o: \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$< .c.o: \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$< @@ -2518,10 +2626,10 @@ ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS" for i in $ad_vars ; do name=$i - t1="t2=\$"`echo $i` + t1="t2=\$"`echo "$i"` eval $t1 printf "%-20s = " $name >> $MAKEFILE - echo $t2 >> $MAKEFILE + echo "$t2" | sed -e 's| \+| |g' >> $MAKEFILE done echo " Add the source list for AD code generation" @@ -2538,7 +2646,7 @@ cat >>$MAKEFILE < ad_taf_output.$FS -ad_taf: ad_taf_output.o \$(OBJFILES) - \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS) +\${EXE_AD}: ad_taf_output.o \$(OBJFILES) + \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS) ad_tamc_output.$FS: ad_input_code.$FS \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS