Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fortran: don't generate temporary files when not necessary.
authorAugustin Degomme <adegomme@users.noreply.github.com>
Mon, 25 Oct 2021 09:17:53 +0000 (11:17 +0200)
committerAugustin Degomme <adegomme@users.noreply.github.com>
Mon, 25 Oct 2021 09:31:30 +0000 (11:31 +0200)
It's only necessary for files with "program xxx" clause, so one for each executable (it can be necessary for all files, but only when trace_call_location is set).
This should help with debugging, as gdb cannot find temporary files which are deleted

src/smpi/smpif90.in
src/smpi/smpiff.in

index ca8eda5..33508f7 100644 (file)
@@ -38,9 +38,9 @@ cleanup () {
 trap 'cleanup' EXIT
 
 filter_and_compile() {
-    list_add TMPFILES "${TMPFILE}"
     #replace "program main_name by subroutine user_main (and the end clause as well)"
-    if [ "x${SMPI_PRETEND_CC}" = "x" ]; then
+    if [ "x${SMPI_PRETEND_CC}" = "x" ] && [ "x${TMPFILE}" != "x" ]; then
+      list_add TMPFILES "${TMPFILE}"
       sed 's/^\([[:space:]]*\)\([eE][nN][dD] \)\{0,1\}[pP][rR][oO][gG][rR][aA][mM][^a-zA-Z0-9]*\([a-zA-Z0-9_]*\)/\1\2subroutine user_main /g' "${ARG}" >> "${TMPFILE}"
       SRCFILE="${TMPFILE}"
     else
@@ -64,13 +64,17 @@ while [ $# -gt 0 ]; do
             ;;
         *.f90)
             FILENAME=$(basename "${ARG}")
-            TMPFILE=$(mymktemp "${ARG}" ".f90")
+            if main=$(grep -q -i "program" "${ARG}"); then
+              TMPFILE=$(mymktemp "${ARG}" ".f90")
+            fi
             ORIGFILE="${FILENAME%.f90}"
             filter_and_compile
             ;;
         *.F90)
             FILENAME=$(basename "${ARG}")
-            TMPFILE=$(mymktemp "${ARG}" ".F90")
+            if main=$(grep -q -i "program" "${ARG}"); then
+              TMPFILE=$(mymktemp "${ARG}" ".F90")
+            fi
             ORIGFILE="${FILENAME%.F90}"
             filter_and_compile
             ;;
index 9b9472e..373c7de 100644 (file)
@@ -38,8 +38,8 @@ cleanup () {
 trap 'cleanup' EXIT
 
 filter_and_compile_f77() {
-    list_add TMPFILES "${TMPFILE}"
-    if [ "x${SMPI_PRETEND_CC}" = "x" ]; then
+    if [ "x${SMPI_PRETEND_CC}" = "x" ] && [ "x${TMPFILE}" != "x" ]; then
+      list_add TMPFILES "${TMPFILE}"
       #replace "program main_name by subroutine user_main (and the end clause as well)"
       if [ "$TRACE_CALL_LOCATION" -gt 0 ]; then
         echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > "${TMPFILE}"
@@ -53,14 +53,18 @@ filter_and_compile_f77() {
     list_add CMDLINE "${SRCFILE}"
 }
 filter_and_compile_f90() {
-    list_add TMPFILES "${TMPFILE}"
-    #replace "program main_name by subroutine user_main (and the end clause as well)"
-    if [ "$TRACE_CALL_LOCATION" -gt 0 ]; then
-      echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > "${TMPFILE}"
-      echo "#line 1 \"${ARG}\"" >> "${TMPFILE}"
+    if [ "x${SMPI_PRETEND_CC}" = "x" ] && [ "x${TMPFILE}" != "x" ]; then
+      list_add TMPFILES "${TMPFILE}"
+      #replace "program main_name by subroutine user_main (and the end clause as well)"
+      if [ "$TRACE_CALL_LOCATION" -gt 0 ]; then
+        echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > "${TMPFILE}"
+        echo "#line 1 \"${ARG}\"" >> "${TMPFILE}"
+      fi
+      sed 's/^\([[:space:]]*\)\([eE][nN][dD] \)\{0,1\}[pP][rR][oO][gG][rR][aA][mM][^a-zA-Z0-9]*\([a-zA-Z0-9_]*\)/\1\2subroutine user_main /g' "${ARG}" >> "${TMPFILE}"
+      SRCFILE="${TMPFILE}"
+    else
+      SRCFILE="${ARG}"
     fi
-    sed 's/^\([[:space:]]*\)\([eE][nN][dD] \)\{0,1\}[pP][rR][oO][gG][rR][aA][mM][^a-zA-Z0-9]*\([a-zA-Z0-9_]*\)/\1\2subroutine user_main /g' "${ARG}" >> "${TMPFILE}"
-    SRCFILE="${TMPFILE}"
     list_add CMDLINE "${SRCFILE}"
 }
 TRACE_CALL_LOCATION=0
@@ -79,25 +83,33 @@ while [ $# -gt 0 ]; do
             ;;
         *.f)
             FILENAME=$(basename "${ARG}")
-            TMPFILE=$(mymktemp "${ARG}" ".f")
+            if [ "$TRACE_CALL_LOCATION" -gt 0 ] || main=$(grep -q -i "program" "${ARG}"); then
+              TMPFILE=$(mymktemp "${ARG}" ".f")
+            fi
             ORIGFILE="${FILENAME%.f}"
             filter_and_compile_f77
             ;;
         *.F)
             FILENAME=$(basename "${ARG}")
-            TMPFILE=$(mymktemp "${ARG}" ".F")
+            if [ "$TRACE_CALL_LOCATION" -gt 0 ] || main=$(grep -q -i "program" "${ARG}"); then
+              TMPFILE=$(mymktemp "${ARG}" ".F")
+            fi
             ORIGFILE="${FILENAME%.F}"
             filter_and_compile_f77
             ;;
         *.f90)
             FILENAME=$(basename "${ARG}")
-            TMPFILE=$(mymktemp "${ARG}" ".f90")
+            if [ "$TRACE_CALL_LOCATION" -gt 0 ] || main=$(grep -q -i "program" "${ARG}"); then
+              TMPFILE=$(mymktemp "${ARG}" ".f90")
+            fi
             ORIGFILE="${FILENAME%.f90}"
             filter_and_compile_f90
             ;;
         *.F90)
             FILENAME=$(basename "${ARG}")
-            TMPFILE=$(mymktemp "${ARG}" ".F90")
+            if [ "$TRACE_CALL_LOCATION" -gt 0 ] || main=$(grep -q -i "program" "${ARG}"); then
+              TMPFILE=$(mymktemp "${ARG}" ".F90")
+            fi
             ORIGFILE="${FILENAME%.F90}"
             filter_and_compile_f90
             ;;