--- MITgcm/tools/genmake2 2007/10/08 07:33:28 1.165 +++ 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.165 2007/10/08 07:33:28 mlosch 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 @@ -746,7 +759,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 @@ -805,7 +820,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 @@ -853,7 +870,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 @@ -897,7 +916,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 @@ -1038,6 +1059,8 @@ FFLAGS= FOPTIM= FEXTRAFLAGS= +USE_EXTENDED_SRC= +EXTENDED_SRC_FLAG= CFLAGS= KFLAGS1= KFLAGS2= @@ -1048,6 +1071,9 @@ NOOPTFLAGS= MPI= MPIPATH= +OMP= +OMPFLAG= +USE_R4= TS= PAPIS= PCLS= @@ -1115,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" @@ -1145,12 +1171,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" @@ -1162,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 @@ -1295,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) @@ -1322,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 ;; @@ -1400,8 +1415,14 @@ fi # Find the MITgcm ${THISVER} -if test -f "${ROOTDIR}/doc/tag-index" ; then - THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1` +version_file="${ROOTDIR}/doc/tag-index" +if test -f $version_file ; then + 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})" + rm -f ./BUILD_INFO.h + fi fi if test "x$MAKEFILE" = x ; then @@ -1557,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" @@ -1638,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... " @@ -1760,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 @@ -1828,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 @@ -1878,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 @@ -1922,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 @@ -1967,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 @@ -2006,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 @@ -2047,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\"" @@ -2099,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 @@ -2155,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" @@ -2214,19 +2257,19 @@ # Here, we build the list of files to be "run through" the adjoint # compiler. -if test -f ./ad_files ; then - rm -f ./ad_files +if test -f ./adSrcFiles.tmp ; then + rm -f ./adSrcFiles.tmp fi echo " Creating the list of files for the adjoint compiler." for i in $SOURCEDIRS ; do list_files=`( cd $i && ls -1 *.list 2>/dev/null )` for j in $list_files ; do - cat $i/$j >> ad_files + cat $i/$j >> adSrcFiles.tmp done done if test ! "x"$FS = "x.f" ; then - cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f - mv -f ad_files_f ad_files + cat adSrcFiles.tmp | sed -e "s/\.f/.$FS/g" > adSrcFiles.tmp_f + mv -f adSrcFiles.tmp_f adSrcFiles.tmp fi echo @@ -2284,18 +2327,63 @@ exit 1 fi rm -f .links.tmp/foo + +if test "x$OPENAD" != x ; then + OAD_DONT_COMPILE="/dev/null" + OAD_DONT_TRANSFORM="/dev/null" + OAD_KEEP_ORIGINAL="/dev/null" + OAD_CB2M_FILES="/dev/null" + echo " looking for dontCompile file: " + for i in "." $MODS ; do + if test -r $i"/dontCompile" ; then + OAD_DONT_COMPILE=$i"/dontCompile" + echo " found $OAD_DONT_COMPILE" + break + fi + done + echo " looking for dontTransform file: " + for i in "." $MODS ; do + if test -r $i"/dontTransform" ; then + OAD_DONT_TRANSFORM=$i"/dontTransform" + echo " found $OAD_DONT_TRANSFORM" + break + fi + done + echo " looking for keepOriginal file: " + for i in "." $MODS ; do + if test -r $i"/keepOriginal" ; then + OAD_KEEP_ORIGINAL=$i"/keepOriginal" + echo " found $OAD_KEEP_ORIGINAL" + break + fi + done + echo " looking for cb2mFiles: " + for i in "." $MODS ; do + if test -r $i"/cb2mFiles" ; then + OAD_CB2M_FILES=$i"/cb2mFiles" + echo " found $OAD_CB2M_FILES" + break + fi + done + echo " OpenAD exceptions: " +fi + echo "# This section creates symbolic links" > srclinks.tmp echo "" >> srclinks.tmp -printf 'SRCFILES = ' > srclist.inc -printf 'CSRCFILES = ' > csrclist.inc -printf 'F90SRCFILES = ' > f90srclist.inc -printf 'HEADERFILES = ' > hlist.inc -printf 'AD_FLOW_FILES = ' > ad_flow_files.inc +printf 'F77_SRC_FILES = ' > F77srclist.tmp +printf 'NON_AD_F77_SRC_FILES = ' > nonADF77srclist.tmp +printf 'C_SRC_FILES = ' > csrclist.tmp +printf 'F90_SRC_FILES = ' > F90srclist.tmp +printf 'H_SRC_FILES = ' > hsrclist.tmp +printf 'AD_FLOW_FILES = ' > ad_flow_files.tmp alldirs="$SOURCEDIRS $INCLUDEDIRS ." for d in $alldirs ; do deplist= sfiles=`( cd $d; echo *.[h,c,F] *.flow )` sfiles=`( echo $sfiles; cd $d; echo *.F90 )` + if test "x$OPENAD" != x ; then + sfiles=`( echo $sfiles | grep -v _cb2m\. )` + fi for sf in $sfiles ; do if test ! -r ".links.tmp/$sf" ; then if test -f "$d/$sf" ; then @@ -2330,47 +2418,86 @@ if test "x$ignore_f" = xf ; then extn=`echo $sf | $AWK -F. '{print $NF}'` case $extn in - F) - echo " \\" >> srclist.inc - printf " $sf" >> srclist.inc - ;; - F90) - echo " \\" >> f90srclist.inc - printf " $sf" >> f90srclist.inc - ;; - c) - echo " \\" >> csrclist.inc - printf " $sf" >> csrclist.inc - ;; - h) - echo " \\" >> hlist.inc - printf " $sf" >> hlist.inc - ;; - flow) - echo " \\" >> ad_flow_files.inc - printf " $sf" >> ad_flow_files.inc - ;; - esac - fi + F) + echo " \\" >> F77srclist.tmp + printf " $sf" >> F77srclist.tmp + if test "x$OPENAD" != x ; then + basename=${sf%%.F} + isAD=`egrep ^$basename.f'[ ]*' adSrcFiles.tmp` + if test -z "$isAD" ; then + toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE}` + if test -z "$toBeIgnored" ; then + echo " \\" >> nonADF77srclist.tmp + printf " $sf" >> nonADF77srclist.tmp + else + echo " not to be compiled : $sf" + fi + else # file is initially listed as an AD file we want to exclude it + # or we want to retain the untransformed version + notToBeTransformed=`egrep ^$basename'[ ]*' ${OAD_DONT_TRANSFORM}` + untransformedVersionToBeKept=`egrep ^$basename'[ ]*' ${OAD_KEEP_ORIGINAL}` + if test -n "$notToBeTransformed"; then + echo " not to be transformed: $sf" + fi + if test -n "$untransformedVersionToBeKept" ; then + echo " original to be kept : $sf" + fi + if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then + echo " \\" >> nonADF77srclist.tmp + printf " $sf" >> nonADF77srclist.tmp + fi + fi + fi + ;; + F90) + echo " \\" >> F90srclist.tmp + printf " $sf" >> F90srclist.tmp + ;; + c) + echo " \\" >> csrclist.tmp + printf " $sf" >> csrclist.tmp + ;; + h) + echo " \\" >> hsrclist.tmp + printf " $sf" >> hsrclist.tmp + ;; + flow) + echo " \\" >> ad_flow_files.tmp + printf " $sf" >> ad_flow_files.tmp + ;; + esac + fi fi fi done if test "x$deplist" != x ; then - echo "" >> srclinks.tmp + if test "$d" != "." ; then + echo "" >> srclinks.tmp echo "# These files are linked from $d" >> srclinks.tmp echo "$deplist :" >> srclinks.tmp - printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp +# We need to make sure that the link isn't already there. +# This may happen when make thinks that a header file has to be "remade" +# because a module it depends on has changed. In this case we do nothing. + printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> srclinks.tmp + fi fi done rm -rf .links.tmp -echo "" >> srclist.inc -echo "" >> csrclist.inc -echo "" >> f90srclist.inc -echo "" >> hlist.inc -echo "" >> ad_flow_files.inc +echo "" >> F77srclist.tmp +echo "" >> nonADF77srclist.tmp +echo "" >> csrclist.tmp +echo "" >> F90srclist.tmp +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 @@ -2378,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 @@ -2389,7 +2516,7 @@ cat >>$MAKEFILE < \$@ @@ -2568,10 +2709,10 @@ decode_files.o : EMBEDDED_FILES.h -## \$(F77FILES) -all_fF.tar.gz : \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(F77FILES) Makefile +## \$(F77_PP_SRC_FILES) +all_fF.tar.gz : \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile @echo Creating \$@ ... - -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(F77FILES) Makefile + -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile -rm -f all_fF.tar.gz -gzip all_fF.tar @@ -2593,10 +2734,19 @@ \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ .$FS.o: \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$< -.F90.o: +.F90.$FS90: + \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ +.FF90.f$FS90: + \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ +.$FS90.o: \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$< +.f$FS90.o: + cp \$< \$(basename \$<).f90 + \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$(basename \$<).f90 .c.o: \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$< +.flow.flowdir: + \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@ # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain .F.p: @@ -2604,8 +2754,15 @@ .p.$FS: \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$< +EOF + #========================================= #=== Automatic Differentiation Rules === +#=== for TAMC/TAF ====================== + +if test "x$OPENAD" = x ; then + +cat >>$MAKEFILE <> $MAKEFILE printf "AD_FILES = " >> $MAKEFILE -AD_FILES=`cat ad_files` +AD_FILES=`cat adSrcFiles.tmp` for i in $AD_FILES ; do echo " \\" >> $MAKEFILE printf " $i" >> $MAKEFILE done echo >> $MAKEFILE -rm -f ad_files +rm -f adSrcFiles.tmp cat >>$MAKEFILE < ad_config.template cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h -rm -f ad_config.template - @make \$(F77FILES) - @make \$(AD_FLOW_FILES) - cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS + @make \$(F77_PP_SRC_FILES) + @make \$(FLOFILES) + 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 + ls -l ad_input_code_ad.$FS cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS adtafonly: \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS + ls -l ad_input_code_ad.$FS cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS \${EXE_AD}: ad_taf_output.o \$(OBJFILES) @@ -2681,20 +2840,22 @@ ftltaf: ftl_taf_output.$FS ftltamc: ftl_tamc_output.$FS -ftl_input_code.$FS: \$(AD_FILES) \$(HEADERFILES) +ftl_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES) @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ftl_config.template cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h -rm -f ftl_config.template - @make \$(F77FILES) + @make \$(F77_PP_SRC_FILES) @make \$(AD_FLOW_FILES) cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS ftl_taf_output.$FS: ftl_input_code.$FS \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS + ls -l ftl_input_code_ftl.$FS cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS ftltafonly: \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS + ls -l ftl_input_code_ftl.$FS cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS ftl_taf: ftl_taf_output.o \$(OBJFILES) @@ -2732,10 +2893,253 @@ cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h -rm -f ftl_config.template -#========================================= +EOF + +fi + +#=== for OpenAD ======================== + +if test "x$OPENAD" != x ; then + +# ============ begin OpenAD specific section ============== + +cat >>$MAKEFILE <> $MAKEFILE +printf "CB2M_F90_SRC_NAMES = " >> $MAKEFILE +for i in `cat ${OAD_CB2M_FILES}` ; do + echo " \\" >> $MAKEFILE + printf " $i" >> $MAKEFILE +done +echo >> $MAKEFILE + +echo " Add the source list for AD code generation" +echo >> $MAKEFILE +printf "AD_FILES = " >> $MAKEFILE +for i in `cat ${OAD_CB2M_FILES}` ; do + echo " \\" >> $MAKEFILE + printf " ${i}_mod.f$FS90" >> $MAKEFILE +done +AD_FILES=`cat adSrcFiles.tmp` +for i in $AD_FILES ; do + basename=${i%%.f} + toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}` + if test -z "$toBeIgnored" ; then + echo " \\" >> $MAKEFILE + printf " $i" >> $MAKEFILE + fi +done +echo >> $MAKEFILE +rm -f adSrcFiles.tmp + +cat >>$MAKEFILE <> \$(MAKEFILE) + -rm -f makedepend.out + +OPENAD_SUPPORT_F90_SRC_FILES = \ +w2f__types.F90 \ +OAD_active.F90 \ +OAD_cp.F90 \ +OAD_rev.F90 \ +OAD_tape.F90 + +OPENAD_SUPPORT_C_SRC_FILES = \ +iaddr.c \ +timeRatio.c + +f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90) + cat \$^ > \$@ + +f95_test.f90: all_mods.xb.x2w.w2f.pp.f$FS90 \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90) ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90 + cat \$^ > \$@ + +f95_test.out: f95_test_mods.f90 f95_test.f90 + 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 + +# 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)) 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 +.PHONY: openad + +# create the module files +%_mod.FF90 : %.h ../OAD_support/cb2mGetModules.csh ../OAD_support/cb2mGetModules.awk + ../OAD_support/cb2mGetModules.csh $< ../OAD_support/cb2mGetModules.awk + +# create the header files +%_mod.h : %.h ../OAD_support/cb2mGetHeaders.csh ../OAD_support/cb2mGetHeaders.awk + ../OAD_support/cb2mGetHeaders.csh $< ../OAD_support/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES) + +# change everybody else to use the new module files: +%_cb2m.FF90 : %.F ../OAD_support/cb2mUseModules.bash + ../OAD_support/cb2mUseModules.bash $< ${MPI} + +# makefile debug rule +small_f: \$(CB2M_F90_PP_SRC_FILES) +.PHONY: small_f + +ad_output.txt: \$(EXE_AD) + @printf 'linking data files ... ' + \$(LN) -f ../input_ad/data* ../input_ad/eedata . + \$(LN) -f ../../global_ocean.90x40x15/input/*.bin . + @printf 'running ... ' + @./\$(EXE_AD) > \$@ + +CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90) +ad_input_code.f$FS90: \$(CB2M_AD_FILES) + cat \$^ > \$@ + +# strip all comments and blanks to reduce +# the file size in order to reduce perl's memory requirements +ad_input_code_sf.f$FS90 : ad_input_code.f$FS90 + cat \$^ | sed -f ../OAD_support/strip.sed | sed -f ../OAD_support/stop2print.sed > \$@ + +# mfef90 preprocessing +# expand statement functions +# expose mfef90 specific substring handling +# add the w2f__types module +ad_input_code_sf.w2f.f$FS90: ad_input_code_sf.f$FS90 mfef90 whirl2f whirl2f_be w2f__types.f90 + ./mfef90 -r8 -z -F -N132 \$< + mv \$<.B \$(basename \$<).B + ./whirl2f -openad \$(basename \$<).B + cat w2f__types.f90 \$(basename \$<).w2f.f > \$@ + +# canonicalizer +ad_input_code_sf.w2f.pre.f$FS90: ad_input_code_sf.w2f.f$FS90 preProcess.py + ./preProcess.py --timing --r8 -H -S \$< -o \$@ + +# F -> WHIRL +# note that the canonicalized version cuts off at col 72 +# doing this also for string constants which is ok as long +# as we are in fixed mode and cut of exactly there. +# Otherwise mfef90 patches in spaces to fill up to 72 (or 132) +# characters respectively. +ad_input_code_sf.w2f.pre.B: ad_input_code_sf.w2f.pre.f$FS90 mfef90 + ./mfef90 -r8 -z -F \$< + mv \$<.B \$@ + +# WHIRL -> XAIF +ad_input_code_sf.w2f.pre.xaif : ad_input_code_sf.w2f.pre.B whirl2xaif + ./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 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 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 + ./whirl2f -FLIST:ftn_file=\$@ -openad \$< + +# insert template directives +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' +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: + \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ . + +mfef90: + \$(LN) \${OPEN64ROOT}/crayf90/sgi/mfef90 . + +# link the support files: +\$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES): + \$(LN) ../OAD_support/\$@ . + +whirl2xaif xaif2whirl: + \$(LN) \${OPENADFORTTK}/bin/\$@ . + +preProcess.py postProcess.py: + \$(LN) \${OPENADFORTTK_BASE}/tools/SourceProcessing/\$@ . + +whirl2f whirl2f_be: + \$(LN) \${OPEN64ROOT}/whirl2f/\$@ . + +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 ============== + +EOF + +fi + +#========================================= + if test "x$EXEHOOK" != x ; then printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE fi