Skip to content

Commit fca8657

Browse files
authored
Merge pull request #364 from sourceryinstitute/bugfix-#359
Ensure the correct MPIEXEC is used - Fixes #359 - Closes #360 (supersedes outdated PR)
2 parents 28e62f5 + 9d066ff commit fca8657

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

CMakeLists.txt

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.0)
1+
cmake_minimum_required(VERSION 3.2)
22

33
# Set the type/configuration of build to perform
44
set ( CMAKE_CONFIGURATION_TYPES "Debug" "Release" "MinSizeRel" "RelWithDebInfo" "CodeCoverage" )
@@ -90,7 +90,7 @@ the C compiler if it matches the Fortran compiler ID." )
9090
endif()
9191
set( CMAKE_Fortran_COMPILER_VERSION "${DETECTED_VER}" )
9292
endif()
93-
93+
9494
# We have populated CMAKE_Fortran_COMPILER_VERSION if it was missing
9595
if(gfortran_compiler AND (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER 5.0.0))
9696
set(opencoarrays_aware_compiler true)
@@ -155,7 +155,7 @@ endif()
155155

156156
find_package( MPI )
157157

158-
if ( (NOT MPI_C_FOUND) OR (NOT MPI_Fortran_FOUND) )
158+
if ( (NOT MPI_C_FOUND) OR (NOT MPI_Fortran_FOUND) OR (NOT MPIEXEC))
159159
find_program (MY_MPI_EXEC NAMES mpirun mpiexec lamexec srun
160160
PATHS "${CMAKE_SOURCE_DIR/prerequisites/installations/mpich/3.1.4}" "${CMAKE_SOURCE_DIR}/prerequisites/installations/mpich/*" ENV PATH
161161
HINTS "${FTN_COMPILER_DIR}" "${C_COMPILER_DIR}"
@@ -164,6 +164,46 @@ if ( (NOT MPI_C_FOUND) OR (NOT MPI_Fortran_FOUND) )
164164
find_package( MPI REQUIRED )
165165
endif()
166166

167+
# Test for consistent MPI environment
168+
if (NOT MPIEXEC)
169+
message ( ERROR "CMake failed to find `mpiexec` or similar. If building with `./install.sh` please
170+
report this bug to the OpenCoarrays developers at
171+
https://github.com/sourceryinstitute/opencoarrays/issues, otherwise use point CMake
172+
to the desired MPI runtime.")
173+
endif()
174+
175+
get_filename_component(MPIEXEC_RELATIVE_LOC "${MPIEXEC}"
176+
PROGRAM)
177+
get_filename_component(MPIEXEC_ABS_LOC "${MPIEXEC_RELATIVE_LOC}"
178+
REALPATH)
179+
get_filename_component(MPIEXEC_DIR "${MPIEXEC_ABS_LOC}"
180+
DIRECTORY)
181+
182+
get_filename_component(MPICC_RELATIVE_LOC "${MPI_C_COMPILER}"
183+
PROGRAM)
184+
get_filename_component(MPICC_ABS_LOC "${MPICC_RELATIVE_LOC}"
185+
REALPATH)
186+
get_filename_component(MPICC_DIR "${MPICC_ABS_LOC}"
187+
DIRECTORY)
188+
189+
get_filename_component(MPIFC_RELATIVE_LOC "${MPI_Fortran_COMPILER}"
190+
PROGRAM)
191+
get_filename_component(MPIFC_ABS_LOC "${MPIFC_RELATIVE_LOC}"
192+
REALPATH)
193+
get_filename_component(MPIFC_DIR "${MPIFC_ABS_LOC}"
194+
DIRECTORY)
195+
196+
if ((MPIEXEC_DIR STREQUAL MPICC_DIR) AND (MPIEXEC_DIR STREQUAL MPIFC_DIR))
197+
message ( STATUS "MPI runtime and compile time environments appear to be consistent")
198+
else()
199+
message ( WARNING "MPIEXEC is in \"${MPIEXEC_DIR},\"
200+
which differs from the location of MPICC and/or MPIFC which are in
201+
\"${MPICC_DIR}\" and \"${MPIFC_DIR},\" respectively.
202+
This is likely indicative of a problem. If building with `./install.sh` please report
203+
this to the OpenCoarrays developers by filing a new issue at:
204+
https://github.com/sourceryinstitute/OpenCoarrays/issues/new")
205+
endif()
206+
167207
#--------------------------------------------------------
168208
# Make sure a simple "hello world" C mpi program compiles
169209
#--------------------------------------------------------

prerequisites/install-functions/build_opencoarrays.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ build_opencoarrays()
2222
FC="${MPIFC_show[0]}"
2323
# Set CC to the MPI implementation's gcc command...
2424
CC="${MPICC_show[0]}"
25+
# try to find mpiexec
26+
MPIEXEC_CANDIDATES=($(find "${MPICC%/*}" -name 'mpiexec' -o -name 'mpirun' -o -name 'lamexec' -o -name 'srun'))
27+
if ! ((${#MPIEXEC_CANDIDATES[@]} >= 1)); then
28+
emergency "Could not find a suitable \`mpiexec\` in directory containing mpi wrappers (${MPICC%/*})"
29+
else
30+
MPIEXEC="${MPIEXEC_CANDIDATES[0]}"
31+
fi
2532
info "Configuring OpenCoarrays in ${PWD} with the command:"
26-
info "CC=\"${CC}\" FC=\"${FC}\" $CMAKE \"${opencoarrays_src_dir}\" -DCMAKE_INSTALL_PREFIX=\"${install_path}\" -DMPI_C_COMPILER=\"${MPICC}\" -DMPI_Fortran_COMPILER=\"${MPIFC}\""
27-
CC="${CC}" FC="${FC}" $CMAKE "${opencoarrays_src_dir}" -DCMAKE_INSTALL_PREFIX="${install_path}" -DMPI_C_COMPILER="${MPICC}" -DMPI_Fortran_COMPILER="${MPIFC}"
33+
info "CC=\"${CC}\" FC=\"${FC}\" $CMAKE \"${opencoarrays_src_dir}\" -DCMAKE_INSTALL_PREFIX=\"${install_path}\" -DMPIEXEC=\"${MPIEXEC}\" -DMPI_C_COMPILER=\"${MPICC}\" -DMPI_Fortran_COMPILER=\"${MPIFC}\""
34+
CC="${CC}" FC="${FC}" $CMAKE "${opencoarrays_src_dir}" -DCMAKE_INSTALL_PREFIX="${install_path}" -DMPIEXEC="${MPIEXEC}" -DMPI_C_COMPILER="${MPICC}" -DMPI_Fortran_COMPILER="${MPIFC}"
2835
info "Building OpenCoarrays in ${PWD} with the command make -j${num_threads}"
2936
make "-j${num_threads}"
3037
if [[ ! -z ${SUDO:-} ]]; then
@@ -33,4 +40,3 @@ build_opencoarrays()
3340
info "Installing OpenCoarrays in ${install_path} with the command ${SUDO:-} make install"
3441
${SUDO:-} make install
3542
}
36-

0 commit comments

Comments
 (0)