From dcd458c30ea0c4ccffcc43a0748750e28edb0ba4 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Wed, 10 Jul 2024 13:48:26 +0200 Subject: [PATCH 1/3] Fixed 19 --- src/delegator.cpp | 56 +++++++++++++++++++++++++++++++++-------------- src/delegator.hpp | 15 ++++++++----- 2 files changed, 48 insertions(+), 23 deletions(-) diff --git a/src/delegator.cpp b/src/delegator.cpp index ea73f97..57d44d7 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -18,11 +18,11 @@ #include "backends/extrae/extrae_type_stack.hpp" #endif -void Delegator::InitDetectionBackend(const std::string_view backend) { +void Delegator::InitDetectionBackend(const std::string &backend) { pn_annotation_strategy_ = std::make_unique(); } -void Delegator::InitNonProperlyNestedBackends(const std::string_view backend) { +void Delegator::InitNonProperlyNestedBackends(const std::string &backend) { // check if backend is supplied if (backend.compare(NPNDefault::name) == 0) { @@ -36,12 +36,12 @@ void Delegator::InitNonProperlyNestedBackends(const std::string_view backend) { else { npn_annotation_strategy_ = std::make_unique(); - std::cout << "Could not find a matching PNP backend with name" << backend - << " now selecting the Default" << std::endl; + std::cout << "Could not find a matching NotProperlyNested backend with name" + << backend << " now selecting the Default" << std::endl; } } -void Delegator::InitProperlyNestedBackends(const std::string_view backend) { +void Delegator::InitProperlyNestedBackends(const std::string &backend) { if (backend.compare(PNDefault::name) == 0) { pn_annotation_strategy_ = std::make_unique(); } @@ -55,14 +55,14 @@ void Delegator::InitProperlyNestedBackends(const std::string_view backend) { pn_annotation_strategy_ = std::make_unique(); } #endif - else { - std::cout << "Could not find a matching properly nested backend with name" - << backend << " skipping." << std::endl; - } } -void Delegator::Init(std::string_view nesting_mode, std::string_view backend) { - std::cout << nesting_mode << "Backend:" << backend << std::endl; +void Delegator::Init(std::string_view nesting_mode, + std::string_view backend_in) { + std::string backend = std::string(backend_in); + + std::cout << "NESMIK init called with: " << nesting_mode + << " and Backend: " << backend << std::endl; // detect nesting mode requested by the user if (nesting_mode.compare("?") == 0) { @@ -87,6 +87,11 @@ void Delegator::Init(std::string_view nesting_mode, std::string_view backend) { std::cout << "Selecting nesting mode to: " << "assume properly nested behavior" << std::endl; break; + case NestingMode::ProperlyNestedButOtherBackend: + std::cout << "Something went wrong when selecting the nesting mode" + << std::endl; + exit(1); + break; } if (stringsAreCaseInsensitiveEqual("ENV", std::string(backend))) { @@ -114,17 +119,22 @@ void Delegator::Init(std::string_view nesting_mode, std::string_view backend) { // one InitProperlyNestedBackends(backend); if (pn_annotation_strategy_ == nullptr) { - std::cout << "No ProperlyNested backend found, proceeding with Not " - "Properly Nested Backend" + std::cout + << "Could not find a matching ProperlyNested backend with name " + << backend << std::endl; + std::cout << "Now looking for a NonProperlyNested backend, as they " + "support ProperlyNested ones" << std::endl; + InitNonProperlyNestedBackends(backend); - nesting_mode_ = NestingMode::NotProperlyNested; + nesting_mode_ = NestingMode::ProperlyNestedButOtherBackend; } break; } switch (nesting_mode_) { case NestingMode::NotProperlyNested: + case NestingMode::ProperlyNestedButOtherBackend: return npn_annotation_strategy_->Init(); break; case NestingMode::Detection: @@ -139,6 +149,9 @@ void Delegator::RegionStart(std::string_view name) { switch (nesting_mode_) { case NestingMode::NotProperlyNested: return npn_annotation_strategy_->RegionStart({name}); + case NestingMode::ProperlyNestedButOtherBackend: + name_stack_.push(std::string(name)); + return npn_annotation_strategy_->RegionStart({name}); case NestingMode::Detection: case NestingMode::ProperlyNested: // First push to stack @@ -150,6 +163,7 @@ void Delegator::RegionStart(std::string_view name) { void Delegator::RegionStop(std::string_view name) { switch (nesting_mode_) { case NestingMode::NotProperlyNested: + case NestingMode::ProperlyNestedButOtherBackend: return npn_annotation_strategy_->RegionStop({name}); break; case NestingMode::Detection: @@ -166,15 +180,23 @@ void Delegator::RegionStopLast() { switch (nesting_mode_) { case NestingMode::NotProperlyNested: std::cout << "Calling region_stop_last() is not supported in " - "NotProperlyNested Backends" + "NotProperlyNested Codes" << std::endl; break; case NestingMode::Detection: case NestingMode::ProperlyNested: + case NestingMode::ProperlyNestedButOtherBackend: const std::string stack_empty = "NESMIK: STACK EMPTPY"; - const std::string& last_region_name = + const std::string &last_region_name = name_stack_.empty() ? stack_empty : name_stack_.top(); - pn_annotation_strategy_->RegionStopLast({last_region_name, name_stack_}); + + if (nesting_mode_ == NestingMode::Detection || + nesting_mode_ == NestingMode::ProperlyNested) { + pn_annotation_strategy_->RegionStopLast( + {last_region_name, name_stack_}); + } else if (nesting_mode_ == NestingMode::ProperlyNestedButOtherBackend) { + npn_annotation_strategy_->RegionStop({last_region_name}); + } if (!name_stack_.empty()) { name_stack_.pop(); } diff --git a/src/delegator.hpp b/src/delegator.hpp index dd521aa..2369f12 100644 --- a/src/delegator.hpp +++ b/src/delegator.hpp @@ -6,7 +6,12 @@ #include #include -enum class NestingMode { Detection, ProperlyNested, NotProperlyNested }; +enum class NestingMode { + Detection, + ProperlyNested, + NotProperlyNested, + ProperlyNestedButOtherBackend +}; class Delegator { private: @@ -27,10 +32,8 @@ class Delegator { static void Finalize(); private: - static std::vector SplitString(const std::string &str, - char delimiter); - static void InitDetectionBackend(const std::string_view backend); - static void InitNonProperlyNestedBackends(const std::string_view backend); - static void InitProperlyNestedBackends(const std::string_view backend); + static void InitDetectionBackend(const std::string &backend); + static void InitNonProperlyNestedBackends(const std::string &backend); + static void InitProperlyNestedBackends(const std::string &backend); }; #endif // NESMIK_DELEGATOR_HPP -- GitLab From 3c1dd8d16db209c2f12cafd1d0fa9f8634d2db40 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Wed, 10 Jul 2024 14:20:42 +0200 Subject: [PATCH 2/3] Removed Properly nested default backend. --- src/backends/default/default.cpp | 28 ++-------------------------- src/backends/default/default.hpp | 12 ------------ src/delegator.cpp | 4 ++-- 3 files changed, 4 insertions(+), 40 deletions(-) diff --git a/src/backends/default/default.cpp b/src/backends/default/default.cpp index 63d3468..0fe3a45 100644 --- a/src/backends/default/default.cpp +++ b/src/backends/default/default.cpp @@ -3,30 +3,6 @@ #include #include -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; -} - -void PNDefault::RegionStopLast( - const ProperlyNestedRegionInformation ®ion) noexcept { - std::cout << "Region stop: " << region.name << std::endl; -} - -void PNDefault::Init() noexcept { - std::cout << "nesmik::Init() Backend: PN;Default " << std::endl; -} -void PNDefault::Finalize() noexcept { - std::cout << "nesmik::Finalize() Backend: PN;Default " << std::endl; -} - -// NPN - NPNDefault::NPNDefault() { parallelism_descriptor_ = {.mpi_descriptor_ = MPIDescriptor::DontCare, .thread_descriptor_ = ThreadDescriptor::Supported}; @@ -43,8 +19,8 @@ void NPNDefault::RegionStop( } void NPNDefault::Init() noexcept { - std::cout << "nesmik::Init() Backend: NPN;Default " << std::endl; + std::cout << "nesmik::Init() Backend: Default " << std::endl; } void NPNDefault::Finalize() noexcept { - std::cout << "nesmik::Finalize() Backend: NPN;Default " << std::endl; + std::cout << "nesmik::Finalize() Backend: Default " << std::endl; } diff --git a/src/backends/default/default.hpp b/src/backends/default/default.hpp index 2792dbd..7158c24 100644 --- a/src/backends/default/default.hpp +++ b/src/backends/default/default.hpp @@ -2,18 +2,6 @@ #include "strategies.hpp" -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; - virtual void Init() noexcept; - virtual void Finalize() noexcept; -}; - class NPNDefault : public NotProperlyNestedAnnotationStrategy { public: NPNDefault(); diff --git a/src/delegator.cpp b/src/delegator.cpp index 57d44d7..d95a378 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -42,8 +42,8 @@ void Delegator::InitNonProperlyNestedBackends(const std::string &backend) { } void Delegator::InitProperlyNestedBackends(const std::string &backend) { - if (backend.compare(PNDefault::name) == 0) { - pn_annotation_strategy_ = std::make_unique(); + if (false) { + // a bit ugly, but worky } #ifdef ENABLE_EXTRAE else if (backend.compare(ExtraeTypeStackStrategy::name) == 0) { -- GitLab From d14793bf84d33984feb01b94cb18e278a92c8723 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Wed, 10 Jul 2024 14:54:51 +0200 Subject: [PATCH 3/3] Adding comments --- src/delegator.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/delegator.hpp b/src/delegator.hpp index 2369f12..314056d 100644 --- a/src/delegator.hpp +++ b/src/delegator.hpp @@ -7,10 +7,11 @@ #include enum class NestingMode { - Detection, - ProperlyNested, - NotProperlyNested, - ProperlyNestedButOtherBackend + Detection, // When selecting the very special Detection backend + ProperlyNested, // Application is properly nested + NotProperlyNested, // Application annotation is not properly nested + ProperlyNestedButOtherBackend // Application is properly nested, but were + // using a not properly nested backend }; class Delegator { -- GitLab