diff --git a/src/backends/default/default.cpp b/src/backends/default/default.cpp index 63d34684a925433fe33af5235d828a7cf4d987a4..0fe3a459cdf4f46de739e993216a7168b942f381 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 2792dbd93c3c05c4ce1fbf61d336ca23e662263c..7158c24880387e08a69638d141458b364b3ccaab 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 ea73f973363c0211b307824be7c3f6a5259f298c..d95a378b2d4f9c0860632e128438721383c0671b 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,14 +36,14 @@ 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) { - if (backend.compare(PNDefault::name) == 0) { - pn_annotation_strategy_ = std::make_unique(); +void Delegator::InitProperlyNestedBackends(const std::string &backend) { + if (false) { + // a bit ugly, but worky } #ifdef ENABLE_EXTRAE else if (backend.compare(ExtraeTypeStackStrategy::name) == 0) { @@ -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 dd521aaa11ec3cf646446e57ef994c651f0ef906..314056d616597b8ddfbeb7ab2d6abf8de604275f 100644 --- a/src/delegator.hpp +++ b/src/delegator.hpp @@ -6,7 +6,13 @@ #include #include -enum class NestingMode { Detection, ProperlyNested, NotProperlyNested }; +enum class NestingMode { + 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 { private: @@ -27,10 +33,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