From 8cdfd812c8d23223eb6247e084a4fe948697b16d Mon Sep 17 00:00:00 2001 From: Augustin Degomme Date: Fri, 23 Mar 2018 09:55:51 +0100 Subject: [PATCH] build a mpi.mod file 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 | 12 +++++++++++- include/smpi/mpif.h.in | 3 ++- src/smpi/smpif90.in | 2 +- src/smpi/smpiff.in | 2 +- teshsuite/smpi/mpich3-test/f90/datatype/indtype.f90 | 2 +- tools/cmake/Distrib.cmake | 4 ++++ 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f12df62b42..397c6bd7fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/include/smpi/mpif.h.in b/include/smpi/mpif.h.in index 8af2cdf881..580f2b3a6e 100644 --- a/include/smpi/mpif.h.in +++ b/include/smpi/mpif.h.in @@ -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) @@ -289,3 +289,4 @@ double precision smpi_get_host_current_power_peak integer smpi_get_host_nb_pstates double precision smpi_get_host_consumed_energy +@MODULE_MPIF_OUT@ diff --git a/src/smpi/smpif90.in b/src/smpi/smpif90.in index 1a327da6bf..b0c2b29d84 100644 --- a/src/smpi/smpif90.in +++ b/src/smpi/smpif90.in @@ -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}" } diff --git a/src/smpi/smpiff.in b/src/smpi/smpiff.in index 5741ba8941..5361c3bb95 100644 --- a/src/smpi/smpiff.in +++ b/src/smpi/smpiff.in @@ -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}" } diff --git a/teshsuite/smpi/mpich3-test/f90/datatype/indtype.f90 b/teshsuite/smpi/mpich3-test/f90/datatype/indtype.f90 index 123a6230e8..3d05a6b63a 100644 --- a/teshsuite/smpi/mpich3-test/f90/datatype/indtype.f90 +++ b/teshsuite/smpi/mpich3-test/f90/datatype/indtype.f90 @@ -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) diff --git a/tools/cmake/Distrib.cmake b/tools/cmake/Distrib.cmake index 01e0885a77..25014f1318 100644 --- a/tools/cmake/Distrib.cmake +++ b/tools/cmake/Distrib.cmake @@ -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) -- 2.20.1