Skip to content

Commit

Permalink
Merge fix for OpenMPI check in cross-compiling mode
Browse files Browse the repository at this point in the history
This merge replaces try-run with try-compile in OpenMPI check.

try-run can't be run in cross-compiling mode, which happens for example on Macs. So, the sufficient OpenMPI version check has been re-written to run at compile time.

Related PR: #1446
  • Loading branch information
MarcelKoch authored Oct 31, 2023
2 parents 565ec65 + f135d1e commit 1e10b24
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,21 @@ if(GINKGO_BUILD_MPI)
set(GINKGO_HAVE_GPU_AWARE_MPI OFF)
endif()

try_run(uses_openmpi gko_result_unused
# use try_compile instead of try_run to prevent cross-compiling issues
try_compile(uses_openmpi
${Ginkgo_BINARY_DIR}
${Ginkgo_SOURCE_DIR}/cmake/openmpi_test.cpp
COMPILE_DEFINITIONS -DCHECK_HAS_OPEN_MPI=1
LINK_LIBRARIES MPI::MPI_CXX
RUN_OUTPUT_VARIABLE openmpi_version
)
if(uses_openmpi)
if(openmpi_version VERSION_LESS "4.1")
try_compile(valid_openmpi_version
${Ginkgo_BINARY_DIR}
${Ginkgo_SOURCE_DIR}/cmake/openmpi_test.cpp
COMPILE_DEFINITIONS -DCHECK_OPEN_MPI_VERSION=1
LINK_LIBRARIES MPI::MPI_CXX
)
if(NOT valid_openmpi_version)
message(WARNING
"OpenMPI v4.0.x has a bug that forces us to use blocking communication in our distributed "
"matrix class. To enable faster, non-blocking communication, consider updating your OpenMPI version or "
Expand Down
12 changes: 7 additions & 5 deletions cmake/openmpi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

int main()
{
#if defined(OPEN_MPI) && OPEN_MPI
std::printf("%d.%d.%d", OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION,
OMPI_RELEASE_VERSION);
return 1;
#if CHECK_HAS_OPEN_MPI && defined(OPEN_MPI) && OPEN_MPI
static_assert(true, "Check availability of OpenMPI");
#elif CHECK_OPEN_MPI_VERSION && defined(OPEN_MPI) && OPEN_MPI
static_assert(OMPI_MAJOR_VERSION > 4 ||
(OMPI_MAJOR_VERSION == 4 && OMPI_MINOR_VERSION >= 1),
"Check OpenMPI version.");
#else
return 0;
static_assert(false, "No OpenMPI available");
#endif
}

0 comments on commit 1e10b24

Please sign in to comment.