From 4a402ed0f2579310d6dfff4c3a59c4e1cbc3fc7d Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 1 Oct 2024 19:59:05 +0200 Subject: [PATCH 1/8] unify level description into inline function --- src/backends/extrae_type_stack/extrae_type_stack.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backends/extrae_type_stack/extrae_type_stack.cpp b/src/backends/extrae_type_stack/extrae_type_stack.cpp index 43b816f..92d062c 100644 --- a/src/backends/extrae_type_stack/extrae_type_stack.cpp +++ b/src/backends/extrae_type_stack/extrae_type_stack.cpp @@ -14,6 +14,10 @@ extern "C" { #include } +inline std::string getLevelString(const std::size_t leve){ + return "Level: " + std::to_string(i); +} + ExtraeTypeStackStrategy::ExtraeTypeStackStrategy() : mpi_helper_{}, extrae_wrapper_{base_type_} { parallelism_descriptor_ = { @@ -24,7 +28,7 @@ ExtraeTypeStackStrategy::ExtraeTypeStackStrategy() void ExtraeTypeStackStrategy::Init() noexcept { // initialize the stack levels up to MAX_STACK_LEVELS for (std::size_t i = 0; i < MAX_STACK_LEVELS; i++) { - std::string description = "Level: " + std::to_string(i); + const std::string description = getLevelString(i); extrae_wrapper_.RegisterTypeWithDescription(description, base_type_ + i); } } @@ -35,7 +39,7 @@ void ExtraeTypeStackStrategy::RegionStart( const auto regionName = std::string(region.name); const auto level = region.stack_.size(); max_stack_size = std::max(level, max_stack_size); - std::string description = "Level: " + std::to_string(level); + const std::string description = getLevelString(level); extrae_wrapper_.StartWithTypeNameAndRegionName(description, regionName); } void ExtraeTypeStackStrategy::RegionStopLast( -- GitLab From e5542177371d7e99017d10bf98d2f282e5dc449c Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 1 Oct 2024 19:59:34 +0200 Subject: [PATCH 2/8] Add tests to enable MPMPD in Extrae --- tests/CMakeLists.txt | 31 +++++++++++++-------------- tests/cpp/TestCppTalpTreeMPI_MPMD.cpp | 9 ++++++-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9223038..2ac8198 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -34,29 +34,28 @@ target_include_directories(TestCppTalpTree add_test(NAME TestCppTalpTree COMMAND TestCppTalpTree) +endif() - if(WITH_MPI AND WITH_MPI_TESTS) - - add_executable(TestCppTalpTreeMPI cpp/TestCppTalpTreeMPI.cpp) - target_link_libraries(TestCppTalpTreeMPI nesmik::nesmik MPI::MPI_CXX) - target_include_directories(TestCppTalpTreeMPI - PRIVATE ${NESMIK_PUBLIC_HEADERS}) +if(WITH_MPI AND WITH_MPI_TESTS) + 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 TestCppTalpTree) + add_test(NAME TestCppTalpTreeMPI + COMMAND TestCppTalpTree) - add_executable(TestCppTalpTreeMPI_MPMD cpp/TestCppTalpTreeMPI_MPMD.cpp) - target_link_libraries(TestCppTalpTreeMPI_MPMD nesmik::nesmik MPI::MPI_CXX) - target_include_directories(TestCppTalpTreeMPI_MPMD - PRIVATE ${NESMIK_PUBLIC_HEADERS}) + add_executable(TestCppTalpTreeMPI_MPMD cpp/TestCppTalpTreeMPI_MPMD.cpp) + target_link_libraries(TestCppTalpTreeMPI_MPMD nesmik::nesmik MPI::MPI_CXX) + target_include_directories(TestCppTalpTreeMPI_MPMD + PRIVATE ${NESMIK_PUBLIC_HEADERS}) - add_test(NAME TestCppTalpTreeMPI_MPMD - COMMAND TestCppTalpTreeMPI_MPMD) + add_test(NAME TestCppTalpTreeMPI_MPMD + COMMAND TestCppTalpTreeMPI_MPMD) - endif() +endif() -endif() if(ENABLE_EXTRAE) add_executable(TestCppExtraeTypeStack cpp/TestCppExtraeTypeStack.cpp) diff --git a/tests/cpp/TestCppTalpTreeMPI_MPMD.cpp b/tests/cpp/TestCppTalpTreeMPI_MPMD.cpp index 600f2d3..e09dd72 100644 --- a/tests/cpp/TestCppTalpTreeMPI_MPMD.cpp +++ b/tests/cpp/TestCppTalpTreeMPI_MPMD.cpp @@ -6,10 +6,15 @@ int main() { int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); nesmik::nesmik_init(); + + MPI_Barrier(MPI_COMM_WORLD); + // each process has its own regions nesmik::region_start("Top"); - nesmik::region_start(std::to_string(rank)); - nesmik::region_stop(std::to_string(rank)); + nesmik::region_start("rank: "+std::to_string(rank)); + nesmik::region_stop("rank: "+std::to_string(rank)); nesmik::region_stop("Top"); + + MPI_Barrier(MPI_COMM_WORLD); nesmik::nesmik_finalize(); MPI_Finalize(); } -- GitLab From d55727d93abb76dd2de6f5be3d3e6787fa91af47 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 1 Oct 2024 20:00:43 +0200 Subject: [PATCH 3/8] fix typo --- src/backends/extrae_type_stack/extrae_type_stack.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backends/extrae_type_stack/extrae_type_stack.cpp b/src/backends/extrae_type_stack/extrae_type_stack.cpp index 92d062c..0e28b63 100644 --- a/src/backends/extrae_type_stack/extrae_type_stack.cpp +++ b/src/backends/extrae_type_stack/extrae_type_stack.cpp @@ -14,8 +14,8 @@ extern "C" { #include } -inline std::string getLevelString(const std::size_t leve){ - return "Level: " + std::to_string(i); +inline std::string getLevelString(const std::size_t level){ + return "Level: " + std::to_string(level); } ExtraeTypeStackStrategy::ExtraeTypeStackStrategy() -- GitLab From cf90a6d995545e021bdd859036a1b53f3413974b Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 1 Oct 2024 20:01:23 +0200 Subject: [PATCH 4/8] rename internal extrae_types --- .../extrae_partial_tracer/extrae_partial_tracer.hpp | 2 +- src/backends/extrae_type_stack/extrae_type_stack.hpp | 2 +- src/backends/wrappers/extrae/extrae_types.hpp | 6 ++++-- src/backends/wrappers/extrae/paraver_config.cpp | 2 +- src/backends/wrappers/extrae/paraver_config.hpp | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp b/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp index f704595..b4cbe5a 100644 --- a/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp +++ b/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp @@ -51,7 +51,7 @@ class ExtraePartialTracer : public ProperlyNestedAnnotationStrategy { std::unique_ptr type_stack_strategy_; void shutdown() noexcept; void start() noexcept; - const extrae_type state_type_{82000}; + const actual_extrae_type state_type_{82000}; const std::string type_description_ = "Extrae::PartialTracer State"; public: diff --git a/src/backends/extrae_type_stack/extrae_type_stack.hpp b/src/backends/extrae_type_stack/extrae_type_stack.hpp index 2275991..8726fac 100644 --- a/src/backends/extrae_type_stack/extrae_type_stack.hpp +++ b/src/backends/extrae_type_stack/extrae_type_stack.hpp @@ -13,7 +13,7 @@ class ExtraeTypeStackStrategy : public ProperlyNestedAnnotationStrategy { private: const bool write_config_file_default_{true}; - const extrae_type base_type_{81000}; // base event for the MPI wrapper + const actual_extrae_type base_type_{81000}; // base event for the MPI wrapper const std::size_t MAX_STACK_LEVELS = 50; // maximum of supported stack levels EnvironmentVariable write_config_file_ = EnvironmentVariable( diff --git a/src/backends/wrappers/extrae/extrae_types.hpp b/src/backends/wrappers/extrae/extrae_types.hpp index 35c5025..895fc57 100644 --- a/src/backends/wrappers/extrae/extrae_types.hpp +++ b/src/backends/wrappers/extrae/extrae_types.hpp @@ -1,5 +1,7 @@ #ifndef NESMIK_EXTRAE_TYPES_HPP #define NESMIK_EXTRAE_TYPES_HPP -typedef unsigned long extrae_value; -typedef unsigned long extrae_type; +// This defines the acutally supported types by extrae and paraver. (Spoiler: its not what their APIs promote ;)) +// See https://github.com/bsc-performance-tools/extrae/issues/110 and https://github.com/bsc-performance-tools/extrae/issues/111 +typedef int actual_extrae_value; +typedef int actual_extrae_type; #endif // NESMIK_EXTRAE_TYPES_HPP diff --git a/src/backends/wrappers/extrae/paraver_config.cpp b/src/backends/wrappers/extrae/paraver_config.cpp index 0caa3c0..d458c23 100644 --- a/src/backends/wrappers/extrae/paraver_config.cpp +++ b/src/backends/wrappers/extrae/paraver_config.cpp @@ -93,7 +93,7 @@ void ParaverConfig::addTimeline(ParaverTimelineWindow window_config) { auto replaced_window_y_pos = std::regex_replace( replaced_event_num, std::regex("NESMIK_REPLACE_WINDOW_Y_POSITION"), std::to_string(150)); - extrae_value max_value_in_array{0}; + actual_extrae_value max_value_in_array{0}; auto max_value_in_array_iterator = std::max_element(window_config.semantic_maximums.begin(), diff --git a/src/backends/wrappers/extrae/paraver_config.hpp b/src/backends/wrappers/extrae/paraver_config.hpp index 91d609f..e52979d 100644 --- a/src/backends/wrappers/extrae/paraver_config.hpp +++ b/src/backends/wrappers/extrae/paraver_config.hpp @@ -8,8 +8,8 @@ struct ParaverTimelineWindow { const std::vector &window_names; - const std::vector &types; - const std::vector semantic_maximums; + const std::vector &types; + const std::vector semantic_maximums; std::optional stacked_window_name; }; -- GitLab From d3fdd08d014047b2457adb6fed621e2e5b1f226e Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 1 Oct 2024 20:02:19 +0200 Subject: [PATCH 5/8] - Move to const string& for all strings - Introduce hashes values to allow MPMD WARNING: No hash collision detection and only INT used for hashes --- .../wrappers/extrae/extrae_wrapper.cpp | 46 +++++++++++++------ .../wrappers/extrae/extrae_wrapper.hpp | 27 ++++++----- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/backends/wrappers/extrae/extrae_wrapper.cpp b/src/backends/wrappers/extrae/extrae_wrapper.cpp index 735d87f..d6216dd 100644 --- a/src/backends/wrappers/extrae/extrae_wrapper.cpp +++ b/src/backends/wrappers/extrae/extrae_wrapper.cpp @@ -10,10 +10,16 @@ #include "extrae_types.hpp" #include "paraver_config.hpp" + +#ifdef WITH_MPI +#include +#endif + extern "C" { #include } -ExtraeWrapper::ExtraeWrapper(extrae_type base_type) : base_type_(base_type) { + +ExtraeWrapper::ExtraeWrapper(actual_extrae_type base_type) : base_type_(base_type) { auto isInitializedVal = Extrae_is_initialized(); if (isInitializedVal == 0) { // Extrae is not initialized yet see @@ -24,25 +30,30 @@ ExtraeWrapper::ExtraeWrapper(extrae_type base_type) : base_type_(base_type) { } } -extrae_value ExtraeWrapper::getValueByName(extrae_type type, +actual_extrae_value ExtraeWrapper::getValueByName(actual_extrae_type type, const std::string &name) { value_map_t &value_map = string_to_value_; if (value_map.count(name) > 0) { return value_map[name]; } else - // if not allocate new entry { - const auto newValue = value_map.size() + 1; - value_map[name] = newValue; - return newValue; + // allocate a new value by hashing the string name + auto hash = std::hash{}(name); + actual_extrae_value downcasted_hash = static_cast(hash); + if(downcasted_hash < 0){ + // as we dont support negative values in the .pcf files, we also engineer around that ;) + downcasted_hash*=-1; + } + value_map[name] = downcasted_hash; + return downcasted_hash; } } void ExtraeWrapper::RegisterTypeWithDescription( - const std::string &type_description, extrae_type type) { + const std::string &type_description, actual_extrae_type type) { type_map_[type_description] = type; } -void ExtraeWrapper::StartWithTypeAndRegionName(extrae_type type, +void ExtraeWrapper::StartWithTypeAndRegionName(actual_extrae_type type, const std::string &value_str) { const auto value = getValueByName(type, value_str); // write it in type specific map @@ -51,13 +62,13 @@ void ExtraeWrapper::StartWithTypeAndRegionName(extrae_type type, static_cast(value)); } -void ExtraeWrapper::StopWithTypeAndRegionName(extrae_type type, +void ExtraeWrapper::StopWithTypeAndRegionName(actual_extrae_type type, const std::string &value_str) { Extrae_eventandcounters(static_cast(type), 0); } void ExtraeWrapper::StopWithTypeNameAndRegionName( - const std::string type_description, const std::string &value_str) { + const std::string &type_description, const std::string &value_str) { // if this assertion fails, the type with that description has not been // registered before and not started. assert(type_map_.count(type_description) > 0); @@ -65,7 +76,7 @@ void ExtraeWrapper::StopWithTypeNameAndRegionName( } void ExtraeWrapper::StartWithTypeNameAndRegionName( - const std::string type_description, const std::string &value_str) { + const std::string& type_description, const std::string &value_str) { if (type_map_.count(type_description) == 0) { const auto new_type = type_map_.size(); type_map_[type_description] = base_type_ + new_type; @@ -74,7 +85,8 @@ void ExtraeWrapper::StartWithTypeNameAndRegionName( } void ExtraeWrapper::Finalize() { - // now for ever type define the event types: + + // for ever type define the event types: for (const auto &[description, type_from_map] : type_map_) { // For every type registered: extrae_type_t type = static_cast(type_from_map); @@ -121,14 +133,18 @@ std::string ExtraeWrapper::getParaverConfig(ExtraeParaverConfig config) { ParaverConfig paraver_config(config.description); // create arrays - std::vector types; + std::vector types; std::vector window_names; - std::vector semantic_maximums; + std::vector semantic_maximums; for (const auto &[name, type] : type_map_) { + if(type_to_value_map_[type].empty()){ + // dont put into the paraver config if no values have been recorded + continue; + } types.push_back(type); window_names.push_back(name); // now the ugly search for the semantic maximum - extrae_value semantic_maximum{0}; + actual_extrae_value semantic_maximum{0}; for (const auto &[value_name, value] : type_to_value_map_[type]) { semantic_maximum = std::max(value, semantic_maximum); } diff --git a/src/backends/wrappers/extrae/extrae_wrapper.hpp b/src/backends/wrappers/extrae/extrae_wrapper.hpp index 6fd0ce5..2e84afb 100644 --- a/src/backends/wrappers/extrae/extrae_wrapper.hpp +++ b/src/backends/wrappers/extrae/extrae_wrapper.hpp @@ -5,6 +5,8 @@ #include #include +#include + #include "extrae_types.hpp" struct ExtraeParaverConfig { @@ -12,32 +14,33 @@ struct ExtraeParaverConfig { std::string description; }; -using value_map_t = std::unordered_map; +using value_map_t = std::unordered_map; class ExtraeWrapper { - const extrae_type base_type_; + const actual_extrae_type base_type_; private: - std::unordered_map type_map_; - std::unordered_map type_to_value_map_; - std::unordered_map string_to_value_; + std::unordered_map type_map_; + std::unordered_map type_to_value_map_; + std::unordered_map string_to_value_; + MPIHelper mpi_helper_; bool did_init_extrae_{false}; EnvironmentVariable finalize_extrae_ = EnvironmentVariable( "CALL_EXTRAE_FINALZIE", "Enable it to tell neSmiK to call Extrae_fini upon finalization.", false); - extrae_value getValueByName(extrae_type type, const std::string &name); + actual_extrae_value getValueByName(actual_extrae_type type, const std::string &name); public: - ExtraeWrapper(extrae_type base_type); + ExtraeWrapper(actual_extrae_type base_type); void RegisterTypeWithDescription(const std::string &type_description, - extrae_type type); - void StartWithTypeNameAndRegionName(const std::string type_description, + actual_extrae_type type); + void StartWithTypeNameAndRegionName(const std::string &type_description, const std::string &value_str); - void StartWithTypeAndRegionName(extrae_type type, + void StartWithTypeAndRegionName(actual_extrae_type type, const std::string &value_str); - void StopWithTypeAndRegionName(extrae_type type, + void StopWithTypeAndRegionName(actual_extrae_type type, const std::string &value_str); - void StopWithTypeNameAndRegionName(const std::string type_description, + void StopWithTypeNameAndRegionName(const std::string &type_description, const std::string &value_str); std::string getParaverConfig(ExtraeParaverConfig config); -- GitLab From 439ab8bee0c922733637b41ed38caebbffe2a9b5 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 1 Oct 2024 20:04:17 +0200 Subject: [PATCH 6/8] make pre-commit happy --- .../extrae_type_stack/extrae_type_stack.cpp | 2 +- .../extrae_type_stack/extrae_type_stack.hpp | 2 +- src/backends/wrappers/extrae/extrae_types.hpp | 6 +++-- .../wrappers/extrae/extrae_wrapper.cpp | 24 +++++++++---------- .../wrappers/extrae/extrae_wrapper.hpp | 4 ++-- tests/cpp/TestCppTalpTreeMPI_MPMD.cpp | 4 ++-- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/backends/extrae_type_stack/extrae_type_stack.cpp b/src/backends/extrae_type_stack/extrae_type_stack.cpp index 0e28b63..7b61177 100644 --- a/src/backends/extrae_type_stack/extrae_type_stack.cpp +++ b/src/backends/extrae_type_stack/extrae_type_stack.cpp @@ -14,7 +14,7 @@ extern "C" { #include } -inline std::string getLevelString(const std::size_t level){ +inline std::string getLevelString(const std::size_t level) { return "Level: " + std::to_string(level); } diff --git a/src/backends/extrae_type_stack/extrae_type_stack.hpp b/src/backends/extrae_type_stack/extrae_type_stack.hpp index 8726fac..c8ccf25 100644 --- a/src/backends/extrae_type_stack/extrae_type_stack.hpp +++ b/src/backends/extrae_type_stack/extrae_type_stack.hpp @@ -13,7 +13,7 @@ class ExtraeTypeStackStrategy : public ProperlyNestedAnnotationStrategy { private: const bool write_config_file_default_{true}; - const actual_extrae_type base_type_{81000}; // base event for the MPI wrapper + const actual_extrae_type base_type_{81000}; // base event for the MPI wrapper const std::size_t MAX_STACK_LEVELS = 50; // maximum of supported stack levels EnvironmentVariable write_config_file_ = EnvironmentVariable( diff --git a/src/backends/wrappers/extrae/extrae_types.hpp b/src/backends/wrappers/extrae/extrae_types.hpp index 895fc57..f960f53 100644 --- a/src/backends/wrappers/extrae/extrae_types.hpp +++ b/src/backends/wrappers/extrae/extrae_types.hpp @@ -1,7 +1,9 @@ #ifndef NESMIK_EXTRAE_TYPES_HPP #define NESMIK_EXTRAE_TYPES_HPP -// This defines the acutally supported types by extrae and paraver. (Spoiler: its not what their APIs promote ;)) -// See https://github.com/bsc-performance-tools/extrae/issues/110 and https://github.com/bsc-performance-tools/extrae/issues/111 +// This defines the actually supported types by extrae and paraver. (Spoiler: +// its not what their APIs promote ;)) See +// https://github.com/bsc-performance-tools/extrae/issues/110 and +// https://github.com/bsc-performance-tools/extrae/issues/111 typedef int actual_extrae_value; typedef int actual_extrae_type; #endif // NESMIK_EXTRAE_TYPES_HPP diff --git a/src/backends/wrappers/extrae/extrae_wrapper.cpp b/src/backends/wrappers/extrae/extrae_wrapper.cpp index d6216dd..1eab24e 100644 --- a/src/backends/wrappers/extrae/extrae_wrapper.cpp +++ b/src/backends/wrappers/extrae/extrae_wrapper.cpp @@ -10,7 +10,6 @@ #include "extrae_types.hpp" #include "paraver_config.hpp" - #ifdef WITH_MPI #include #endif @@ -19,7 +18,8 @@ extern "C" { #include } -ExtraeWrapper::ExtraeWrapper(actual_extrae_type base_type) : base_type_(base_type) { +ExtraeWrapper::ExtraeWrapper(actual_extrae_type base_type) + : base_type_(base_type) { auto isInitializedVal = Extrae_is_initialized(); if (isInitializedVal == 0) { // Extrae is not initialized yet see @@ -31,18 +31,19 @@ ExtraeWrapper::ExtraeWrapper(actual_extrae_type base_type) : base_type_(base_typ } actual_extrae_value ExtraeWrapper::getValueByName(actual_extrae_type type, - const std::string &name) { + const std::string &name) { value_map_t &value_map = string_to_value_; if (value_map.count(name) > 0) { return value_map[name]; - } else - { + } else { // allocate a new value by hashing the string name auto hash = std::hash{}(name); - actual_extrae_value downcasted_hash = static_cast(hash); - if(downcasted_hash < 0){ - // as we dont support negative values in the .pcf files, we also engineer around that ;) - downcasted_hash*=-1; + actual_extrae_value downcasted_hash = + static_cast(hash); + if (downcasted_hash < 0) { + // as we dont support negative values in the .pcf files, we also engineer + // around that ;) + downcasted_hash *= -1; } value_map[name] = downcasted_hash; return downcasted_hash; @@ -76,7 +77,7 @@ void ExtraeWrapper::StopWithTypeNameAndRegionName( } void ExtraeWrapper::StartWithTypeNameAndRegionName( - const std::string& type_description, const std::string &value_str) { + const std::string &type_description, const std::string &value_str) { if (type_map_.count(type_description) == 0) { const auto new_type = type_map_.size(); type_map_[type_description] = base_type_ + new_type; @@ -85,7 +86,6 @@ void ExtraeWrapper::StartWithTypeNameAndRegionName( } void ExtraeWrapper::Finalize() { - // for ever type define the event types: for (const auto &[description, type_from_map] : type_map_) { // For every type registered: @@ -137,7 +137,7 @@ std::string ExtraeWrapper::getParaverConfig(ExtraeParaverConfig config) { std::vector window_names; std::vector semantic_maximums; for (const auto &[name, type] : type_map_) { - if(type_to_value_map_[type].empty()){ + if (type_to_value_map_[type].empty()) { // dont put into the paraver config if no values have been recorded continue; } diff --git a/src/backends/wrappers/extrae/extrae_wrapper.hpp b/src/backends/wrappers/extrae/extrae_wrapper.hpp index 2e84afb..54b3c59 100644 --- a/src/backends/wrappers/extrae/extrae_wrapper.hpp +++ b/src/backends/wrappers/extrae/extrae_wrapper.hpp @@ -4,7 +4,6 @@ #include #include #include - #include #include "extrae_types.hpp" @@ -28,7 +27,8 @@ class ExtraeWrapper { "CALL_EXTRAE_FINALZIE", "Enable it to tell neSmiK to call Extrae_fini upon finalization.", false); - actual_extrae_value getValueByName(actual_extrae_type type, const std::string &name); + actual_extrae_value getValueByName(actual_extrae_type type, + const std::string &name); public: ExtraeWrapper(actual_extrae_type base_type); diff --git a/tests/cpp/TestCppTalpTreeMPI_MPMD.cpp b/tests/cpp/TestCppTalpTreeMPI_MPMD.cpp index e09dd72..f5e7c67 100644 --- a/tests/cpp/TestCppTalpTreeMPI_MPMD.cpp +++ b/tests/cpp/TestCppTalpTreeMPI_MPMD.cpp @@ -10,8 +10,8 @@ int main() { MPI_Barrier(MPI_COMM_WORLD); // each process has its own regions nesmik::region_start("Top"); - nesmik::region_start("rank: "+std::to_string(rank)); - nesmik::region_stop("rank: "+std::to_string(rank)); + nesmik::region_start("rank: " + std::to_string(rank)); + nesmik::region_stop("rank: " + std::to_string(rank)); nesmik::region_stop("Top"); MPI_Barrier(MPI_COMM_WORLD); -- GitLab From 1fc93d306794e28a854c243a1e861018971fad11 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Wed, 2 Oct 2024 08:02:56 +0200 Subject: [PATCH 7/8] Added an eviroment variable to write all the regions, even though we might not enable tracing on them --- .../extrae_partial_tracer.cpp | 28 +++++++++++++++++++ .../extrae_partial_tracer.hpp | 6 ++++ 2 files changed, 34 insertions(+) diff --git a/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp b/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp index d2efb16..c70e682 100644 --- a/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp +++ b/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp @@ -79,12 +79,28 @@ void ExtraePartialTracer::Init() noexcept { << job.stop_at << "}" << std::endl; } } + if (mpi_helper_.IsRankNumber(0) && + write_all_regions_.getValue().value_or(false)) { + std::cout << "neSmiK Partial Tracer: Writing all regions even though " + "tracing might be off" + << std::endl; + } } void ExtraePartialTracer::RegionStart( const ProperlyNestedRegionInformation ®ion) noexcept { const std::string region_name = std::string(region.name); + if (write_all_regions_.getValue().value_or(false)) { + if (is_shutdown_) { + start(); + type_stack_strategy_->RegionStart(region); + shutdown(); + } else { + type_stack_strategy_->RegionStart(region); + } + } + // A bit costly maybe if there is a lot of jobs, but much easier than keeping // a tree or hashmap around std::vector matching_jobs; @@ -134,6 +150,18 @@ void ExtraePartialTracer::RegionStopLast( const ProperlyNestedRegionInformation ®ion) noexcept { const std::string region_name = std::string(region.name); + if (write_all_regions_.getValue().value_or(false)) { + if (write_all_regions_.getValue().value_or(false)) { + if (is_shutdown_) { + start(); + type_stack_strategy_->RegionStopLast(region); + shutdown(); + } else { + type_stack_strategy_->RegionStopLast(region); + } + } + } + if (!is_shutdown_) { std::cout << "Region stop last " << region.name << std::endl; type_stack_strategy_->RegionStopLast(region); diff --git a/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp b/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp index b4cbe5a..d613fd7 100644 --- a/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp +++ b/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp @@ -42,6 +42,12 @@ class ExtraePartialTracer : public ProperlyNestedAnnotationStrategy { "EXTRAE_WRITE_CONFIG_FILE", "Write corresponding Paraver .cfg file if set to True", false); + EnvironmentVariable write_all_regions_ = + EnvironmentVariable("PARTIAL_TRACER_ADD_ALL_REGIONS", + "Write all regions into the trace, even though " + "extrae might not be tracing for all of them", + false); + MPIHelper mpi_helper_; std::unordered_map region_counter_starts_; std::unordered_map region_counter_stops_; -- GitLab From 41b95b7075e8b91c36307388d6aa8b9c0b081314 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Wed, 2 Oct 2024 09:50:10 +0200 Subject: [PATCH 8/8] correct logic --- .../extrae_partial_tracer.cpp | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp b/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp index c70e682..9e1593f 100644 --- a/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp +++ b/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp @@ -91,16 +91,6 @@ void ExtraePartialTracer::RegionStart( const ProperlyNestedRegionInformation ®ion) noexcept { const std::string region_name = std::string(region.name); - if (write_all_regions_.getValue().value_or(false)) { - if (is_shutdown_) { - start(); - type_stack_strategy_->RegionStart(region); - shutdown(); - } else { - type_stack_strategy_->RegionStart(region); - } - } - // A bit costly maybe if there is a lot of jobs, but much easier than keeping // a tree or hashmap around std::vector matching_jobs; @@ -144,27 +134,28 @@ void ExtraePartialTracer::RegionStart( if (!is_shutdown_) { type_stack_strategy_->RegionStart(region); } + // If were not running but env is set, we still add it to the trace + if (is_shutdown_ && write_all_regions_.getValue().value_or(false)) { + start(); + type_stack_strategy_->RegionStart(region); + shutdown(); + } } void ExtraePartialTracer::RegionStopLast( const ProperlyNestedRegionInformation ®ion) noexcept { const std::string region_name = std::string(region.name); - if (write_all_regions_.getValue().value_or(false)) { - if (write_all_regions_.getValue().value_or(false)) { - if (is_shutdown_) { - start(); - type_stack_strategy_->RegionStopLast(region); - shutdown(); - } else { - type_stack_strategy_->RegionStopLast(region); - } - } + // We add because were not shutdown + if (!is_shutdown_) { + type_stack_strategy_->RegionStopLast(region); } - if (!is_shutdown_) { - std::cout << "Region stop last " << region.name << std::endl; + // If were shutdown we still add it if the env is set + if (is_shutdown_ && write_all_regions_.getValue().value_or(false)) { + start(); type_stack_strategy_->RegionStopLast(region); + shutdown(); } std::vector matching_jobs; -- GitLab