Skip to content

Commit

Permalink
replaces try-run with try-compile in OpenMPI check
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MarcelKoch committed Oct 31, 2023
1 parent 565ec65 commit 2745299
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,22 @@ 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
OUTPUT_VARIABLE output
)
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);
#elif CHECK_OPEN_MPI_VERSION
static_assert(OMPI_MAJOR_VERSION > 4 ||
(OMPI_MAJOR_VERSION == 4 && OMPI_MINOR_VERSION >= 1));
#else
return 0;
static_assert(false);
#endif
return 1;
}

0 comments on commit 2745299

Please sign in to comment.