From 0b480d2602412af1ef78fc0920af730d6d55351b Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 13 Jun 2024 17:57:25 +0200 Subject: [PATCH 1/6] Add descriptors for thread awareness --- src/backends/default/default.cpp | 18 +++++++++++ src/backends/default/default.hpp | 2 ++ src/backends/dlb/dlb/dlb.cpp | 8 +++++ src/backends/dlb/dlb/dlb.hpp | 1 + .../dlb/dlb_talp_tree/dlb_talp_tree.cpp | 10 ++++++ .../dlb/dlb_talp_tree/dlb_talp_tree.hpp | 1 + src/backends/extrae/extrae_type_stack.cpp | 9 ++++++ src/backends/extrae/extrae_type_stack.hpp | 1 + src/strategies.hpp | 32 +++++++++++++++++++ 9 files changed, 82 insertions(+) diff --git a/src/backends/default/default.cpp b/src/backends/default/default.cpp index d460168..7b0c270 100644 --- a/src/backends/default/default.cpp +++ b/src/backends/default/default.cpp @@ -3,6 +3,14 @@ #include "default.hpp" +PNDefault::PNDefault(){ + parallelism_descriptor_={ + .mpi_descriptor_ = MPIDescriptor::DontCare, + .thread_descriptor_ = ThreadDescriptor::Supported + }; +} + + void PNDefault::RegionStart( const ProperlyNestedRegionInformation ®ion) noexcept { std::cout << "Region start: " << region.name << std::endl; @@ -22,6 +30,16 @@ void PNDefault::Finalize() noexcept { // NPN + +NPNDefault::NPNDefault(){ + parallelism_descriptor_={ + .mpi_descriptor_ = MPIDescriptor::DontCare, + .thread_descriptor_ = ThreadDescriptor::Supported + }; +} + + + void NPNDefault::RegionStart( const NotProperlyNestedRegionInformation ®ion) noexcept { std::cout << "Region start: " << region.name << std::endl; diff --git a/src/backends/default/default.hpp b/src/backends/default/default.hpp index 9d8b8e4..8a1242f 100644 --- a/src/backends/default/default.hpp +++ b/src/backends/default/default.hpp @@ -4,6 +4,7 @@ class PNDefault : public ProperlyNestedAnnotationStrategy { public: + PNDefault(); inline static const std::string name = "Default"; void RegionStart(const ProperlyNestedRegionInformation &info_to_start) noexcept override; void RegionStopLast(const ProperlyNestedRegionInformation &info_to_stop) noexcept override; @@ -15,6 +16,7 @@ public: class NPNDefault : public NotProperlyNestedAnnotationStrategy { public: + NPNDefault(); inline static const std::string name = "Default"; virtual void RegionStart(const NotProperlyNestedRegionInformation &info_to_start) noexcept override; virtual void RegionStop(const NotProperlyNestedRegionInformation &info_to_stop) noexcept override; diff --git a/src/backends/dlb/dlb/dlb.cpp b/src/backends/dlb/dlb/dlb.cpp index 3a7b076..6ab4171 100644 --- a/src/backends/dlb/dlb/dlb.cpp +++ b/src/backends/dlb/dlb/dlb.cpp @@ -3,6 +3,14 @@ #include "dlb_talp.h" #include + +DLBTalpStrategy::DLBTalpStrategy(){ + parallelism_descriptor_={ + .mpi_descriptor_ = MPIDescriptor::DontCare, + .thread_descriptor_ = ThreadDescriptor::Supported // Even though it makes no semantical sense + }; +} + void DLBTalpStrategy::RegionStart( const NotProperlyNestedRegionInformation ®ion) noexcept { // we have to create a small std::string thing because we cannot assume that diff --git a/src/backends/dlb/dlb/dlb.hpp b/src/backends/dlb/dlb/dlb.hpp index 83201cc..b3647b1 100644 --- a/src/backends/dlb/dlb/dlb.hpp +++ b/src/backends/dlb/dlb/dlb.hpp @@ -6,6 +6,7 @@ class DLBTalpStrategy : public NotProperlyNestedAnnotationStrategy { public: + DLBTalpStrategy(); inline static const std::string name = "TALP"; virtual void RegionStart(const NotProperlyNestedRegionInformation ®ion) noexcept override; virtual void RegionStop(const NotProperlyNestedRegionInformation ®ion) noexcept override; diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index cefe614..b419ea1 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -8,6 +8,16 @@ #include #include + +DLBTalpTreeStrategy::DLBTalpTreeStrategy(){ + parallelism_descriptor_={ + .mpi_descriptor_ = MPIDescriptor::Aware, + .thread_descriptor_ = ThreadDescriptor::Unsupported + }; +} + + + void DLBTalpTreeStrategy::RegionStart( const ProperlyNestedRegionInformation ®ion) noexcept { diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp index a1c7823..03fb0b9 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp @@ -26,6 +26,7 @@ private: public: + DLBTalpTreeStrategy(); inline static const std::string_view name = "TALP-Tree"; void RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept override; void RegionStopLast(const ProperlyNestedRegionInformation ®ion) noexcept override; diff --git a/src/backends/extrae/extrae_type_stack.cpp b/src/backends/extrae/extrae_type_stack.cpp index ab69008..23c5b4f 100644 --- a/src/backends/extrae/extrae_type_stack.cpp +++ b/src/backends/extrae/extrae_type_stack.cpp @@ -12,6 +12,15 @@ extern "C" { #include } +ExtraeTypeStackStrategy::ExtraeTypeStackStrategy(){ + parallelism_descriptor_={ + .mpi_descriptor_ = MPIDescriptor::Aware, + .thread_descriptor_ = ThreadDescriptor::Supported // i guess no test currently for this + }; +} + + + const std::string ExtraeTypeStackStrategy::paraverConfigHead = R"( diff --git a/src/backends/extrae/extrae_type_stack.hpp b/src/backends/extrae/extrae_type_stack.hpp index 7906dd3..c74ab9f 100644 --- a/src/backends/extrae/extrae_type_stack.hpp +++ b/src/backends/extrae/extrae_type_stack.hpp @@ -31,6 +31,7 @@ private: static extrae_value get_value_by_region_name(const std::string &name); public: + ExtraeTypeStackStrategy(); inline static const std::string_view name = "Extrae::TypeStack"; virtual void RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept override; diff --git a/src/strategies.hpp b/src/strategies.hpp index 7880da0..6b50110 100644 --- a/src/strategies.hpp +++ b/src/strategies.hpp @@ -5,6 +5,34 @@ #include #include + +/* + Describes the Strategy behavior with respect to MPI. +*/ +enum class MPIDescriptor{ + DontCare, // Strategy doesnt know and doesnt care + Aware, // Strategy knows about MPI and can use the PMPI Interface to do e.g. reductions. + Required // Strategy requires MPI (should be safeguareded by build options) +}; + +/* + Describes the Strategy behavior with respect to any thread level parallelism + Mainly concerned if starting and stopping regions is supported from multiple threads +*/ +enum class ThreadDescriptor{ + Supported, + Unsupported +}; + +/* + Bundles the above enums into a nice struct +*/ +struct ParallelismDescriptor{ + MPIDescriptor mpi_descriptor_ = MPIDescriptor::DontCare; + ThreadDescriptor thread_descriptor_ = ThreadDescriptor::Unsupported; +}; + + struct ProperlyNestedRegionInformation { std::string_view name; }; @@ -23,6 +51,8 @@ public: virtual void RegionStopLast(const ProperlyNestedRegionInformation ®ion) noexcept = 0; virtual void Finalize() noexcept = 0; + + ParallelismDescriptor parallelism_descriptor_; }; class NotProperlyNestedAnnotationStrategy { @@ -34,6 +64,8 @@ public: virtual void RegionStop(const NotProperlyNestedRegionInformation ®ion) noexcept = 0; virtual void Finalize() noexcept = 0; + + ParallelismDescriptor parallelism_descriptor_; }; #endif // NESMIK_STRATEGY_HPP \ No newline at end of file -- GitLab From cb96e4fa31c2edcbaa223ecd67393333a3f83f27 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Fri, 14 Jun 2024 12:13:28 +0200 Subject: [PATCH 2/6] Add MPI backend and add paralllelism helper --- CMakeLists.txt | 20 ++++++++- src/CMakeLists.txt | 2 +- src/parallelism_helper.cpp | 84 ++++++++++++++++++++++++++++++++++++++ src/parallelism_helper.hpp | 29 +++++++++++++ 4 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 src/parallelism_helper.cpp create mode 100644 src/parallelism_helper.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f884a73..1434352 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,12 +9,19 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") -option(BACKEND_EXTRAE "Enable Extrae" OFF) -option(BACKEND_DLB "Enable DLB" OFF) +# Available backend options +option(ENABLE_EXTRAE "Enable Extrae" OFF) +option(ENABLE_DLB "Enable DLB" OFF) + +# Install depending options option(BUILD_C_FORTRAN "Enable C and Fortran Interfaces" ON) option(SPLIT_FORTRAN_LIBRARY "Split the fortran symbols into a special library (nesmik_f) - EXPERIMENTAL" OFF) option(GEN_BINDINGS "Use Shroud to Generate C/Fortran interface" OFF) +# Other options +option(WITH_MPI "Compile with MPI" OFF) + + if(BUILD_C_FORTRAN) enable_language(Fortran) set(CMAKE_Fortran_FORMAT FREE) @@ -33,11 +40,20 @@ target_include_directories(${PROJECT_NAME} PUBLIC ) + + if(BUILD_C_FORTRAN AND SPLIT_FORTRAN_LIBRARY) add_library(nesmik_f) add_library(nesmik::nesmik_f ALIAS nesmik_f) endif() +if(WITH_MPI) + find_package(MPI REQUIRED COMPONENTS CXX) + target_link_libraries(${PROJECT_NAME} PUBLIC MPI::MPI_CXX) + target_compile_definitions(nesmik PRIVATE "WITH_MPI") +endif() + + add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f90296..bdc267e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ add_subdirectory(backends) -target_sources(nesmik PRIVATE delegator.cpp nesmik.cpp) +target_sources(nesmik PRIVATE delegator.cpp nesmik.cpp parallelism_helper.cpp) if(BUILD_C_FORTRAN) add_subdirectory(bindings) diff --git a/src/parallelism_helper.cpp b/src/parallelism_helper.cpp new file mode 100644 index 0000000..6c90c13 --- /dev/null +++ b/src/parallelism_helper.cpp @@ -0,0 +1,84 @@ +#include +#include +#include + +#ifdef WITH_MPI +void MPIHelper::MaybeInitMPI() +{ + int is_initialized; + MPI_Initialized(&is_initialized); + if(!is_initialized){ + MPI_Init(NULL, NULL); + did_initialize_ = true; + std::cout << "neSmiK forced to call MPI_Init, please try to make sure to call MPI_Init before calling into neSmiK" << std::endl; + } +} + +bool MPIHelper::IsUsingMPI()const +{ + int is_initialized; + MPI_Initialized(&is_initialized); + if(is_initialized){ + int mpi_size; + MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); + return mpi_size > 1; + } + return false; + +} + +bool MPIHelper::CompiledWithMPI() const { + return true; +} + +bool MPIHelper::IsRankNumber(int asked_rank) const { + int rank; + MPI_Comm_rank(MPI_COMM_WORLD,&rank); + + return rank == asked_rank; +} + +MPIHelper::~MPIHelper(){ + if(did_initialize_){ + MPI_Finalize(); + } +} +#else +void MPIHelper::MaybeInitMPI() const +{ + return; +} + +bool MPIHelper::IsUsingMPI() const +{ + return false; +} + +bool MPIHelper::CompiledWithMPI() const { + return false; +} + +bool MPIHelper::IsRankNumber(int asked_rank) const { + return rank==0; +} + +MPIHelper::~MPIHelper(){ + +} +#endif + + +MPIHelper& MPIHelper::operator=(const MPIHelper& other) +{ + if (this != &other) { // protect against invalid self-assignment + did_initialize_ = other.did_initialize_; + } + // by convention, always return *this + return *this; +} + + +MPIHelper::MPIHelper(MPIHelper &other) +{ + did_initialize_= other.did_initialize_; +} \ No newline at end of file diff --git a/src/parallelism_helper.hpp b/src/parallelism_helper.hpp new file mode 100644 index 0000000..213ecbe --- /dev/null +++ b/src/parallelism_helper.hpp @@ -0,0 +1,29 @@ +#ifndef NESMIK_PARALLELISM_HELPER_HPP +#define NESMIK_PARALLELISM_HELPER_HPP +/* + Small helper class that can be used by Backends to Check MPI status in the application beeing run. +*/ +class MPIHelper{ + private: + bool did_initialize_ =false; + + public: + // returns if the library is compiled with MPI support + bool CompiledWithMPI()const ; + // Inits MPI if necesarry, otherwise does nothing. + void MaybeInitMPI(); + // Check is the application is actually using MPI with more than one process + bool IsUsingMPI() const; + // Checks if rank is a certain one, and 0 if MPI is not active + bool IsRankNumber(int asked_rank) const; + + MPIHelper(MPIHelper &t); // copy constructor + MPIHelper& operator=(const MPIHelper& other); // copy assignment operator + ~MPIHelper(); // Destructor + + MPIHelper() = default; + + +}; + +#endif // NESMIK_PARALLELISM_HELPER_HPP \ No newline at end of file -- GitLab From 6536f66165706aad9a40b10463654a95d4f104e3 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Fri, 14 Jun 2024 12:13:42 +0200 Subject: [PATCH 3/6] Make talp tree mpi aware --- .../dlb/dlb_talp_tree/dlb_talp_tree.cpp | 30 +++++++++++++++---- .../dlb/dlb_talp_tree/dlb_talp_tree.hpp | 4 +++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index b419ea1..4e9fc99 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -8,8 +8,14 @@ #include #include +#ifdef WITH_MPI + #include +#endif -DLBTalpTreeStrategy::DLBTalpTreeStrategy(){ + +#include + +DLBTalpTreeStrategy::DLBTalpTreeStrategy():mpi_helper_{}{ parallelism_descriptor_={ .mpi_descriptor_ = MPIDescriptor::Aware, .thread_descriptor_ = ThreadDescriptor::Unsupported @@ -75,6 +81,8 @@ void DLBTalpTreeStrategy::RegionStopLast( this->talp_profiling_strategy.RegionStart({name}); } + + void DLBTalpTreeStrategy::Init() noexcept { this->current_region = std::hash{}(this->top_region); @@ -85,6 +93,11 @@ void DLBTalpTreeStrategy::Init() noexcept { /* .childs */ {}, }; + + if(mpi_helper_.CompiledWithMPI()){ + mpi_helper_.MaybeInitMPI(); + } + this->talp_profiling_strategy.Init(); } @@ -207,11 +220,18 @@ void DLBTalpTreeStrategy::Finalize() noexcept { region_stream_csv << std::endl; } - std::cout << region_stream_stdout.str() << std::endl; + if(mpi_helper_.IsRankNumber(0)){ + std::cout << region_stream_stdout.str() << std::endl; + } + + + if(mpi_helper_.IsRankNumber(0)){ + std::ofstream csv_stream; + csv_stream.open("nesmik_talp_tree.csv", std::ios::trunc); + csv_stream << region_stream_csv.str() << std::endl; + } + - std::ofstream csv_stream; - csv_stream.open("nesmik_talp_tree.csv", std::ios::trunc); - csv_stream << region_stream_csv.str() << std::endl; this->talp_profiling_strategy.Finalize(); } diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp index 03fb0b9..9e62b3d 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp @@ -8,6 +8,8 @@ #include #include +#include + struct TalpRegionNode { std::string name; std::string tree_lines; @@ -24,6 +26,8 @@ private: std::size_t current_region; std::map regions; + // Mpi aware stuff + MPIHelper mpi_helper_; public: DLBTalpTreeStrategy(); -- GitLab From ddf00a3d5e993ddcec3d5a6bb6f28929e766628f Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Fri, 14 Jun 2024 12:35:01 +0200 Subject: [PATCH 4/6] Smal whoopsie ;) --- src/parallelism_helper.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/parallelism_helper.cpp b/src/parallelism_helper.cpp index 6c90c13..657db3b 100644 --- a/src/parallelism_helper.cpp +++ b/src/parallelism_helper.cpp @@ -44,8 +44,7 @@ MPIHelper::~MPIHelper(){ } } #else -void MPIHelper::MaybeInitMPI() const -{ +void MPIHelper::MaybeInitMPI() { return; } @@ -59,7 +58,7 @@ bool MPIHelper::CompiledWithMPI() const { } bool MPIHelper::IsRankNumber(int asked_rank) const { - return rank==0; + return asked_rank==0; } MPIHelper::~MPIHelper(){ -- GitLab From b5c84b8a8bc6d6b9f92989d8e392feed39fec6dd Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Fri, 14 Jun 2024 14:32:19 +0200 Subject: [PATCH 5/6] Add more robust implementation of the Parallelism Helper --- .../dlb/dlb_talp_tree/dlb_talp_tree.cpp | 8 +-- src/parallelism_helper.cpp | 64 ++++++------------- src/parallelism_helper.hpp | 22 +++---- 3 files changed, 29 insertions(+), 65 deletions(-) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index 4e9fc99..f03b597 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -91,13 +91,7 @@ void DLBTalpTreeStrategy::Init() noexcept { /* .tree_lines */ "", /* .parent */ 0, /* .childs */ {}, - }; - - - if(mpi_helper_.CompiledWithMPI()){ - mpi_helper_.MaybeInitMPI(); - } - + }; this->talp_profiling_strategy.Init(); } diff --git a/src/parallelism_helper.cpp b/src/parallelism_helper.cpp index 657db3b..88f5e13 100644 --- a/src/parallelism_helper.cpp +++ b/src/parallelism_helper.cpp @@ -3,27 +3,11 @@ #include #ifdef WITH_MPI -void MPIHelper::MaybeInitMPI() -{ - int is_initialized; - MPI_Initialized(&is_initialized); - if(!is_initialized){ - MPI_Init(NULL, NULL); - did_initialize_ = true; - std::cout << "neSmiK forced to call MPI_Init, please try to make sure to call MPI_Init before calling into neSmiK" << std::endl; - } -} + bool MPIHelper::IsUsingMPI()const { - int is_initialized; - MPI_Initialized(&is_initialized); - if(is_initialized){ - int mpi_size; - MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); - return mpi_size > 1; - } - return false; + return is_using_mpi_; } @@ -32,21 +16,25 @@ bool MPIHelper::CompiledWithMPI() const { } bool MPIHelper::IsRankNumber(int asked_rank) const { - int rank; - MPI_Comm_rank(MPI_COMM_WORLD,&rank); - - return rank == asked_rank; + return asked_rank== mpi_comm_rank; } -MPIHelper::~MPIHelper(){ - if(did_initialize_){ - MPI_Finalize(); +MPIHelper::MPIHelper(){ + // First check if MPI is initialized + int is_initialized; + MPI_Initialized(&is_initialized); + mpi_is_initialized_ = static_cast(is_initialized); + + if(mpi_is_initialized_){ + MPI_Comm_size(MPI_COMM_WORLD,&mpi_comm_size); + MPI_Comm_rank(MPI_COMM_WORLD,&mpi_comm_rank); + + is_using_mpi_ = mpi_comm_size > 1; } } + #else -void MPIHelper::MaybeInitMPI() { - return; -} + bool MPIHelper::IsUsingMPI() const { @@ -61,23 +49,7 @@ bool MPIHelper::IsRankNumber(int asked_rank) const { return asked_rank==0; } -MPIHelper::~MPIHelper(){ - -} -#endif - - -MPIHelper& MPIHelper::operator=(const MPIHelper& other) -{ - if (this != &other) { // protect against invalid self-assignment - did_initialize_ = other.did_initialize_; - } - // by convention, always return *this - return *this; -} +MPIHelper::MPIHelper(){} -MPIHelper::MPIHelper(MPIHelper &other) -{ - did_initialize_= other.did_initialize_; -} \ No newline at end of file +#endif \ No newline at end of file diff --git a/src/parallelism_helper.hpp b/src/parallelism_helper.hpp index 213ecbe..a0edf1f 100644 --- a/src/parallelism_helper.hpp +++ b/src/parallelism_helper.hpp @@ -5,24 +5,22 @@ */ class MPIHelper{ private: - bool did_initialize_ =false; - + + // Default values for non-MPI execution + bool is_using_mpi_ = false; + bool mpi_is_initialized_ = false; + int mpi_comm_size = 0; + int mpi_comm_rank = 0; + public: + + MPIHelper(); // returns if the library is compiled with MPI support - bool CompiledWithMPI()const ; - // Inits MPI if necesarry, otherwise does nothing. - void MaybeInitMPI(); + bool CompiledWithMPI() const ; // Check is the application is actually using MPI with more than one process bool IsUsingMPI() const; // Checks if rank is a certain one, and 0 if MPI is not active bool IsRankNumber(int asked_rank) const; - - MPIHelper(MPIHelper &t); // copy constructor - MPIHelper& operator=(const MPIHelper& other); // copy assignment operator - ~MPIHelper(); // Destructor - - MPIHelper() = default; - }; -- GitLab From 26f6a57084eb5a0a6d3f846c81482e6d77203689 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Fri, 14 Jun 2024 14:32:29 +0200 Subject: [PATCH 6/6] Add MPI test version --- tests/CMakeLists.txt | 14 ++++++++++++++ tests/cpp/TestCppTalpTreeMPI.cpp | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/cpp/TestCppTalpTreeMPI.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c4c5e24..32c9d06 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,6 +24,20 @@ target_include_directories(TestCppTalpTree add_test(NAME TestCppTalpTree COMMAND TestCppTalpTree) + + if(WITH_MPI) + + add_executable(TestCppTalpTreeMPI cpp/TestCppTalpTreeMPI.cpp) + target_link_libraries(TestCppTalpTreeMPI nesmik::nesmik MPI::MPI_CXX) + target_include_directories(TestCppTalpTreeMPI + PRIVATE ${NESMIK_PUBLIC_HEADERS}) + + add_test(NAME TestCppTalpTreeMPI + COMMAND mpirun -np 2 TestCppTalpTree) + + endif() + + endif() if(ENABLE_EXTRAE) diff --git a/tests/cpp/TestCppTalpTreeMPI.cpp b/tests/cpp/TestCppTalpTreeMPI.cpp new file mode 100644 index 0000000..1e0e648 --- /dev/null +++ b/tests/cpp/TestCppTalpTreeMPI.cpp @@ -0,0 +1,20 @@ +#include "nesmik/nesmik.hpp" +#include +int main() { + MPI_Init(NULL,NULL); + nesmik::init("ProperlyNested","TALP-Tree"); + nesmik::region_start("Top"); + nesmik::region_start("child-1"); + nesmik::region_start("child-1.1"); + nesmik::region_stop("child-1.1"); + nesmik::region_start("child-1.2"); + nesmik::region_stop("child-1.2"); + nesmik::region_stop("child-1"); + nesmik::region_start("child-2"); + nesmik::region_start("child-2.1"); + nesmik::region_stop("child-2.1"); + nesmik::region_stop("child-2"); + nesmik::region_stop("Top"); + nesmik::finalize(); + MPI_Finalize(); +} -- GitLab