--- MITgcm/tools/genmake2 2008/12/11 17:50:56 1.180 +++ MITgcm/tools/genmake2 2010/05/23 03:45:58 1.205 @@ -1,6 +1,6 @@ #! /usr/bin/env bash # -# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.180 2008/12/11 17:50:56 utke Exp $ +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/genmake2,v 1.205 2010/05/23 03:45:58 jmc Exp $ # # Makefile generator for MITgcm UV codes # created by cnh 03/98 @@ -480,12 +480,16 @@ # strip the comments and then convert the dependency file into # two arrays: PNAME, DNAME cat $1 | sed -e 's/#.*$//g' \ - | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \ + | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \ > ./.pd_tmp + RETVAL=$? + if test ! "x${RETVAL}" = x0 ; then + echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$1\"" + exit 1 + fi . ./.pd_tmp rm -f ./.pd_tmp - printf "PNAME = "${} } @@ -519,6 +523,9 @@ -pdefault=NAME | --pdefault=NAME Get the default package list from "NAME". + -bash NAME + Explicitly specify the Bourne or BASH shell to use + -make NAME | -m NAME --make=NAME | -m=NAME Use "NAME" for the MAKE program. The default is "make" but @@ -578,6 +585,10 @@ *only* works if it is supported by the OPTFILE that is being used. + -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 + Use "real*4" type for _RS variable (#undef REAL4_IS_SLOW) + *only* works if CPP_EEOPTIONS.h allows this. + -ignoretime | -ignore_time | --ignoretime | --ignore_time Ignore all the "wall clock" routines entirely. This will not in any way hurt the model results -- it simply means @@ -611,14 +622,16 @@ set to PATH. i.e. Include files from \$PATH/include, link to libraries from \$PATH/lib and use binaries from \$PATH/bin. + -omp | --omp + Activate OpenMP code + use Compiler option OMPFLAG + -omp=OMPFLAG | --omp=OMPFLAG + Activate OpenMP code + use Compiler option OMPFLAG + -es | --es | -embed-source | --embed-source Embed a tarball containing the full source code (including the Makefile, etc.) used to build the executable [off by default] - -bash NAME - Explicitly specify the Bourne or BASH shell to use - While it is most often a single word, the "NAME" variables specified above can in many cases be a space-delimited string such as: @@ -630,7 +643,7 @@ For more detailed genmake documentation, please see: - http://mitgcm.org/devel_HOWTO/ + http://mitgcm.org/public/devel_HOWTO/ EOF @@ -1046,6 +1059,8 @@ FFLAGS= FOPTIM= FEXTRAFLAGS= +USE_EXTENDED_SRC= +EXTENDED_SRC_FLAG= CFLAGS= KFLAGS1= KFLAGS2= @@ -1056,6 +1071,9 @@ NOOPTFLAGS= MPI= MPIPATH= +OMP= +OMPFLAG= +USE_R4= TS= PAPIS= PCLS= @@ -1123,7 +1141,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 PAPIS PCLS PAPI PCL HPMT GSL DEVEL MPI JAM DUMPSTATE STANDARDDIRS" +gm_s2="FC IEEE USE_R4 TS PAPIS PCLS PAPI PCL HPMT GSL DEVEL MPI OMP 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 FEXTRAFLAGS" @@ -1164,15 +1182,6 @@ fi #echo "$0::$1:$2:$3:$4:$5:$6:$7:" -#OPTIONS= -#n=0 -#for i ; do -# echo "$i $n" -# setvar="OPTIONS[$n]='$i'" -# # echo " $setvar" -# eval "$setvar" -# n=$(( $n + 1 )) -#done #parse_options ac_prev= for ac_option in "$@" ; do @@ -1297,6 +1306,9 @@ -noieee | --noieee) IEEE= ;; + -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 ) + USE_R4=true ;; + -ts | --ts) TS=true ;; -papis | --papis) @@ -1324,10 +1336,11 @@ MPIPATH=$ac_optarg MPI=true ;; -# -jam | --jam) -# JAM=1 ;; -# -nojam | --nojam) -# JAM=0 ;; + -omp | --omp) + OMP=true ;; + -omp=* | --omp=*) + OMPFLAG=$ac_optarg + OMP=true ;; -ds | --ds) DUMPSTATE=t ;; @@ -1404,7 +1417,7 @@ # Find the MITgcm ${THISVER} version_file="${ROOTDIR}/doc/tag-index" if test -f $version_file ; then - THISVER=`grep '^checkpoint' $version_file | head -1` + THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file` #- remove ./BUILD_INFO.h file if older than version_file if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then echo " remove ./BUILD_INFO.h (older than ${version_file})" @@ -1565,6 +1578,17 @@ echo " Turning on MPI cpp macros" DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI" fi +if test ! "x$OMP" = x ; then + echo " Add OMPFLAG and turn on OpenMP cpp macros" + FFLAGS="$FFLAGS $OMPFLAG" + F90FLAGS="$F90FLAGS $OMPFLAG" + DEFINES="$DEFINES -DUSE_OMP_THREADING" +fi + +if test ! "x$USE_R4" = x ; then + echo " Turning on LET_RS_BE_REAL4 cpp flag" + DEFINES="$DEFINES -DLET_RS_BE_REAL4" +fi if test ! "x$TS" = x ; then echo " Turning on timing per timestep" @@ -1646,6 +1670,11 @@ INCLUDES="$INCLUDES $GSLINC" LIBS="$LIBS $GSLLIB" fi +#- if USE_EXTENDED_SRC is set, add EXTENDED_SRC_FLAG to FFLAGS : +if test ! "x$USE_EXTENDED_SRC" = x ; then + FFLAGS="$FFLAGS $EXTENDED_SRC_FLAG" + F90FIXEDFORMAT="$F90FIXEDFORMAT $EXTENDED_SRC_FLAG" +fi printf "\n=== Checking system libraries ===\n" printf " Do we have the system() command using $FC... " @@ -1768,14 +1797,14 @@ printf "\n=== Setting defaults ===\n" -printf " Adding MODS directories: " +printf " Adding MODS directories: " for d in $MODS ; do if test ! -d $d ; then echo echo "Error: MODS directory \"$d\" not found!" exit 1 else - printf " $d" + printf "$d " SOURCEDIRS="$SOURCEDIRS $d" INCLUDEDIRS="$INCLUDEDIRS $d" fi @@ -1836,6 +1865,19 @@ EXECUTABLE=${EXECUTABLE:-mitgcmuv} +# Set Standard Code Directories: +if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then + STANDARDDIRS="eesupp model" +fi +# if model in Standard-Code-Dir, add eesupp (needed to compile model) +echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1 +ckM=$? +echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1 +ckE=$? +if test $ckM = 0 -a $ckE = 1 ; then + STANDARDDIRS="$STANDARDDIRS eesupp" +fi + # We have a special set of source files in eesupp/src which are # generated from some template source files. We'll make them first so # they appear as regular source code @@ -1886,20 +1928,11 @@ echo " getting package dependency info from $PDEPEND" # Strip the comments and then convert the dependency file into # two arrays: PNAME, DNAME -cat $PDEPEND | sed -e 's/#.*$//g' \ - | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \ - > ./.pd_tmp -RETVAL=$? -if test ! "x${RETVAL}" = x0 ; then - echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\"" - exit 1 -fi -. ./.pd_tmp -rm -f ./.pd_tmp +get_pdepend_list $PDEPEND # Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups" -# file should eventually be added so that, for convenience, one can -# specify groups of packages using names like "ocean" and "atmosphere". +# file has been added so that, for convenience, one can specify +# groups of packages using names like "ocean" and "atmosphere". echo " checking default package list: " if test "x${PDEFAULT}" = x ; then for i in "." $MODS ; do @@ -1930,14 +1963,15 @@ for i in $def ; do PACKAGES="$PACKAGES $i" done - echo " before group expansion packages are: $PACKAGES" + echo " before group expansion packages are:$PACKAGES" RET=1 while test $RET = 1 ; do expand_pkg_groups; RET=$?; done - echo " after group expansion packages are: $PACKAGES" + echo " after group expansion packages are: $PACKAGES" fi fi echo " applying DISABLE settings" +echo "" > ./.tmp_pack for i in $PACKAGES ; do echo $i >> ./.tmp_pack done @@ -1975,11 +2009,11 @@ PACKAGES="$PACKAGES $i" done rm -f ./.tmp_pack -echo " packages are: $PACKAGES" +echo " packages are: $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 +echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then if test "x$HAVE_NETCDF" != xt ; then @@ -2014,7 +2048,7 @@ # 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 +echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1 RETVAL=$? if test "x$RETVAL" = x0 ; then if test "x$HAVE_NETCDF" != xt ; then @@ -2055,6 +2089,10 @@ pin="t" fi done + # or in the current $STANDARDDIRS list? + for p in $STANDARDDIRS ; do + if test "x$p" = "x$pname" ; then pin="t" ; fi + done # Is the DNAME entry a (+) or (-) rule ? tmp="dname=\"\$DNAME_$i\"" @@ -2107,7 +2145,7 @@ done ck=$ck"t" done -echo " packages are: $PACKAGES" +echo " packages are: $PACKAGES" for i in $PACKAGES ; do adr="$ROOTDIR/pkg/$i" if test -d $adr ; then @@ -2163,11 +2201,8 @@ done -echo " Adding STANDARDDIRS" +echo " Adding STANDARDDIRS='$STANDARDDIRS'" BUILDDIR=${BUILDDIR:-.} -if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then - STANDARDDIRS="eesupp model" -fi if test "x$STANDARDDIRS" != x ; then for d in $STANDARDDIRS ; do adr="$ROOTDIR/$d/src" @@ -2455,8 +2490,14 @@ echo "" >> hsrclist.tmp echo "" >> ad_flow_files.tmp +CMDLINE=$0 +for xx in "$@" ; do nw=`echo $xx | wc -w` + if test $nw = '1' ; then CMDLINE="$CMDLINE $xx" + else CMDLINE="$CMDLINE '$xx'" ; fi +done + if test -f $MAKEFILE ; then - mv -f $MAKEFILE "$MAKEFILE.bak" + mv -f $MAKEFILE "$MAKEFILE.old" fi echo " Writing makefile: $MAKEFILE" echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE @@ -2464,7 +2505,7 @@ echo "# This makefile was generated automatically on" >> $MAKEFILE echo "# $THISDATE" >> $MAKEFILE echo "# by the command:" >> $MAKEFILE -echo "# $0 $G2ARGS" >> $MAKEFILE +echo "# $CMDLINE" >> $MAKEFILE echo "# executed by:" >> $MAKEFILE echo "# ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE @@ -2475,7 +2516,7 @@ cat >>$MAKEFILE <>$MAKEFILE < ad_config.template cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h -rm -f ad_config.template @make \$(F77_PP_SRC_FILES) @make \$(FLOFILES) - cat \$(FLOFILES) \$(AD_FILES) > ad_input_code.$FS + cat \$(FLOFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS ad_taf_output.$FS: ad_input_code.$FS \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS @@ -2951,11 +2991,31 @@ f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1 f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1 -AD_OBJ_FILES=\$(OPENAD_SUPPORT_F90_SRC_FILES:.F90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o) all_mods.xb.x2w.w2f.pp.o ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.o \$(NON_AD_F77_SRC_FILES:.F=_cb2m.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o) +# the file included below is created by the +# postProcessor and its inclusion sets the +# variable POSTPROCESSEDFILES +# used below. Because the file is made during +# make it won't be read until the second (recursive) +# invocation in the rule below +-include postProcess.make + +AD_OBJ_FILES_S1=\$(OPENAD_SUPPORT_F90_SRC_FILES:.F90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o) \$(POSTPROCESSEDFILES:.f$FS90=.o) + +AD_OBJ_FILES_S2=\$(AD_OBJ_FILES_S1) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o) + +postProcess.comp: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S1) +ifeq (\$(MAKELEVEL),0) + \$(MAKE) adAll +else + touch \$@ +endif -\$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(AD_OBJ_FILES) - @echo Creating \$@ ... - \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES) \$(LIBS) +\$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.comp \$(AD_OBJ_FILES_S2) +ifeq (\$(MAKELEVEL),1) + \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS) +else + touch \$@ +endif # makefile debug rule openad: ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90 @@ -2985,7 +3045,7 @@ @./\$(EXE_AD) > \$@ CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90) -ad_input_code.f$FS90: ../OAD_support/maxMinDefs.f \$(CB2M_AD_FILES) +ad_input_code.f$FS90: \$(CB2M_AD_FILES) cat \$^ > \$@ # strip all comments and blanks to reduce @@ -3005,7 +3065,7 @@ # canonicalizer ad_input_code_sf.w2f.pre.f$FS90: ad_input_code_sf.w2f.f$FS90 preProcess.py - ./preProcess.py --mode=reverse \$< -o \$@ + ./preProcess.py --timing --r8 -H -S \$< -o \$@ # F -> WHIRL # note that the canonicalized version cuts off at col 72 @@ -3022,12 +3082,12 @@ ./whirl2xaif -s -n --debug 1 -o \$@ \$< # XAIF -> XAIF' -ad_input_code_sf.w2f.pre.xb.xaif : ad_input_code_sf.w2f.pre.xaif xaif.xsd xaif_base.xsd xaif_inlinable_intrinsics.xsd xaif_derivative_propagator.xsd xaif_output.xsd openad_adm - ./openad_adm -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r +ad_input_code_sf.w2f.pre.xb.xaif : ad_input_code_sf.w2f.pre.xaif xaif.xsd xaif_base.xsd xaif_inlinable_intrinsics.xsd xaif_derivative_propagator.xsd xaif_output.xsd oadDriver + ./oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r # XAIF' -> WHIRL' ad_input_code_sf.w2f.pre.xb.x2w.B : ad_input_code_sf.w2f.pre.xb.xaif xaif2whirl - ./xaif2whirl --debug 1 --structured ad_input_code_sf.w2f.pre.B \$< + ./xaif2whirl --debug 1 ad_input_code_sf.w2f.pre.B \$< # WHIRL' -> F' ad_input_code_sf.w2f.pre.xb.x2w.w2f.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.B whirl2f whirl2f_be @@ -3037,22 +3097,15 @@ ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.w2f.f$FS90 ../OAD_support/insertTemplateDir.bash ../OAD_support/insertTemplateDir.bash \$< \$@ +PPEXTRAS=\$(wildcard ../OAD_support/ad_template.*.F) ../OAD_support/ad_inline.F # postprocess F' -ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.pp.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.f$FS90 multi-pp.pl ../OAD_support/ad_inline.f \$(wildcard ../OAD_support/ad_template.*.f) - perl multi-pp.pl -inline=../OAD_support/ad_inline.f \$< - # the postprocessor still gets the name wrong - cat \$<.pp | sed 's/RETURN//' > \$@ - -# extract all transformed modules -all_mods.xb.x2w.w2f.pp.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.pp.f$FS90 - cat \$< | sed -n '/MODULE /,/END MODULE/p' > \$@ - -# remove the transformed globals module from the -# transformed ad_input_code file -# and remove for now the duplicate variables -# and fix 2 data statements -ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90: ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.pp.f$FS90 - cat \$< | sed '/MODULE /,/END MODULE/d' | sed '/^ INTEGER(w2f__i4) DOLOOP_UB/d' > \$@ +postProcess.tag: ad_input_code_sf.w2f.pre.xb.x2w.w2f.td.f$FS90 postProcess.py \$(PPEXTRAS:.F=.f) + # the target is a placeholder to signal execution of the rule + touch \$@ + # this step also creates the file postProcess.make but we cannot + # name it as the target or else make will try to remake it for + # the include directive above for any rule, e.g. make clean + ./postProcess.py --progress --timing --outputFormat=fixed -m r -i ../OAD_support/ad_inline.f --width 4 \$< # setup some links %.xsd: @@ -3068,17 +3121,16 @@ whirl2xaif xaif2whirl: \$(LN) \${OPENADFORTTK}/bin/\$@ . -%.pl: - \$(LN) \${OPENADFORTTK}/bin/\$@ . - -preProcess.py: +preProcess.py postProcess.py: \$(LN) \${OPENADFORTTK_BASE}/tools/SourceProcessing/\$@ . whirl2f whirl2f_be: \$(LN) \${OPEN64ROOT}/whirl2f/\$@ . -openad_adm: - \$(LN) \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/test/t \$@ +oadDriver: + \$(LN) \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver \$@ + +AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.make postProcess.tag postProcess.comp \$(PPEXTRAS:.F=.f) # ============ end OpenAD specific section ==============