Skip to content

Commit 9ecbf35

Browse files
committed
Improve OpenMPI support in unit tests
1 parent dbbbd38 commit 9ecbf35

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,15 +584,16 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
584584
#---------------------------------------------------------------------------------------
585585

586586
# Determine if we're using Open MPI
587+
cmake_host_system_information(RESULT N_CPU QUERY NUMBER_OF_LOGICAL_CORES)
588+
cmake_host_system_information(RESULT HOST_NAME QUERY HOSTNAME)
587589
execute_process(COMMAND ${MPIEXEC} --version
588590
OUTPUT_VARIABLE mpi_version_out)
589591
if (mpi_version_out MATCHES "[Oo]pen[ -][Mm][Pp][Ii]")
590592
message( STATUS "OpenMPI detected")
591593
set ( openmpi true )
594+
# Write out a host file because OMPI's mpiexec is dumb
595+
file(APPEND ${CMAKE_BINARY_DIR}/hostfile "${HOST_NAME} slots=${N_CPU}\n")
592596
endif ()
593-
594-
include( ProcessorCount )
595-
ProcessorCount(N_CPU)
596597
function(add_caf_test name num_caf_img test_target)
597598
# Function to add MPI tests.
598599
if(TARGET ${test_target})
@@ -605,6 +606,10 @@ function(add_caf_test name num_caf_img test_target)
605606
message( FATAL_ERROR "Test ${name} requires ${min_test_imgs} but was only given ${num_caf_images}" )
606607
endif()
607608
endif()
609+
# Add a host file for OMPI
610+
if ( openmpi )
611+
set(test_parameters --hostfile ${CMAKE_BINARY_DIR}/hostfile)
612+
endif()
608613
if ( ((N_CPU LESS num_caf_img) OR (N_CPU EQUAL 0)) )
609614
message(STATUS "Test ${name} is oversubscribed: ${num_caf_img} CAF images requested with ${N_CPU} system processor available.")
610615
if ( openmpi )
@@ -613,7 +618,7 @@ function(add_caf_test name num_caf_img test_target)
613618
elseif ( N_CPU LESS 2 )
614619
set( num_caf_img 2 )
615620
endif()
616-
set (test_parameters --oversubscribe)
621+
set (test_parameters ${test_parameters} --oversubscribe)
617622
message( STATUS "Open-MPI back end detected, passing --oversubscribe for oversubscribed test, ${name}, with ${num_caf_img} ranks/images." )
618623
endif()
619624
endif()
@@ -755,8 +760,8 @@ if(opencoarrays_aware_compiler)
755760

756761
# IMAGE FAIL tests
757762
if(NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0.0)
758-
add_caf_test(image_status_test_1 4 image_status_test_1)
759763
if(CAF_ENABLE_FAILED_IMAGES)
764+
add_caf_test(image_status_test_1 4 image_status_test_1)
760765
if ((NOT DEFINED ENV{TRAVIS}) OR (CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER}))
761766
add_caf_test(image_fail_test_1 4 image_fail_test_1)
762767
set_property(TEST image_fail_test_1 PROPERTY FAIL_REGULAR_EXPRESSION "Test failed.")

0 commit comments

Comments
 (0)