From 2745299228849c2653e3efa2137fa4208ce0e81e Mon Sep 17 00:00:00 2001 From: Marcel Koch Date: Tue, 31 Oct 2023 14:54:33 +0100 Subject: [PATCH 1/2] 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. --- CMakeLists.txt | 14 +++++++++++--- cmake/openmpi_test.cpp | 12 +++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4f6fa5376d..78ba1f939cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 " diff --git a/cmake/openmpi_test.cpp b/cmake/openmpi_test.cpp index 3b6f33dd5d0..7580a908b6c 100644 --- a/cmake/openmpi_test.cpp +++ b/cmake/openmpi_test.cpp @@ -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; } From f135d1e375b0742b3873e20b0454d2114dce0022 Mon Sep 17 00:00:00 2001 From: Marcel Koch Date: Tue, 31 Oct 2023 15:08:30 +0100 Subject: [PATCH 2/2] review updates: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - unused variable - correct return code - consistent ifdef check - don't use c++17 Co-authored-by: Yu-Hsiang M. Tsai Co-authored-by: Pratik Nayak Co-authored-by: Tobias Ribizel Co-authored-by: Thomas Grützmacher --- CMakeLists.txt | 1 - cmake/openmpi_test.cpp | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78ba1f939cb..fbda6bfb8f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -248,7 +248,6 @@ if(GINKGO_BUILD_MPI) ${Ginkgo_SOURCE_DIR}/cmake/openmpi_test.cpp COMPILE_DEFINITIONS -DCHECK_HAS_OPEN_MPI=1 LINK_LIBRARIES MPI::MPI_CXX - OUTPUT_VARIABLE output ) if(uses_openmpi) try_compile(valid_openmpi_version diff --git a/cmake/openmpi_test.cpp b/cmake/openmpi_test.cpp index 7580a908b6c..94b2774503b 100644 --- a/cmake/openmpi_test.cpp +++ b/cmake/openmpi_test.cpp @@ -39,12 +39,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. int main() { #if CHECK_HAS_OPEN_MPI && defined(OPEN_MPI) && OPEN_MPI - static_assert(true); -#elif CHECK_OPEN_MPI_VERSION + 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)); + (OMPI_MAJOR_VERSION == 4 && OMPI_MINOR_VERSION >= 1), + "Check OpenMPI version."); #else - static_assert(false); + static_assert(false, "No OpenMPI available"); #endif - return 1; }