From 94b5b39e97ec646f92371f1bdac2b9eddef978b1 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Wed, 17 Jul 2024 18:09:35 +0200 Subject: [PATCH] - Add debug output for env reading - make handling of init more robust --- src/delegator.cpp | 45 +++++++++++++++++------------- src/utils/environment_variable.hpp | 3 ++ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/delegator.cpp b/src/delegator.cpp index f231283..60f68f5 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -68,7 +68,7 @@ void Delegator::Init(std::string_view nesting_mode, << " and Backend: " << backend << std::endl; } - // detect nesting mode requested by the user + // detect nesting mode specified by the user if (nesting_mode.compare("?") == 0) { nesting_mode_ = NestingMode::Detection; } else if (nesting_mode.compare("ProperlyNested") == 0) { @@ -81,16 +81,16 @@ void Delegator::Init(std::string_view nesting_mode, // Some debug output switch (nesting_mode_) { case NestingMode::Detection: - std::cout << "Selecting nesting mode to: " - << "detecting nesting behavior" << std::endl; + std::cout << "nesting mode set to: " + << "Detection (?)" << std::endl; break; case NestingMode::NotProperlyNested: - std::cout << "Selecting nesting mode to: " - << "non properly nested behavior" << std::endl; + std::cout << "nesting mode set to: " + << "NotProperlyNested" << std::endl; break; case NestingMode::ProperlyNested: - std::cout << "Selecting nesting mode to: " - << "assume properly nested behavior" << std::endl; + std::cout << "nesting mode set to: " + << "ProperlyNested" << std::endl; break; case NestingMode::ProperlyNestedButOtherBackend: std::cout << "Something went wrong when selecting the nesting mode" @@ -111,31 +111,37 @@ void Delegator::Init(std::string_view nesting_mode, // Unwraping the std::optional is safe because the variable is required. backend = env_backend.getValue().value(); + if (mpi_helper_->IsRankNumber(0)) { + std::cout << "Reading Backend from environment variable: " + << env_backend.getEnvName() << "=" << backend << std::endl; + } } // next choose backend switch (nesting_mode_) { + case NestingMode::ProperlyNestedButOtherBackend: + break; case NestingMode::Detection: InitDetectionBackend(backend); break; case NestingMode::ProperlyNested: - case NestingMode::NotProperlyNested: + InitProperlyNestedBackends(backend); // we preferably use a Properly nested backend, // but if this is not possible, we will select the not properly nested // one - InitProperlyNestedBackends(backend); - if (pn_annotation_strategy_ == nullptr) { - if (mpi_helper_->IsRankNumber(0)) { - 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); + [[fallthrough]]; + case NestingMode::NotProperlyNested: + if (pn_annotation_strategy_ == nullptr && mpi_helper_->IsRankNumber(0)) { + std::cout + << "Could not find a matching ProperlyNested backend with name " + << backend << std::endl; + std::cout << "Now looking for a NotProperlyNested backend, as they " + "support ProperlyNested ones" + << std::endl; nesting_mode_ = NestingMode::ProperlyNestedButOtherBackend; } + + InitNonProperlyNestedBackends(backend); break; } @@ -214,6 +220,7 @@ void Delegator::RegionStopLast() { void Delegator::Finalize() { switch (nesting_mode_) { case NestingMode::NotProperlyNested: + case NestingMode::ProperlyNestedButOtherBackend: return npn_annotation_strategy_->Finalize(); break; case NestingMode::Detection: diff --git a/src/utils/environment_variable.hpp b/src/utils/environment_variable.hpp index edf98f3..e370c67 100644 --- a/src/utils/environment_variable.hpp +++ b/src/utils/environment_variable.hpp @@ -51,6 +51,9 @@ class EnvironmentVariable { public: std::optional getValue() const { return value_; } bool isSet() const { return value_.has_value(); } + std::string getEnvName() const { + return EnvironmentVariable::PREFIX + variable_name_; + } }; #endif // NESMIK_ENVIROMENT_VARIABLE_HPP -- GitLab