From bc03d7925080b8b8c8bab386c98f8f73b5c01afb Mon Sep 17 00:00:00 2001 From: mjlosch Date: Sun, 29 Sep 2024 16:59:47 +0200 Subject: [PATCH] make it work for bottom_ctrl_5x5 and almost for the rest - add F90 files that do neiter define nor use modules to the lists of AD_F90FILES and F90_SRC_FILES - exclude generating ad_taf_outpF90.$FS90 if there are no AD_F90FILES - delete unnecessary white spaces - this works for bottom_ctrl_5x5, because it uses the extended file format for fixed format already. All other AD-verification experiments still fail, because with hard coded '-fixed -e' in the TAF command, TAF produces lines that are 132 characters long and this requires an extra flag for the Fortran compiler --- tools/genmake2 | 99 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 32 deletions(-) diff --git a/tools/genmake2 b/tools/genmake2 index 66fc114c36..ab8f43a2af 100755 --- a/tools/genmake2 +++ b/tools/genmake2 @@ -2778,12 +2778,13 @@ test -f $TMP.adF90Graph && rm -f $TMP.adF90Graph touch $TMP.adSrcFiles touch $TMP.adF90Files touch $TMP.adF90Graph +touch $TMP.adF90noGraph for i in $SOURCEDIRS ; do list_files=`( cd $i && ls -1 *_ad_diff.list 2>/dev/null )` for j in $list_files ; do - grep '\.f\>' $i/$j >> $TMP.adSrcFiles + grep '\.f\>' $i/$j >> $TMP.adSrcFiles # Retain file paths for topo sorting later - grep '\.f90\>' $i/$j | sed 's/f90$/F90/'g | while IFS= read -r line; do + grep '\.f90\>' $i/$j | sed 's/f90$/F90/'g | while IFS= read -r line; do echo "$i/$line" >> $TMP.adF90Files done done @@ -2792,21 +2793,34 @@ done # Sort the f90 files in topological order while IFS= read -r f90file; do # List modules used in f90file, ignoring those commented out - mod_used=$(grep -i "^[^!]*\buse\b" $f90file | awk '{print $2}' | \ - tr -d ',') - - for mod in $mod_used; do - # Find the file that defines this module - mod_file=$(grep -li "^module $mod\b" $(grep -v $f90file "$TMP.adF90Files")) - if [ -n "$mod_file" ]; then - echo $mod_file $f90file >> $TMP.adF90Graph - fi - done + mod_used=$(grep -i "^[^!]*\buse\b" $f90file | awk '{print $2}' | tr -d ',') + + if [ -n "$mod_used" ]; then + for mod in $mod_used; do + # Find the file that defines this module + mod_file=$(grep -li "^module $mod\b" \ + $(grep -v $f90file "$TMP.adF90Files")) + if [ -n "$mod_file" ]; then + echo $mod_file $f90file >> $TMP.adF90Graph + fi + done + else + echo $f90file >> $TMP.adF90noGraph + fi done < $TMP.adF90Files # Replace alphabetical with topological file order -tsort $TMP.adF90Graph | sed 's|.*/||' | sed 's/\.F90/\.f90/g' > $TMP.adF90Files +tsort $TMP.adF90Graph | sed -e 's|.*/||' -e 's/\.F90/\.f90/g' > $TMP.adF90Files +# append files without use-statements if they are not already included +while IFS= read -r f90file; do + f=$(echo $f90file | sed -e 's|.*/||' -e 's/\.F90/\.f90/g' ) + inList=$(grep -i $f $TMP.adF90Files) + if test -z "$inList" ; then + echo $f >> $TMP.adF90Files + fi +done < $TMP.adF90noGraph # Clean up topological sorting files -rm -rf $TMP.adF90Graph +rm -rf $TMP.adF90Graph $TMP.adF90noGraph + echo echo "=== Creating the Makefile ===" @@ -3062,12 +3076,12 @@ for d in $alldirs ; do F90) echo " \\" >> $TMP.F90srclist printf " $sf" >> $TMP.F90srclist - # Store file path and name for topo ordering later - echo "$d/$sf" >> $TMP.F90Files + # Store file path and name for topo ordering later + echo "$d/$sf" >> $TMP.F90Files if ( test "x$OPENAD" = x && test "x$TAPENADE" = x ) ; then basename=${sf%%.F90} - isAD=`egrep ^$basename.F90'[ ]*' $TMP.adF90Files` + isAD=`egrep ^$basename.f90'[ ]*' $TMP.adF90Files` if test -z "$isAD" ; then echo " \\" >> $TMP.nonADF90srclist printf " $sf" >> $TMP.nonADF90srclist @@ -3104,23 +3118,34 @@ for d in $alldirs ; do fi done -# # Sort the F90 files in topological order while IFS= read -r f90file; do + mod_used=$(grep -i "^[^!]*\buse\b" $f90file | awk '{print $2}' | tr -d ',') # Find modules used, ignoring those commented out - mod_used=$(grep -i "^[^!]*\buse\b" $f90file | awk '{print $2}' | \ - tr -d ',') - - for mod in $mod_used; do - # Find the file that defines this module - mod_file=$(grep -li "^module $mod\b" $(grep -v $f90file "$TMP.F90Files")) - if [ -n "$mod_file" ]; then - echo $mod_file $f90file >> "$TMP.F90Graph" - fi - done + mod_used=$(grep -i "^[^!]*\buse\b" $f90file | awk '{print $2}' | tr -d ',') + + if [ -n "$mod_used" ]; then + for mod in $mod_used; do + # Find the file that defines this module + mod_file=$(grep -li "^module $mod\b" \ + $(grep -v $f90file "$TMP.F90Files")) + if [ -n "$mod_file" ]; then + echo $mod_file $f90file >> $TMP.F90Graph + fi + done + else + echo $f90file >> $TMP.F90noGraph + fi done < "$TMP.F90Files" # Replace alphabetical with topological file order -tsort "$TMP.F90Graph" > "$TMP.F90Files" +tsort $TMP.F90Graph > $TMP.F90Files +# append files without use-statements if they are not already included +while IFS= read -r f90file; do + inList=$(grep -i $f90file $TMP.F90Files) + if test -z "$inList" ; then + echo $f90file >> $TMP.F90Files + fi +done < $TMP.F90noGraph # # Format to F90srclist specs @@ -3132,7 +3157,7 @@ cat $TMP.F90srclist.tmp > $TMP.F90srclist # # Clean up topological sorting files rm -rf $TMP.F90Files.tmp $TMP.F90Files $TMP.F90srclist.tmp -rm -rf $TMP.F90Graph +rm -rf $TMP.F90Graph $TMP.noF90Graph rm -rf $TMP.links echo "" >> $TMP.F77srclist @@ -3583,6 +3608,9 @@ ad_taf_output.$FS: ad_inpF90_code.$FS90 ad_input_code.$FS ls -l ad_inpF90_code_ad.$FS90 ad_input_code_ad.$FS cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS +EOF +if test -n "$AD_F90FILES" ; then +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) -f \$(MAKEFILE) \$(FLOWFILES) - @\$(MAKE) -f \$(MAKEFILE) \$(F90_PP_SRC_FILES) \$(F77_PP_SRC_FILES) + @\$(MAKE) -f \$(MAKEFILE) \$(F90_PP_SRC_FILES) \$(F77_PP_SRC_FILES) @-rm -f \$(AD_F90FILES:.$FS90=_ad.$FS90) \$(AD_F90FILES:.$FS90=_ad.o); echo '' @-rm -f \$(AD_FILES:.$FS=_ad.$FS) \$(AD_FILES:.$FS=_ad.o); echo '' \$(MAKE) -f \$(MAKEFILE) remove_comments \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) -free -N 150 \$(AD_F90FILES) -fixed -e \$(FLOWFILES) \$(AD_FILES) \$(MAKE) -f \$(MAKEFILE) adj_sed +EOF +if test -n "$AD_F90FILES" ; then +cat >>$MAKEFILE < ad_taf_outpF90.$FS90 +EOF +fi +cat >>$MAKEFILE < ad_taf_output.$FS \$(EXE_ADJ): \$(SPECIAL_FILES) \$(H_SRC_FILES) ad_taf_output.$FS \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(NON_AD_F77_SRC_FILES:.F=.o) \$(C_SRC_FILES:.c=.o) \$(EMBEDDED_FILES)