Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for Hpx 1 5 #187

Merged
merged 5 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions auxiliary/cinchtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,12 @@
#define CINCH_WRITE(f) cinch::test_output_t::instance().to_file((f))

// Dump captured output on failure
#if !defined(_MSC_VER)
#define CINCH_ASSERT(ASSERTION, ...) \
ASSERT_##ASSERTION(__VA_ARGS__) << CINCH_DUMP()
#else
// MSVC has a brain-dead preprocessor...
#define CINCH_ASSERT(ASSERTION, x, y) ASSERT_##ASSERTION(x, y) << CINCH_DUMP()
#endif

// Dump captured output on failure
#if !defined(_MSC_VER)
#define CINCH_EXPECT(EXPECTATION, ...) \
EXPECT_##EXPECTATION(__VA_ARGS__) << CINCH_DUMP()
#else
// MSVC has a brain-dead preprocessor...
#define CINCH_EXPECT(EXPECTATION, x, y) \
EXPECT_##EXPECTATION(x, y) << CINCH_DUMP()
#endif

// compare collections with varying levels of assertions
#define CINCH_CHECK_EQUAL_COLLECTIONS(...) \
Expand Down
85 changes: 73 additions & 12 deletions auxiliary/test-hpx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <vector>

#if defined(CINCH_ENABLE_MPI)
#include <cstdlib>
#include <mpi.h>
#endif

Expand Down Expand Up @@ -40,6 +41,39 @@ driver_initialization(int argc, char ** argv) {
}
#endif

#if defined(CINCH_ENABLE_MPI)
namespace detail {
template<char Delimiter>
struct word_delimited_by : std::string {};

template<char Delimiter>
inline std::istream &
operator>>(std::istream & is, word_delimited_by<Delimiter> & str) {
std::getline(is, str, Delimiter);
return is;
}

bool
detect_mpi_environment() {
#if defined(__bgq__)
// If running on BG/Q, we can safely assume to always run in an
// MPI environment
return true;
#else
static std::vector<std::string> const envvars = {"MV2_COMM_WORLD_RANK",
"PMI_RANK", "OMPI_COMM_WORLD_SIZE", "ALPS_APP_PE", "PMIX_RANK"};

for(auto const & envvar : envvars) {
char * env = std::getenv(envvar.c_str());
if(env)
return true;
}
return false;
#endif
}
} // namespace detail
#endif

//----------------------------------------------------------------------------//
// Implement a function to print test information for the user.
//----------------------------------------------------------------------------//
Expand All @@ -51,10 +85,14 @@ print_devel_code_label(std::string name) {
clog_rank(info, 0) << OUTPUT_LTGREEN("Executing development target " << name)
<< std::endl;

// This is safe even if the user creates other comms, because we
// execute this function before handing control over to the user
// code logic.
MPI_Barrier(MPI_COMM_WORLD);
#if defined(CINCH_ENABLE_MPI)
if(::detail::detect_mpi_environment()) {
// This is safe even if the user creates other comms, because we
// execute this function before handing control over to the user
// code logic.
MPI_Barrier(MPI_COMM_WORLD);
}
#endif
} // print_devel_code_label
#endif

Expand All @@ -68,11 +106,21 @@ main(int argc, char ** argv) {
int rank = 0;

#if defined(CINCH_ENABLE_MPI)
// Initialize the MPI runtime
MPI_Init(&argc, &argv);

// Disable XML output, if requested, everywhere but rank 0
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
bool has_mpi = ::detail::detect_mpi_environment();
if(has_mpi) {
// Initialize the MPI runtime
int provided;
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
if(provided < MPI_THREAD_MULTIPLE) {
printf("ERROR: Your implementation of MPI does not support "
"MPI_THREAD_MULTIPLE which is required for use of "
"MPI conduit with the HPX-MPI Interop!\n");
}
assert(provided == MPI_THREAD_MULTIPLE);

// Disable XML output, if requested, everywhere but rank 0
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
}

std::vector<char *> args(argv, argv + argc);
if(rank > 0) {
Expand Down Expand Up @@ -117,7 +165,14 @@ main(int argc, char ** argv) {
} // if

#if defined(CINCH_ENABLE_MPI)
MPI_Finalize();
if(has_mpi) {
int finalized = 1;
MPI_Finalized(&finalized);
if (!finalized) {
// Shutdown the MPI runtime
MPI_Finalize();
}
}
#endif

return 1;
Expand Down Expand Up @@ -165,8 +220,14 @@ main(int argc, char ** argv) {
} // if

#if defined(CINCH_ENABLE_MPI)
// Shutdown the MPI runtime
MPI_Finalize();
if(has_mpi) {
int finalized = 1;
MPI_Finalized(&finalized);
if (!finalized) {
// Shutdown the MPI runtime
MPI_Finalize();
}
}
#endif

return result;
Expand Down
2 changes: 1 addition & 1 deletion cmake/detail/test-policies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
set(test_policy_exec_threads ${MPIEXEC_NUMPROC_FLAG})
set(test_policy_defines -DCINCH_ENABLE_MPI)

elseif(MPI_${MPI_LANGUAGE}_FOUND AND HPX_FOUND AND
elseif(HPX_FOUND AND # MPI_${MPI_LANGUAGE}_FOUND AND
(test_POLICY STREQUAL "HPX" OR test_POLICY STREQUAL "MPI"))

set(test_policy_runtime ${CINCH_SOURCE_DIR}/auxiliary/test-hpx.cc)
Expand Down
1 change: 1 addition & 0 deletions cmake/devel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function(cinch_add_devel_target name)
string(TOUPPER ${_first} _first)
string(REGEX REPLACE "^.(.*)" "${_first}\\1" _leafdir "${_leafdir}")
string(CONCAT _folder "Tests/" ${_leafdir})
string(CONCAT _folder ${_folder} "/Devel")
set_target_properties(${name} PROPERTIES FOLDER "${_folder}")

endfunction(cinch_add_devel_target)
Expand Down
2 changes: 2 additions & 0 deletions cmake/hpx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ if(ENABLE_HPX)
add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
add_definitions(-D_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING)
add_definitions(-DGTEST_LANG_CXX11=1)
add_definitions(-Zc:preprocessor -wd5104 -wd5105)
add_definitions(-wd4244 -wd4251 -wd4275) # from gtest
endif()

message(STATUS "HPX found: ${HPX_FOUND}")
Expand Down
6 changes: 3 additions & 3 deletions cmake/unit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ endif(ENABLE_UNIT_TESTS)
Test does NOT get run (but still build) if
ENV{'OPENMPI'} is "true".
``FOLDER``
specify folder for MS Office input files
specify folder for MS Office input files
``GPUCOUNT <gpuscount>...``
specify the number of GPU to run the test with Kokkos CUDA support
specify the number of GPU to run the test with Kokkos CUDA support
#]=============================================================================]

function(cinch_add_unit name)
Expand All @@ -147,7 +147,7 @@ function(cinch_add_unit name)
set(options NOCI NOOPENMPI)
set(one_value_args POLICY)
set(multi_value_args
SOURCES INPUTS THREADS LIBRARIES DEFINES DRIVER ARGUMENTS TESTLABELS
SOURCES INPUTS THREADS LIBRARIES DEFINES DRIVER ARGUMENTS TESTLABELS
FOLDER GPUCOUNT)
cmake_parse_arguments(unit "${options}" "${one_value_args}"
"${multi_value_args}" ${ARGN})
Expand Down