Skip to content

Commit 0c792d3

Browse files
authored
Merge branch 'master' into bugfix-strided_sendget
2 parents 9b9d845 + 4d6a0d7 commit 0c792d3

File tree

9 files changed

+217
-16
lines changed

9 files changed

+217
-16
lines changed

CMakeLists.txt

Lines changed: 154 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
1515
"CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}"
1616
" == CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}"
1717
"\nThis archive does not support in-source builds:\n"
18-
"You must now delete the CMakeCache.txt file and the CMakeFiles/ directory under"
18+
"You must now delete the CMakeCache.txt file and the CMakeFiles/ directory under "
1919
"the 'src' source directory or you will not be able to configure correctly!"
2020
"\nYou must now run something like:\n"
2121
" $ rm -r CMakeCache.txt CMakeFiles/"
@@ -88,6 +88,7 @@ else()
8888
endif()
8989

9090
if(gfortran_compiler)
91+
set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
9192
set(CMAKE_REQUIRED_FLAGS "-fcoarray=single -ffree-form")
9293
endif()
9394
include(CheckFortranSourceCompiles)
@@ -99,7 +100,8 @@ CHECK_Fortran_SOURCE_COMPILES("
99100
end program
100101
" Check_Simple_Coarray_Fortran_Source_Compiles)
101102
if(gfortran_compiler)
102-
unset(CMAKE_REQUIRED_FLAGS)
103+
set (CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
104+
unset(OLD_REQUIRED_FLAGS)
103105
endif()
104106

105107

@@ -108,17 +110,161 @@ endif()
108110
#----------------------------------------------------------------------------
109111

110112
# If the user passes FC=mpif90 etc. check and prefer that location
111-
get_filename_component( FTN_MPI_DIR "${CMAKE_Fortran_COMPILER}"
113+
get_filename_component( FTN_COMPILER_NAME "${CMAKE_Fortran_COMPILER}"
114+
NAME )
115+
get_filename_component( C_COMPILER_NAME "${CMAKE_C_COMPILER}"
116+
NAME )
117+
get_filename_component( FTN_COMPILER_DIR "${CMAKE_Fortran_COMPILER}"
112118
REALPATH )
113-
get_filename_component( C_MPI_DIR "${CMAKE_C_COMPILER}"
119+
get_filename_component( C_COMPILER_DIR "${CMAKE_C_COMPILER}"
114120
REALPATH )
115-
set ( MPI_HOME "${MPI_HOME}" "${FTN_MPI_DIR}/.." "${C_MPI_DIR}/.." )
116121

117-
# Check the install.sh defaut mpich installation directories
118-
set ( MPI_HOME "${MPI_HOME}" "${CMAKE_SOURCE_DIR}/prerequisites/installations/mpich/3.1.4" "${CMAKE_SOURCE_DIR}/prerequisites/installations/mpich/*" )
122+
if (FTN_COMPILER_NAME MATCHES '^[mM][pP][iI]')
123+
set (MPI_Fortran_COMPILER "${CMAKE_Fortran_COMPILER}")
124+
endif()
125+
if (C_COMPILER_NAME MATCHES '^[mM][pP][iI]')
126+
set (MPI_C_COMPILER "${CMAKE_C_COMPILER}")
127+
endif()
128+
129+
find_package( MPI )
130+
131+
if ( (NOT MPI_C_FOUND) OR (NOT MPI_Fortran_FOUND) )
132+
find_program (MY_MPI_EXEC NAMES mpirun mpiexec lamexec srun
133+
PATHS "${CMAKE_SOURCE_DIR/prerequisites/installations/mpich/3.1.4}" "${CMAKE_SOURCE_DIR}/prerequisites/installations/mpich/*" ENV PATH
134+
HINTS "${FTN_COMPILER_DIR}" "${C_COMPILER_DIR}"
135+
PATH_SUFFIXES bin)
136+
set ( MPI_HOME "${MPI_HOME}" "${MY_MPI_EXEC}" "${MY_MPI_EXEC}/.." )
137+
find_package( MPI REQUIRED )
138+
endif()
119139

120-
find_package( MPI REQUIRED )
140+
#--------------------------------------------------------
141+
# Make sure a simple "hello world" C mpi program compiles
142+
#--------------------------------------------------------
143+
set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
144+
set(CMAKE_REQUIRED_FLAGS ${MPI_C_COMPILE_FLAGS} ${MPI_C_LINK_FLAGS})
145+
set(OLD_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
146+
set(CMAKE_REQUIRED_INCLUDES ${MPI_C_INCLUDE_PATH})
147+
set(OLD_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
148+
set(CMAKE_REQUIRED_LIBRARIES ${MPI_C_LIBRARIES})
149+
include (CheckCSourceCompiles)
150+
CHECK_C_SOURCE_COMPILES("
151+
#include <mpi.h>
152+
#include <stdio.h>
153+
int main(int argc, char** argv) {
154+
MPI_Init(NULL, NULL);
155+
int world_size;
156+
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
157+
int world_rank;
158+
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
159+
char processor_name[MPI_MAX_PROCESSOR_NAME];
160+
int name_len;
161+
MPI_Get_processor_name(processor_name, &name_len);
162+
printf('Hello world from processor %s, rank %d out of %d processors',
163+
processor_name, world_rank, world_size);
164+
MPI_Finalize();
165+
}"
166+
MPI_C_COMPILES)
167+
set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
168+
set(CMAKE_REQUIRED_INCLUDES ${OLD_INCLUDES})
169+
set(CMAKE_REQUIRED_LIBRARIES ${OLD_LIBRARIES})
170+
unset(OLD_REQUIRED_FLAGS)
171+
unset(OLD_INCLUDES)
172+
unset(OLD_LIBRARIES)
173+
174+
if (NOT MPI_C_COMPILES)
175+
message(FATAL_ERROR "MPI_C is missing! "
176+
"Try setting MPI_C_COMPILER to the appropriate C compiler wrapper script and reconfigure. "
177+
"i.e., `cmake -DMPI_C_COMPILER=/path/to/mpicc ..` or set it by editing the cache using "
178+
"cmake-gui or ccmake."
179+
)
180+
endif()
181+
182+
#--------------------------------------------------------------
183+
# Make sure a simple "hello world" Fortran mpi program compiles
184+
# Try using mpi.mod first then fall back on includ 'mpif.h'
185+
#--------------------------------------------------------------
186+
set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
187+
set(CMAKE_REQUIRED_FLAGS "-ffree-form" ${MPI_Fortran_COMPILE_FLAGS} ${MPI_Fortran_LINK_FLAGS})
188+
set(OLD_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
189+
set(CMAKE_REQUIRED_INCLUDES ${MPI_Fortran_INCLUDE_PATH})
190+
set(OLD_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
191+
set(CMAKE_REQUIRED_LIBRARIES ${MPI_Fortran_LIBRARIES})
192+
include (CheckCSourceCompiles)
193+
CHECK_Fortran_SOURCE_COMPILES("
194+
program mpi_hello
195+
use mpi
196+
implicit none
197+
integer :: ierr, mpi_world_size, mpi_world_rank, res_len
198+
character*(MPI_MAX_PROCESSOR_NAME) :: proc
199+
call mpi_init(ierr)
200+
call mpi_comm_size(MPI_COMM_WORLD,mpi_world_size,ierr)
201+
call mpi_comm_rank(MPI_COMM_WORLD,mpi_world_rank,ierr)
202+
call mpi_get_processor_name(proc,res_len,ierr)
203+
write(*,*) 'Hello from processor ', trim(proc), ' rank ', mpi_world_rank, ' out of ', mpi_world_size, '.'
204+
call mpi_finalize(ierr)
205+
end program
206+
"
207+
MPI_Fortran_MODULE_COMPILES)
208+
set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
209+
set(CMAKE_REQUIRED_INCLUDES ${OLD_INCLUDES})
210+
set(CMAKE_REQUIRED_LIBRARIES ${OLD_LIBRARIES})
211+
unset(OLD_REQUIRED_FLAGS)
212+
unset(OLD_INCLUDES)
213+
unset(OLD_LIBRARIES)
214+
215+
#--------------------------------
216+
# If that failed try using mpif.h
217+
#--------------------------------
218+
set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
219+
set(CMAKE_REQUIRED_FLAGS "-ffree-form" ${MPI_Fortran_COMPILE_FLAGS} ${MPI_Fortran_LINK_FLAGS})
220+
set(OLD_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
221+
set(CMAKE_REQUIRED_INCLUDES ${MPI_Fortran_INCLUDE_PATH})
222+
set(OLD_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
223+
set(CMAKE_REQUIRED_LIBRARIES ${MPI_Fortran_LIBRARIES})
224+
include (CheckCSourceCompiles)
225+
CHECK_Fortran_SOURCE_COMPILES("
226+
program mpi_hello
227+
implicit none
228+
include 'mpif.h'
229+
integer :: ierr, mpi_world_size, mpi_world_rank, res_len
230+
character*(MPI_MAX_PROCESSOR_NAME) :: proc
231+
call mpi_init(ierr)
232+
call mpi_comm_size(MPI_COMM_WORLD,mpi_world_size,ierr)
233+
call mpi_comm_rank(MPI_COMM_WORLD,mpi_world_rank,ierr)
234+
call mpi_get_processor_name(proc,res_len,ierr)
235+
write(*,*) 'Hello from processor ', trim(proc), ' rank ', mpi_world_rank, ' out of ', mpi_world_size, '.'
236+
call mpi_finalize(ierr)
237+
end program
238+
"
239+
MPI_Fortran_INCLUDE_COMPILES)
240+
set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
241+
set(CMAKE_REQUIRED_INCLUDES ${OLD_INCLUDES})
242+
set(CMAKE_REQUIRED_LIBRARIES ${OLD_LIBRARIES})
243+
unset(OLD_REQUIRED_FLAGS)
244+
unset(OLD_INCLUDES)
245+
unset(OLD_LIBRARIES)
246+
247+
if ( (NOT MPI_Fortran_MODULE_COMPILES) AND (NOT MPI_Fortran_INCLUDE_COMPILES) )
248+
message ( WARNING "It appears that the Fortran MPI compiler is not working. "
249+
"For OpenCoarrays Aware compilers, this may be irrelavent: "
250+
" The src/extensions/opencoarrays.F90 module will be disabled, but it is "
251+
" possible that the build will succeed, despite this fishy circumstance."
252+
)
253+
endif()
254+
255+
if ( MPI_Fortran_MODULE_COMPILES )
256+
add_definitions(-DMPI_WORKING_MODULE)
257+
else()
258+
message ( WARNING "It appears that MPI was built with a different Fortran compiler. "
259+
"It is possible that this may cause unpredictable behavior. The build will continue "
260+
"using `mpif.h` BUT please report any suspicious behavior to the OpenCoarrays "
261+
"developers."
262+
)
263+
endif()
121264

265+
#----------------
266+
# Setup MPI flags
267+
#----------------
122268
set(CMAKE_C_COMPILE_FLAGS ${CMAKE_C_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS})
123269
set(CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} ${MPI_C_LINK_FLAGS})
124270
set(CMAKE_Fortran_COMPILE_FLAGS ${CMAKE_Fortran_COMPILE_FLAGS} ${MPI_Fortran_COMPILE_FLAGS})

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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ if(CAF_EXPOSE_INIT_FINALIZE)
2828
add_definitions(-DEXPOSE_INIT_FINALIZE)
2929
endif()
3030

31-
add_library(caf_mpi mpi_caf.c ../common/caf_auxiliary.c ../extensions/opencoarrays.F90)
31+
# Determine whether and how to include OpenCoarrays module based on if the Fortran MPI compiler:
32+
# - workds
33+
# - is compatible with the fortran compiler used to build the MPI implementation
34+
if (MPI_Fortran_MODULE_COMPILES)
35+
# likely the same compiler compiled MPI
36+
set(MPI_CAF_FORTRAN_FILES ../extensions/opencoarrays.F90)
37+
endif()
38+
39+
add_library(caf_mpi mpi_caf.c ../common/caf_auxiliary.c ${MPI_CAF_FORTRAN_FILES})
3240
target_link_libraries(caf_mpi PRIVATE ${MPI_C_LIBRARIES} ${MPI_Fortran_LIBRARIES})
3341

3442
set_target_properties ( caf_mpi

src/tests/integration/dist_transpose/coarray_distributed_transpose.F90

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@
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+
# define WALLTIME MPI_WTIME
45+
# endif
46+
#else
47+
implicit none
3948
#endif
40-
implicit none
4149
integer(int64), codimension[*] :: nx, ny, nz
4250
integer(int64), codimension[*] :: my, mx, first_y, last_y, first_x, last_x
4351
integer(int64) :: my_node, num_nodes

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,17 @@ 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+
# define WALLTIME MPI_WTIME
122+
# endif
123+
#else
124+
implicit none
116125
#endif
117-
implicit none
118126
real, codimension[*] :: viscos, shear, b11, b22, b33, b12, velmax
119127
integer(int64), codimension[*] :: nx, ny, nz, nsteps, output_step
120128
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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,17 @@
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+
# define WALLTIME MPI_WTIME
48+
# endif
49+
#else
50+
implicit none
4251
#endif
43-
implicit none
4452
integer(int64) :: nx, ny, nz
4553
integer(int64) :: my, mx, first_y, last_y, first_x, last_x
4654
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)