--- MITgcm/tools/genmake2 2005/10/15 00:35:36 1.133 +++ MITgcm/tools/genmake2 2005/12/22 01:22:27 1.139 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.133 2005/10/15 00:35:36 edhill Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.139 2005/12/22 01:22:27 ce107 Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -353,10 +353,18 @@ else echo " The possible FORTRAN compilers found in your path are:" echo " "$p_FC - if test "x$FC" = x ; then - FC=`echo $p_FC | $AWK '{print $1}'` - echo " Setting FORTRAN compiler to: "$FC - fi + fi + + # Use the first of the compilers found in the current PATH + # that has a correctly-named optfile + if test "x$OPTFILE" = x -a "x$FC" = x ; then + for i in $p_FC ; do + OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i + if test -r $OPTFILE ; then + echo " Setting OPTFILE to: "$OPTFILE + break + fi + done fi if test "x$OPTFILE" = x ; then @@ -529,6 +537,17 @@ -ts | --ts Produce timing information per timestep + -papis | --papis + Produce summary MFlop/s with PAPI per timestep + -foolad | --foolad + Fool the AD code generator + -papi | --papi + Performance analysis with PAPI + -hpmt | --hpmt + Performance analysis with the HPM Toolkit + + -gsl | --gsl + Use GSL to control floating point rounding and precision -mpi | --mpi Include MPI header files and link to MPI libraries @@ -601,7 +620,7 @@ call tsub( string ) end EOF - $FC $FFLAGS $DEFINES -c genmake_tcomp.$FS >> genmake_warnings 2>&1 + $FC $FFLAGS -c genmake_tcomp.$FS >> genmake_warnings 2>&1 RETVAL=$? if test "x$RETVAL" != x0 ; then FC_NAMEMANGLE=$default_nm @@ -689,6 +708,63 @@ } +check_HAVE_SIGREG() { + get_fortran_c_namemangling + cat < genmake_tc_1.c +$FC_NAMEMANGLE +#include +#include +#include +#include +#include + +int * ip; + +static void killhandler( + unsigned int sn, siginfo_t si, struct ucontext *sc ) +{ + *ip = *ip + 1; + return; +} + +void FC_NAMEMANGLE(sigreg) (int * aip) +{ + struct sigaction s; + ip = aip; + s.sa_flags = SA_SIGINFO; + s.sa_sigaction = (void *)killhandler; + if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) { + printf("Sigaction returned error = %d\n", errno); + exit(0); + } + return; +} +EOF + make genmake_tc_1.o >> genmake_warnings 2>&1 + RET_C=$? + cat < genmake_tc_2.$FS + program hello + integer anint + common /iv/ anint + external sigreg + call sigreg(anint) + end +EOF + echo >> genmake_warnings + echo "running: check_HAVE_SIGREG()" >> genmake_warnings + cat genmake_tc_2.$FS >> genmake_warnings + COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" + echo $COMM >> genmake_warnings + $COMM >> genmake_warnings 2>&1 + RETVAL=$? + if test "x$RETVAL" = x0 ; then + HAVE_SIGREG=t + DEFINES="$DEFINES -DHAVE_SIGREG" + fi + rm -f genmake_tc* +} + + check_HAVE_SETRLSTK() { get_fortran_c_namemangling cat < genmake_tc_1.c @@ -713,9 +789,12 @@ call setrlstk() end EOF - $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1 - RET_F=$? - test -x ./genmake_tc && ./genmake_tc >> genmake_warnings 2>&1 + echo >> genmake_warnings + echo "running: check_HAVE_SETRLSTK()" >> genmake_warnings + cat genmake_tc_2.$FS >> genmake_warnings + COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" + echo $COMM >> genmake_warnings + $COMM >> genmake_warnings 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_SETRLSTK=t @@ -755,9 +834,12 @@ print *," HELLO WORLD", nbyte end EOF - $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_tc.log 2>&1 - RET_F=$? - test -x ./genmake_tc && ./genmake_tc >> genmake_tc.log 2>&1 + echo >> genmake_warnings + echo "running: check_HAVE_STAT()" >> genmake_warnings + cat genmake_tc_2.$FS >> genmake_warnings + COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o" + echo $COMM >> genmake_warnings + $COMM >> genmake_tc.log 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_STAT=t @@ -771,7 +853,8 @@ if test ! "x$SKIP_NETCDF_CHECK" = x ; then return fi - echo "" > genmake_tnc.log + echo >> genmake_warnings + echo "running: check_netcdf_libs()" >> genmake_warnings cat < genmake_tnc.F program fgennc #include "netcdf.inc" @@ -789,24 +872,25 @@ IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret) end EOF - echo "Executing:" > genmake_tnc.log - echo " $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS" \ - >> genmake_tnc.log + echo "=== genmake_tnc.F ===" > genmake_tnc.log + cat genmake_tnc.F >> genmake_tnc.log + echo "=== genmake_tnc.F ===" >> genmake_tnc.log RET_CPP=f - $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null \ - && RET_CPP=t + COMM="$CPP $DEFINES $INCLUDES genmake_tnc.F" + echo "$COMM" >> genmake_tnc.log + $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 echo " Please check that \$INCLUDES is properly set." \ >> genmake_tnc.log fi - echo "Executing:" > genmake_tnc.log - echo " $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS" >> genmake_tnc.log - echo " $LINK -o genmake_tnc.o $LIBS" >> genmake_tnc.log + echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log + echo " && $LINK -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 RET_COMPILE=$? + cat genmake_tnc.log >> genmake_warnings #EH3 Remove test program execution for machines that either disallow #EH3 execution or cannot support it (eg. cross-compilers) @@ -819,6 +903,7 @@ HAVE_NETCDF=t 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 " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log echo " && $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log @@ -826,14 +911,10 @@ && $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 RET_COMPILE=$? + cat genmake_tnc.log >> genmake_warnings if test "x$RET_COMPILE" = x0 ; then LIBS="$LIBS -lnetcdf" HAVE_NETCDF=t - else - echo "=== genmake_tnc.F ===" >> genmake_warnings - cat genmake_tnc.F >> genmake_warnings - echo "=== genmake_tnc.F ===" >> genmake_warnings - cat genmake_tnc.log >> genmake_warnings fi fi rm -f genmake_tnc* @@ -880,6 +961,11 @@ MPI= MPIPATH= TS= +PAPIS= +FOOLAD= +PAPI= +HPMT= +GSL= HAVE_TEST_L= # DEFINES checked by test compilation or command-line @@ -937,7 +1023,7 @@ # 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 MPI JAM DUMPSTATE STANDARDDIRS" +gm_s2="FC CPP IEEE TS PAPIS PAPI HPMT GSL 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 " @@ -1119,6 +1205,17 @@ -ts | --ts) TS=true ;; + -papis | --papis) + PAPIS=true ;; + -foolad | --foolad) + FOOLAD=true ;; + -papi | --papi) + PAPI=true ;; + -hpmt | --hpmt) + HPMT=true ;; + + -gsl | --gsl) + GSL=true ;; -mpi | --mpi) MPI=true ;; @@ -1362,7 +1459,53 @@ if test ! "x$TS" = x ; then echo " Turning on timing per timestep" - DEFINES="$DEFINES -DTIME_PER_TIMESTEP" + if test ! "x$FOOLAD" = x ; then + DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP" + else + DEFINES="$DEFINES -DTIME_PER_TIMESTEP" + fi +fi +if test ! "x$PAPIS" = x ; then + echo " Turning on PAPI flop summary per timestep" + echo " Please make sure PAPIINC, PAPILIB are defined" + if test ! "x$FOOLAD" = x ; then + DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP" + else + DEFINES="$DEFINES -DUSE_PAPI_FLOPS" + fi + INCLUDES="$INCLUDES $PAPIINC" + LIBS="$LIBS $PAPILIB" +fi +if test ! "x$PAPI" = x ; then + if test ! "x$PAPIS" = x ; then + echo " PAPI performance analysis and flop summary per timestep cannot co-exist!" + echo " Sticking with PAPI flop summary per timestep!" + else + echo " Turning on performance analysis with PAPI" + echo " Please make sure PAPIINC, PAPILIB are defined" + DEFINES="$DEFINES -DUSE_PAPI" + INCLUDES="$INCLUDES $PAPIINC" + LIBS="$LIBS $PAPILIB" + 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 + echo " Turning on performance analysis with the HPM Toolkit" + echo " Please make sure HPMTINC, HPMTLIB are defined" + DEFINES="$DEFINES -DUSE_LIBHPM" + INCLUDES="$INCLUDES $HPMTINC" + LIBS="$LIBS $HPMTLIB" + fi +fi +if test ! "x$GSL" = x ; then + echo " Turning on use of GSL to control floating point calculations" + echo " Please make sure GSLINC, GSLLIB are defined" + DEFINES="$DEFINES -DUSE_GSL_IEEE" + INCLUDES="$INCLUDES $GSLINC" + LIBS="$LIBS $GSLLIB" fi printf "\n=== Checking system libraries ===\n" @@ -1372,7 +1515,7 @@ call system('echo hi') end EOF -$FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1 +$FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_SYSTEM=t @@ -1393,7 +1536,7 @@ print *, string end EOF -$FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1 +$FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_FDATE=t @@ -1415,7 +1558,7 @@ print *, tarray end EOF -$FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1 +$FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then HAVE_ETIME=t @@ -1445,6 +1588,15 @@ fi rm -f genmake_t* +printf " Can we register a signal handler using $FC... " +check_HAVE_SIGREG +if test "x$HAVE_SIGREG" != x ; then + echo "yes" +else + echo "no" +fi +rm -f genmake_t* + printf " Can we use stat() through C calls... " check_HAVE_STAT if test "x$HAVE_STAT" != x ; then @@ -1914,6 +2066,31 @@ fi done +echo " Creating the pseudo-MPI include directory" +if test ! "x$DIVA" = x ; then + INCLUDES="-I./mpi_headers $INCLUDES" + rm -rf ./mpi_headers + mkdir -p ./mpi_headers + + if test "x$MPIINCLUDEDIR" = x ; then + if test "x$MPIHOME" = x ; then + MPIHOME='/usr' + fi + MPIINCLUDEDIR='$MPIHOME/include' + fi + + if test -r $MPIINCLUDEDIR/mpif.h ; then + for i in $MPI_HEADER_FILES; do + cp -p $MPIINCLUDEDIR/$i ./mpi_headers + done + + perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h + else + echo " We cannot create a copy of mpif.h!" + exit -1 + fi +fi + echo " Determining the list of source and include files" rm -rf .links.tmp mkdir .links.tmp @@ -2197,7 +2374,7 @@ .$FS90.o: \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$< .c.o: - \$(CC) \$(CFLAGS) -c \$< + \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$< # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain .F.p: