Skip to content

Commit f9f750f

Browse files
committed
Enable workarounds when mpi.mod is incompatible
Fall back to using `#include 'mpif.h'` Create interfaces when needed # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch #246-gfortran-mpich-mismatch-detection # Changes to be committed: # modified: ../CMakeLists.txt # modified: ../src/extensions/opencoarrays.F90 # modified: ../src/mpi/CMakeLists.txt # modified: ../src/tests/integration/dist_transpose/coarray_distributed_transpose.F90 # modified: ../src/tests/integration/pde_solvers/navier-stokes/coarray-shear_coll.F90 # modified: ../src/tests/performance/BurgersMPI/shared.F90 # modified: ../src/tests/performance/mpi_dist_transpose/mpi_distributed_transpose.F90 # modified: ../src/tests/unit/init_register/CMakeLists.txt # renamed: ../src/tests/unit/init_register/initialize_mpi.f90 -> ../src/tests/unit/init_register/initialize_mpi.F90 # # Untracked files: # ../.travis-scripts/ # ./ #
1 parent 01881b0 commit f9f750f

File tree

9 files changed

+69
-20
lines changed

9 files changed

+69
-20
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ if ( (NOT MPI_Fortran_MODULE_COMPILES) AND (NOT MPI_Fortran_INCLUDE_COMPILES) )
252252
)
253253
endif()
254254

255-
if ( NOT MPI_Fortran_MODULE_COMPILES )
255+
if ( MPI_Fortran_MODULE_COMPILES )
256+
add_definitions(-DMPI_WORKING_MODULE)
257+
else()
256258
message ( WARNING "It appears that MPI was built with a different Fortran compiler. "
257259
"It is possible that this may cause unpredictable behavior. The build will continue "
258260
"using `mpif.h` BUT please report any suspicious behavior to the OpenCoarrays "

src/extensions/opencoarrays.F90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ module opencoarrays
3232
use iso_c_binding, only : c_int,c_char,c_ptr,c_loc,c_double,c_int32_t,c_ptrdiff_t,c_sizeof,c_bool,c_funloc
3333
implicit none
3434

35+
#ifndef MPI_WORKING_MODULE
36+
#include 'mpif.h'
37+
#endif
38+
3539
private
3640
public :: co_reduce
3741
public :: co_broadcast
@@ -726,7 +730,9 @@ subroutine co_sum_c_int(a,result_image,stat,errmsg)
726730

727731
! Return the image number (MPI rank + 1)
728732
function this_image() result(image_num)
733+
#ifdef MPI_WORKING_MODULE
729734
use mpi, only : MPI_Comm_rank
735+
#endif
730736
integer(c_int) :: image_num,ierr
731737
!image_num = opencoarrays_this_image(unused)
732738
call MPI_Comm_rank(CAF_COMM_WORLD,image_num,ierr)
@@ -736,7 +742,9 @@ function this_image() result(image_num)
736742

737743
! Return the total number of images
738744
function num_images() result(num_images_)
745+
#ifdef MPI_WORKING_MODULE
739746
use mpi, only : MPI_Comm_size
747+
#endif
740748
integer(c_int) :: num_images_,ierr
741749
!num_images_ = opencoarrays_num_images(unused_coarray,unused_scalar)
742750
call MPI_Comm_size(CAF_COMM_WORLD,num_images_,ierr)

src/mpi/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ endif()
3434
if (MPI_Fortran_MODULE_COMPILES)
3535
# likely the same compiler compiled MPI
3636
set(MPI_CAF_FORTRAN_FILES ../extensions/opencoarrays.F90)
37-
elseif(MPI_Fortran_INCLUDE_COMPILES)
38-
# Likely a different version or completely different Fortran compiler built MPI
39-
# Since the .mod file is incompatible hack together a replacement
40-
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/my_mpi_mod.f90"
41-
"
42-
module mpi
43-
implicit none
44-
public
45-
include 'mpif.h'
46-
end module"
47-
)
48-
set(MPI_CAF_FORTRAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/my_mpi_mod.f90" ../extensions/opencoarrays.F90 )
4937
endif()
5038

5139
add_library(caf_mpi mpi_caf.c ../common/caf_auxiliary.c ${MPI_CAF_FORTRAN_FILES})

src/tests/integration/dist_transpose/coarray_distributed_transpose.F90

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,21 @@
3535
module run_size
3636
use iso_fortran_env
3737
#ifndef HAVE_WALLTIME
38-
use MPI, only : WALLTIME=>MPI_WTIME
38+
# ifdef MPI_WORKING_MODULE
39+
use MPI, only : WALLTIME=>MPI_WTIME
40+
implicit none
41+
# else
42+
implicit none
43+
# include 'mpif.h'
44+
interface WALLTIME
45+
function MPI_WTIME() result(res)
46+
double precision :: res
47+
end function
48+
end interface WALLTIME
49+
# endif
50+
#else
51+
implicit none
3952
#endif
40-
implicit none
4153
integer(int64), codimension[*] :: nx, ny, nz
4254
integer(int64), codimension[*] :: my, mx, first_y, last_y, first_x, last_x
4355
integer(int64) :: my_node, num_nodes

src/tests/integration/pde_solvers/navier-stokes/coarray-shear_coll.F90

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,21 @@ module run_size
112112
use iso_fortran_env, only : int64,real64 ! 64-bit integer and real kind parameters
113113
use constants_module, only : one ! 64-bit unit to ensure argument kind match
114114
#ifndef HAVE_WALLTIME
115-
use MPI, only : WALLTIME=>MPI_WTIME
115+
# ifdef MPI_WORKING_MODULE
116+
use MPI, only : WALLTIME=>MPI_WTIME
117+
implicit none
118+
# else
119+
implicit none
120+
# include 'mpif.h'
121+
interface WALLTIME
122+
function MPI_WTIME() result(res)
123+
double precision :: res
124+
end function
125+
end interface WALLTIME
126+
# endif
127+
#else
128+
implicit none
116129
#endif
117-
implicit none
118130
real, codimension[*] :: viscos, shear, b11, b22, b33, b12, velmax
119131
integer(int64), codimension[*] :: nx, ny, nz, nsteps, output_step
120132
integer(int64), codimension[*] :: my, mx, first_y, last_y, first_x, last_x

src/tests/performance/BurgersMPI/shared.F90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626

2727
module shared
2828
!module for sharing mpi functionality/variables with other modules/main
29+
#ifdef MPI_WORKING_MODULE
2930
use mpi !non-native mpi functionality
31+
#else
32+
# include 'mpif.h'
33+
#endif
3034
integer :: tag, status(MPI_STATUS_SIZE)
3135
integer :: MPI_COMM_CART
3236
integer :: my_id, num_procs, ierr, local_grid_resolution, left_id, right_id

src/tests/performance/mpi_dist_transpose/mpi_distributed_transpose.F90

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,21 @@
3838
module mpi_run_size
3939
use iso_fortran_env
4040
#ifndef HAVE_WALLTIME
41-
use MPI, only : WALLTIME=>MPI_WTIME
41+
# ifdef MPI_WORKING_MODULE
42+
use MPI, only : WALLTIME=>MPI_WTIME
43+
implicit none
44+
# else
45+
implicit none
46+
# include 'mpif.h'
47+
interface WALLTIME
48+
function MPI_WTIME() result(res)
49+
double precision :: res
50+
end function
51+
end interface WALLTIME
52+
# endif
53+
#else
54+
implicit none
4255
#endif
43-
implicit none
4456
integer(int64) :: nx, ny, nz
4557
integer(int64) :: my, mx, first_y, last_y, first_x, last_x
4658
integer(int64) :: my_node, num_nodes

src/tests/unit/init_register/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_executable(initialize_mpi initialize_mpi.f90)
1+
add_executable(initialize_mpi initialize_mpi.F90)
22
target_link_libraries(initialize_mpi OpenCoarrays)
33

44
add_executable(register register.f90)

src/tests/unit/init_register/initialize_mpi.f90 renamed to src/tests/unit/init_register/initialize_mpi.F90

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,19 @@
2626
! SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727
!
2828
program initialize_mpi
29+
#ifdef MPI_WORKING_MODULE
2930
use mpi, only : MPI_COMM_SIZE,MPI_COMM_WORLD
3031
implicit none
32+
#else
33+
implicit none
34+
# include 'mpif.h'
35+
interface
36+
subroutine MPI_COMM_SIZE(mpi_comm,nranks,ierr)
37+
integer, intent(in) :: mpi_comm
38+
integer, intent(out) :: nranks, ierr
39+
end subroutine
40+
end interface
41+
#endif
3142

3243
! Set invalid default image number and number of ranks
3344
integer :: me=-1,np=-1,ierr

0 commit comments

Comments
 (0)