Skip to content

Commit 355bbbc

Browse files
committed
Ensure tests are NOT oversubscribed for OpenMPI
1 parent e45b182 commit 355bbbc

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

CMakeLists.txt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,30 @@ add_custom_target ( uninstall
151151

152152
enable_testing()
153153

154+
# Determine if we're using Open MPI
155+
execute_process(COMMAND ${MPIEXEC} --version
156+
OUTPUT_VARIABLE mpi_version_out)
157+
if (mpi_version_out MATCHES "[Oo]pen[ -][Mm][Pp][Ii]")
158+
message( STATUS "OpenMPI detected")
159+
set ( openmpi true )
160+
endif ()
161+
162+
include( ProcessorCount )
163+
ProcessorCount(N)
154164
function(add_mpi_test name num_mpi_proc path)
155-
set(test_parameters ${MPIEXEC_NUMPROC_FLAG} ${num_mpi_proc} )
165+
if ( ((N LESS num_mpi_proc) OR (N EQUAL 0)) )
166+
message(STATUS "Test ${name} is oversubscribed: ${num_mpi_proc} ranks requested with ${N} system processor available.")
167+
if ( openmpi )
168+
if ( N LESS 2 )
169+
set( num_mpi_proc 2 )
170+
set (test_parameters --oversubscribed)
171+
else()
172+
set ( num_mpi_proc ${N} )
173+
endif()
174+
message( STATUS "Open-MPI detected, over-riding oversubscribed test, ${name}, with ${num_mpi_proc} ranks." )
175+
endif()
176+
endif()
177+
set(test_parameters ${test_parameters} ${MPIEXEC_NUMPROC_FLAG} ${num_mpi_proc} )
156178
add_test(NAME ${name} COMMAND ${MPIEXEC} ${test_parameters} "${path}")
157179
set_property(TEST ${name} PROPERTY PASS_REGULAR_EXPRESSION "Test passed.")
158180
endfunction(add_mpi_test)

0 commit comments

Comments
 (0)