Skip to content

Commit

Permalink
make it work for bottom_ctrl_5x5 and almost for the rest
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
mjlosch committed Sep 29, 2024
1 parent f346dbb commit bc03d79
Showing 1 changed file with 67 additions and 32 deletions.
99 changes: 67 additions & 32 deletions tools/genmake2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ==="
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 <<EOF
# We need the extra target for ad_taf_outpF90.$FS90, because the file is
# generated together with ad_taf_output.$FS.
ad_taf_outpF90.$FS90: ad_taf_output.$FS
Expand All @@ -3595,22 +3623,29 @@ adobj: ad_taf_outpF90.o ad_taf_output.o \$(NON_AD_F90_SRC_FILES:.F90=.o) \$(NON_
EOF
fi
fi
else
cat >>$MAKEFILE <<EOF
# ... send multiple files to TAF ...
ad_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_F90FILES) \$(AD_FILES)
ad_taf_output.$FS: \$(AD_FLOW_FILES) \$(AD_F90FILES) \$(AD_FILES)
@$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > 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 <<EOF
cat \$(AD_F90FILES:.$FS90=_ad.$FS90) > ad_taf_outpF90.$FS90
EOF
fi
cat >>$MAKEFILE <<EOF
cat \$(AD_FILES:.$FS=_ad.$FS) > 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)
Expand Down

0 comments on commit bc03d79

Please sign in to comment.