Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
build a mpi.mod file
authorAugustin Degomme <augustin.degomme@unibas.ch>
Fri, 23 Mar 2018 08:55:51 +0000 (09:55 +0100)
committerAugustin Degomme <augustin.degomme@unibas.ch>
Fri, 23 Mar 2018 08:56:47 +0000 (09:56 +0100)
This allows fortran codes to use 'use mpi' instead of 'include mpif.h'
For now this is built in the global CMakelists.txt before finding a beter home

CMakeLists.txt
include/smpi/mpif.h.in
src/smpi/smpif90.in
src/smpi/smpiff.in
teshsuite/smpi/mpich3-test/f90/datatype/indtype.f90
tools/cmake/Distrib.cmake

index f12df62..397c6bd 100644 (file)
@@ -79,9 +79,9 @@ if ((NOT DEFINED enable_smpi) OR enable_smpi)
   endif()
   
   if(CMAKE_Fortran_COMPILER)
+
     # Fortran compiler detected: save it, then replace by smpiff
     set(SMPI_Fortran_COMPILER "${CMAKE_Fortran_COMPILER}" CACHE FILEPATH "The real Fortran compiler")
-    set(CMAKE_Fortran_COMPILER smpiff)
 
        # Set flags/libs to be used in smpiff
     if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
@@ -703,6 +703,16 @@ set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:\${LD_LIBRARY_PATH:+:$LD_LIBRARY_P
 set(SMPIMAIN smpimain)
 
 configure_file(${CMAKE_HOME_DIRECTORY}/include/smpi/mpif.h.in ${CMAKE_BINARY_DIR}/include/smpi/mpif.h @ONLY)
+#configure mpif.f90 to build mpi.mod
+if(enable_fortran)
+  set(MODULE_MPIF_IN "module mpi")
+  set(MODULE_MPIF_OUT "end module mpi")
+  configure_file(${CMAKE_HOME_DIRECTORY}/include/smpi/mpif.h.in ${CMAKE_BINARY_DIR}/src/smpi/mpif.f90.generated @ONLY)
+  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/src/smpi/mpif.f90.generated ${CMAKE_BINARY_DIR}/src/smpi/mpif.f90)
+  set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include/smpi)
+  add_library(mpi SHARED ${CMAKE_BINARY_DIR}/src/smpi/mpif.f90)
+endif()
+
 foreach(script cc cxx ff f90 run)
   configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpi${script}.in ${CMAKE_BINARY_DIR}/bin/smpi${script} @ONLY)
 endforeach()
index 8af2cdf..580f2b3 100644 (file)
@@ -6,7 +6,7 @@
 ! under the terms of the license (GNU LGPL) which comes with this package.
 
 ! SMPI's Fortran 77 include file
-
+@MODULE_MPIF_IN@
       integer MPI_THREAD_SINGLE, MPI_THREAD_FUNNELED
       integer MPI_THREAD_SERIALIZED, MPI_THREAD_MULTIPLE
       parameter(MPI_THREAD_SINGLE=0)
       double precision smpi_get_host_current_power_peak
       integer smpi_get_host_nb_pstates
       double precision smpi_get_host_consumed_energy
+@MODULE_MPIF_OUT@
index 1a327da..b0c2b29 100644 (file)
@@ -29,7 +29,7 @@ trap 'cleanup' EXIT
 filter_and_compile() {
     list_add TMPFILES "${TMPFILE}"
     #replace "program main_name by subroutine user\_main (and the end clause as well)"
-    sed 's/[[:space:]]*[pP][rR][oO][gG][rR][aA][mM][[:space:]]*\([a-zA-Z0-9\-\_]*\)/ subroutine user\_main /g;s/[[:space:]]*[uU][sS][eE][[:space:]]*[mM][pP][iI]/\include \"mpif\.h\" /g' "${ARG}" > "${TMPFILE}"
+    sed 's/[[:space:]]*[pP][rR][oO][gG][rR][aA][mM][[:space:]]*\([a-zA-Z0-9\-\_]*\)/ subroutine user\_main /g' "${ARG}" > "${TMPFILE}"
     SRCFILE="${TMPFILE}"
     list_add CMDLINE "${SRCFILE}"
 }
index 5741ba8..5361c3b 100644 (file)
@@ -33,7 +33,7 @@ filter_and_compile_f77() {
       echo "#include \"@includedir@/smpi/smpi_extended_traces_fortran.h\"" > ${TMPFILE}
       echo "#line 1 \"${ARG}\"" >> ${TMPFILE}
     fi
-    sed 's/[[:space:]]\{6\}[[:space:]]*\([eE][nN][dD] \)\{0,1\}[pP][rR][oO][gG][rR][aA][mM][[:space:]]*\([a-zA-Z0-9\-\_]*\)/      \1subroutine user_main /g;s/[[:space:]]*[uU][sS][eE][[:space:]]*[mM][pP][iI]/\include \"mpif\.h\" /g' "${ARG}" >> "${TMPFILE}"
+    sed 's/[[:space:]]\{6\}[[:space:]]*\([eE][nN][dD] \)\{0,1\}[pP][rR][oO][gG][rR][aA][mM][[:space:]]*\([a-zA-Z0-9\-\_]*\)/      \1subroutine user_main /g' "${ARG}" >> "${TMPFILE}"
     SRCFILE="${TMPFILE}"
     list_add CMDLINE "${SRCFILE}"
 }
index 123a623..3d05a6b 100644 (file)
@@ -6,8 +6,8 @@
 ! This test contributed by Kim McMahon, Cray
 !
       program main
-      implicit none
       use mpi
+      implicit none
 
       integer ierr, i, j, type, count,errs
       parameter (count = 4)
index 01e0885..25014f1 100644 (file)
@@ -20,6 +20,9 @@ if(enable_smpi)
       ${CMAKE_BINARY_DIR}/bin/smpif90
       ${CMAKE_BINARY_DIR}/bin/smpiff
       DESTINATION bin/)
+    install(PROGRAMS
+      ${CMAKE_BINARY_DIR}/src/mpi.mod
+      DESTINATION include/smpi/)
   endif()
 endif()
 
@@ -345,6 +348,7 @@ add_custom_target(maintainer-clean
   COMMAND ${CMAKE_COMMAND} -E remove -f src/simgrid_units_main.c
   COMMAND ${CMAKE_COMMAND} -E remove -f src/xbt_str_unit.c
   COMMAND ${CMAKE_COMMAND} -E remove -f src/xbt_synchro_unit.c
+  COMMAND ${CMAKE_COMMAND} -E remove -f src/mpif.f90
   WORKING_DIRECTORY "${CMAKE_HOME_DIRECTORY}")
 
 include(CPack)