From a6742ad5143231d9381c00ff50d89b9ac72b2109 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Fri, 14 Jun 2024 16:00:43 +0200 Subject: [PATCH 1/7] add skeleton WIP WIP2 WIP --- src/backends/CMakeLists.txt | 2 +- src/backends/detection/CMakeLists.txt | 1 + src/backends/detection/detection.cpp | 119 ++++++++++++++++++++++++++ src/backends/detection/detection.hpp | 57 ++++++++++++ src/delegator.cpp | 27 ++++-- src/delegator.hpp | 3 + src/parallelism_helper.cpp | 9 ++ src/parallelism_helper.hpp | 2 + src/strategies.hpp | 2 + tests/CMakeLists.txt | 3 +- tests/cpp/TestCppTalpTree.cpp | 9 +- 11 files changed, 222 insertions(+), 12 deletions(-) create mode 100644 src/backends/detection/CMakeLists.txt create mode 100644 src/backends/detection/detection.cpp create mode 100644 src/backends/detection/detection.hpp diff --git a/src/backends/CMakeLists.txt b/src/backends/CMakeLists.txt index 43fa57b..ccb0564 100644 --- a/src/backends/CMakeLists.txt +++ b/src/backends/CMakeLists.txt @@ -1,5 +1,5 @@ add_subdirectory(default) - +add_subdirectory(detection) if(ENABLE_DLB) add_subdirectory(dlb) endif() diff --git a/src/backends/detection/CMakeLists.txt b/src/backends/detection/CMakeLists.txt new file mode 100644 index 0000000..e7f4975 --- /dev/null +++ b/src/backends/detection/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(nesmik PRIVATE detection.cpp) diff --git a/src/backends/detection/detection.cpp b/src/backends/detection/detection.cpp new file mode 100644 index 0000000..e9dbbbd --- /dev/null +++ b/src/backends/detection/detection.cpp @@ -0,0 +1,119 @@ +#include "detection.hpp" +#include +#include +#include + +#include + +// for convenience +using json = nlohmann::json; + +void to_json(json& j, const RegionEventEntry& p){ + // first convert to the stack to std::vector in order + + + std::stack local_stack = p.stack_; // copy stack + std::vector stack_vec(local_stack.size()); + + std:: + + for(std::size_t i = p.stack_.size(); i >=0 + // we use camelCase as suggested in https://google.github.io/styleguide/jsoncstyleguide.xml?showone=Property_Name_Format#Property_Name_Format + j = json{ + {"threadId", p.thread_.thread_id_}, + {"processId", p.thread_.process_id_}, + {"regionName", p.region_name_}, + {"stack", p.timestamp}, + {"timestamp", p.timestamp} + }; + +} +void from_json(const json& j, RegionEventEntry& p){ + +} + +ThreadStore getThreadStoreOfCaller(){ + ThreadStore thread_store; + thread_store.process_id_ = getpid(); + thread_store.thread_id_ = gettid(); + return thread_store; +} + + +DetectionStrategy::DetectionStrategy():mpi_helper_{}{ + parallelism_descriptor_={ + .mpi_descriptor_ = MPIDescriptor::Aware, + .thread_descriptor_ = ThreadDescriptor::Supported + }; + + +} + +void DetectionStrategy::Init() noexcept { + +} + +void DetectionStrategy::RegionStart( + const ProperlyNestedRegionInformation ®ion) noexcept { + RegionEventEntry start_entry; + start_entry.region_name_=std::string(region.name); + start_entry.stack_ = region.stack_; + start_entry.thread_ = getThreadStoreOfCaller(); + + std::lock_guard guard(starts_mutex_); + starts_.push_back(start_entry); +} + +void DetectionStrategy::RegionStopLast( + const ProperlyNestedRegionInformation ®ion) noexcept { + + // first create an entry + RegionEventEntry stop_entry; + stop_entry.region_name_ = std::string(region.name); + stop_entry.stack_ = region.stack_; + stop_entry.thread_ = getThreadStoreOfCaller(); + + std::lock_guard guard(ends_mutex_); + ends_.push_back(stop_entry); + + // two error checks are following + + if(region.stack_.empty()){ + std::cout << "neSmiK WARNING: The stack is already empty, so no more regions to close, but it tried to close " << region.name << std::endl; + has_errors_ = true; + return; + } + // now check if we actually pop the right name + if(region.name.compare(region.stack_.top())!= 0){ + std::cout << "neSmiK WARNING: The stack says the next region to close is " << region.stack_.top() << " but tried closing " << region.name<< std::endl; + has_errors_ = true; + return; + } + +} + + + + +void DetectionStrategy::Finalize() noexcept { + + // print summary report + if(has_errors_ && mpi_helper_.IsRankNumber(0)){ + std::cout << "###################################################################################################" << std::endl; + std::cout << "# neSmiK detected that the nesting of regions implemented by the Application is NotProperlyNested #" << std::endl; + std::cout << "# Please be aware, that using backends that require ProperlyNested regions is not supported #" << std::endl; + std::cout << "# If you think this is a bug, as you expected them to be ProperlyNested, #" << std::endl; + std::cout << "# please look at the docs on instructions on how to proceed #"<< std::endl; + std::cout << "###################################################################################################" << std::endl; + } + + + + for(const auto& start : starts_){ + nlohmann::json j = start; + std::cout << "Started " << start.region_name_ << " with pid: " << start.thread_.process_id_ << " and tid: " << start.thread_.thread_id_ << "and the size of stack looked like " << start.stack_.size() << std::endl; + } + + + +} diff --git a/src/backends/detection/detection.hpp b/src/backends/detection/detection.hpp new file mode 100644 index 0000000..53c74d5 --- /dev/null +++ b/src/backends/detection/detection.hpp @@ -0,0 +1,57 @@ +#ifndef NESMIK_DETECTION_H +#define NESMIK_DETECTION_H + +#include +#include + +#include +#include +#include +#include +#include + +#include + +// for convenience +using json = nlohmann::json; + + +struct ThreadStore{ + pid_t thread_id_; + pid_t process_id_; +}; + + +struct RegionEventEntry{ + ThreadStore thread_; + std::string region_name_; + std::stack stack_; + double timestamp; +}; + + + +void to_json(json& j, const RegionEventEntry& p); +void from_json(const json& j, RegionEventEntry& p); + +class DetectionStrategy : public ProperlyNestedAnnotationStrategy { + +private: + MPIHelper mpi_helper_; + std::vector starts_; + std::vector ends_; + + std::mutex starts_mutex_; + std::mutex ends_mutex_; + + bool has_errors_ = false; + +public: + DetectionStrategy(); + inline static const std::string name = "Detection"; + virtual void RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept override; + virtual void RegionStopLast(const ProperlyNestedRegionInformation ®ion) noexcept override; + virtual void Init() noexcept; + virtual void Finalize() noexcept; +}; +#endif // NESMIK_DETECTION_H diff --git a/src/delegator.cpp b/src/delegator.cpp index f389174..795148c 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -5,6 +5,7 @@ #include #include "backends/default/default.hpp" +#include "backends/detection/detection.hpp" #include #include #include @@ -19,8 +20,7 @@ #endif void Delegator::InitDetectionBackend(const std::string_view backend) { - std::cout << "Not supported currnently, come back later pls" << std::endl; - exit(1); + pn_annotation_strategy_ = std::make_unique(); } void Delegator::InitNonProperlyNestedBackends(const std::string_view backend) { @@ -112,9 +112,11 @@ void Delegator::Init(std::string_view nesting_mode, std::string_view backend) { } switch (nesting_mode_) { - case NestingMode::Detecion: + case NestingMode::NotProperlyNested: return npn_annotation_strategy_->Init(); + break; + case NestingMode::Detecion: case NestingMode::ProperlyNested: return pn_annotation_strategy_->Init(); break; @@ -123,22 +125,29 @@ void Delegator::Init(std::string_view nesting_mode, std::string_view backend) { // should be thread safe to call? void Delegator::RegionStart(std::string_view name) { + + switch (nesting_mode_) { - case NestingMode::Detecion: case NestingMode::NotProperlyNested: return npn_annotation_strategy_->RegionStart({name}); + case NestingMode::Detecion: case NestingMode::ProperlyNested: - return pn_annotation_strategy_->RegionStart({name}); + // First push to stack + name_stack_.push(std::string(name)); + return pn_annotation_strategy_->RegionStart({name, name_stack_}); break; } } void Delegator::RegionStop(std::string_view name) { switch (nesting_mode_) { - case NestingMode::Detecion: + case NestingMode::NotProperlyNested: return npn_annotation_strategy_->RegionStop({name}); + break; + case NestingMode::Detecion: case NestingMode::ProperlyNested: - return pn_annotation_strategy_->RegionStopLast({name}); + pn_annotation_strategy_->RegionStopLast({name,name_stack_}); + if(!name_stack_.empty()) {name_stack_.pop();} break; } }; @@ -146,9 +155,11 @@ void Delegator::RegionStop(std::string_view name) { void Delegator::Finalize() { switch (nesting_mode_) { - case NestingMode::Detecion: + case NestingMode::NotProperlyNested: return npn_annotation_strategy_->Finalize(); + break; + case NestingMode::Detecion: case NestingMode::ProperlyNested: return pn_annotation_strategy_->Finalize(); break; diff --git a/src/delegator.hpp b/src/delegator.hpp index 1e67cf0..059d986 100644 --- a/src/delegator.hpp +++ b/src/delegator.hpp @@ -15,6 +15,9 @@ private: pn_annotation_strategy_; inline static std::unique_ptr npn_annotation_strategy_; + + inline static thread_local std::stack name_stack_; + inline static NestingMode nesting_mode_ = NestingMode::Detecion; public: diff --git a/src/parallelism_helper.cpp b/src/parallelism_helper.cpp index 88f5e13..52f4378 100644 --- a/src/parallelism_helper.cpp +++ b/src/parallelism_helper.cpp @@ -19,6 +19,10 @@ bool MPIHelper::IsRankNumber(int asked_rank) const { return asked_rank== mpi_comm_rank; } +int MPIHelper::getRankNumber() const{ + return mpi_comm_rank; +} + MPIHelper::MPIHelper(){ // First check if MPI is initialized int is_initialized; @@ -49,6 +53,11 @@ bool MPIHelper::IsRankNumber(int asked_rank) const { return asked_rank==0; } + +int MPIHelper::getRankNumber() const{ + return mpi_comm_rank; +} + MPIHelper::MPIHelper(){} diff --git a/src/parallelism_helper.hpp b/src/parallelism_helper.hpp index a0edf1f..5aebb05 100644 --- a/src/parallelism_helper.hpp +++ b/src/parallelism_helper.hpp @@ -21,6 +21,8 @@ class MPIHelper{ bool IsUsingMPI() const; // Checks if rank is a certain one, and 0 if MPI is not active bool IsRankNumber(int asked_rank) const; + + int getRankNumber() const; }; diff --git a/src/strategies.hpp b/src/strategies.hpp index 6b50110..dbebd8b 100644 --- a/src/strategies.hpp +++ b/src/strategies.hpp @@ -4,6 +4,7 @@ #include #include #include +#include /* @@ -35,6 +36,7 @@ struct ParallelismDescriptor{ struct ProperlyNestedRegionInformation { std::string_view name; + const std::stack &stack_; }; struct NotProperlyNestedRegionInformation { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 32c9d06..2c97976 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,8 +16,9 @@ target_include_directories(TestCppDLB add_test(NAME TestCppDLB COMMAND TestCppDLB) +find_package(OpenMP REQUIRED) add_executable(TestCppTalpTree cpp/TestCppTalpTree.cpp) -target_link_libraries(TestCppTalpTree nesmik::nesmik) +target_link_libraries(TestCppTalpTree nesmik::nesmik OpenMP::OpenMP_CXX) target_include_directories(TestCppTalpTree PRIVATE ${NESMIK_PUBLIC_HEADERS}) diff --git a/tests/cpp/TestCppTalpTree.cpp b/tests/cpp/TestCppTalpTree.cpp index bfe90d2..68a04a8 100644 --- a/tests/cpp/TestCppTalpTree.cpp +++ b/tests/cpp/TestCppTalpTree.cpp @@ -1,17 +1,22 @@ #include "nesmik/nesmik.hpp" - +#include +#include int main() { - nesmik::init("ProperlyNested","TALP-Tree"); + nesmik::init("?","Detection"); nesmik::region_start("Top"); nesmik::region_start("child-1"); + #pragma omp parallel + { 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.1"); nesmik::region_stop("child-2"); nesmik::region_stop("Top"); nesmik::finalize(); -- GitLab From 16ce60c5423ecfc87269bcf04e8fb50761da7515 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Mon, 17 Jun 2024 14:49:30 +0200 Subject: [PATCH 2/7] make PMPI Calls --- src/backends/detection/detection.cpp | 119 +++++++++++++++++++++++---- src/backends/detection/detection.hpp | 2 +- 2 files changed, 103 insertions(+), 18 deletions(-) diff --git a/src/backends/detection/detection.cpp b/src/backends/detection/detection.cpp index e9dbbbd..2e484bd 100644 --- a/src/backends/detection/detection.cpp +++ b/src/backends/detection/detection.cpp @@ -5,25 +5,33 @@ #include +#include + +#ifdef WITH_MPI + #include +#endif + // for convenience using json = nlohmann::json; void to_json(json& j, const RegionEventEntry& p){ - // first convert to the stack to std::vector in order - + + // first convert to the stack to std::vector in order std::stack local_stack = p.stack_; // copy stack std::vector stack_vec(local_stack.size()); - std:: + for(std::size_t i = 0; i< local_stack.size(); i++){ + stack_vec.at(i) = local_stack.top(); + local_stack.pop(); + } - for(std::size_t i = p.stack_.size(); i >=0 // we use camelCase as suggested in https://google.github.io/styleguide/jsoncstyleguide.xml?showone=Property_Name_Format#Property_Name_Format j = json{ {"threadId", p.thread_.thread_id_}, {"processId", p.thread_.process_id_}, {"regionName", p.region_name_}, - {"stack", p.timestamp}, + {"stack", stack_vec}, {"timestamp", p.timestamp} }; @@ -97,23 +105,100 @@ void DetectionStrategy::RegionStopLast( void DetectionStrategy::Finalize() noexcept { - // print summary report - if(has_errors_ && mpi_helper_.IsRankNumber(0)){ - std::cout << "###################################################################################################" << std::endl; - std::cout << "# neSmiK detected that the nesting of regions implemented by the Application is NotProperlyNested #" << std::endl; - std::cout << "# Please be aware, that using backends that require ProperlyNested regions is not supported #" << std::endl; - std::cout << "# If you think this is a bug, as you expected them to be ProperlyNested, #" << std::endl; - std::cout << "# please look at the docs on instructions on how to proceed #"<< std::endl; - std::cout << "###################################################################################################" << std::endl; - } + + int has_errors = static_cast(has_errors_); + int has_been_called_from_threads = 0; + int has_been_called_from_threads_glob = 0; + + pid_t first_thread_id = 0; + + for(const auto& start : starts_){ + if(first_thread_id == 0){ + first_thread_id = start.thread_.thread_id_; + } + if(start.thread_.thread_id_ != first_thread_id){ + has_been_called_from_threads = 1; + break; + } + } + for(const auto& end : ends_){ + if(first_thread_id == 0){ + first_thread_id = end.thread_.thread_id_; + } + if(end.thread_.thread_id_ != first_thread_id){ + has_been_called_from_threads = 1; + break; + } + } + #ifdef WITH_MPI + + PMPI_Reduce(&has_errors_,&has_errors,1, MPI_INT, MPI_SUM,0,MPI_COMM_WORLD); // sending bool as if it was an int + PMPI_Reduce(&has_been_called_from_threads,&has_been_called_from_threads_glob,1, MPI_INT, MPI_SUM,0,MPI_COMM_WORLD); + + #endif - for(const auto& start : starts_){ - nlohmann::json j = start; - std::cout << "Started " << start.region_name_ << " with pid: " << start.thread_.process_id_ << " and tid: " << start.thread_.thread_id_ << "and the size of stack looked like " << start.stack_.size() << std::endl; + + // print summary report + if(mpi_helper_.IsRankNumber(0)){ + if(mpi_helper_.IsUsingMPI()){ + std::cout << "############################### Using MPI: Yes ##################################################" << std::endl; + } + std::cout << "############################### Nesting Summary #################################################" << std::endl; + std::cout << "# #" << std::endl; + if(has_errors > 0 ){ + std::cout << "# neSmiK detected that the nesting of regions implemented by the application is NotProperlyNested #" << std::endl; + std::cout << "# Please be aware, that using backends that require ProperlyNested regions is not supported #" << std::endl; + std::cout << "# If you think this is a bug, as you expected them to be ProperlyNested, #" << std::endl; + std::cout << "# please look at the docs on instructions on how to proceed. #"<< std::endl; + std::cout << "# #" << std::endl; + if(mpi_helper_.IsUsingMPI()){ + std::cout << "# Nesmik also produced files called nesmik_detection_ends_.json and #" << std::endl; + std::cout << "# nesmik_detection_starts_.json with a json event trace you can use to debug. #" << std::endl; + }else{ + std::cout << "# Nesmik also produced files called nesmik_detection_ends.json and #" << std::endl; + std::cout << "# nesmik_detection_starts.json with a json event trace you can use to debug. #" << std::endl; + } + + }else{ + std::cout << "# neSmiK detected that the nesting of regions implemented by the application is ProperlyNested #" << std::endl; + std::cout << "# That is great news! #" << std::endl; + std::cout << "# #" << std::endl; + } + std::cout << "################################ Thread Summary #################################################" << std::endl; + std::cout << "# #" << std::endl; + if(has_been_called_from_threads_glob > 0 ){ + std::cout << "# neSmiks annontation API has been called from more than one thread. #"<< std::endl; + std::cout << "# Note, that youre backend needs to have multithreading support to generate proper results #"<< std::endl; + std::cout << "# #" << std::endl; + }else{ + std::cout << "# neSmiks annontation API has been NOT called from more than one thread. #"<< std::endl; + std::cout << "# #" << std::endl; + } + std::cout << "###################################################################################################" << std::endl; } + nlohmann::json j_starts = starts_; + nlohmann::json j_end = ends_; + + std::string filenname_starts = "nesmik_detection_starts"; + std::string filenname_ends = "nesmik_detection_ends"; + if(mpi_helper_.IsUsingMPI()){ + // prepend MPI rank to the filename + filenname_starts += "_" + std::to_string(mpi_helper_.getRankNumber()); + filenname_ends += "_" + std::to_string(mpi_helper_.getRankNumber()); + } + + std::ofstream file_starts(filenname_starts +".json"); + std::ofstream file_ends(filenname_ends +".json"); + + file_starts << j_starts; + file_ends << j_end; + + + + } diff --git a/src/backends/detection/detection.hpp b/src/backends/detection/detection.hpp index 53c74d5..d302f07 100644 --- a/src/backends/detection/detection.hpp +++ b/src/backends/detection/detection.hpp @@ -25,7 +25,7 @@ struct ThreadStore{ struct RegionEventEntry{ ThreadStore thread_; std::string region_name_; - std::stack stack_; + std::stack stack_; double timestamp; }; -- GitLab From 590a8f803794b8e9a048b6d1809ddde2e750bf37 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Mon, 17 Jun 2024 15:14:31 +0200 Subject: [PATCH 3/7] reset to master --- tests/CMakeLists.txt | 3 +-- tests/cpp/TestCppTalpTree.cpp | 9 ++------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2c97976..32c9d06 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,9 +16,8 @@ target_include_directories(TestCppDLB add_test(NAME TestCppDLB COMMAND TestCppDLB) -find_package(OpenMP REQUIRED) add_executable(TestCppTalpTree cpp/TestCppTalpTree.cpp) -target_link_libraries(TestCppTalpTree nesmik::nesmik OpenMP::OpenMP_CXX) +target_link_libraries(TestCppTalpTree nesmik::nesmik) target_include_directories(TestCppTalpTree PRIVATE ${NESMIK_PUBLIC_HEADERS}) diff --git a/tests/cpp/TestCppTalpTree.cpp b/tests/cpp/TestCppTalpTree.cpp index 68a04a8..bfe90d2 100644 --- a/tests/cpp/TestCppTalpTree.cpp +++ b/tests/cpp/TestCppTalpTree.cpp @@ -1,22 +1,17 @@ #include "nesmik/nesmik.hpp" -#include -#include + int main() { - nesmik::init("?","Detection"); + nesmik::init("ProperlyNested","TALP-Tree"); nesmik::region_start("Top"); nesmik::region_start("child-1"); - #pragma omp parallel - { 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.1"); nesmik::region_stop("child-2"); nesmik::region_stop("Top"); nesmik::finalize(); -- GitLab From ae41d9d85219aabc87eab34b92603d6d1b1579a3 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Mon, 17 Jun 2024 15:14:49 +0200 Subject: [PATCH 4/7] make more resilient --- src/backends/detection/detection.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/backends/detection/detection.cpp b/src/backends/detection/detection.cpp index 2e484bd..4e53841 100644 --- a/src/backends/detection/detection.cpp +++ b/src/backends/detection/detection.cpp @@ -108,7 +108,7 @@ void DetectionStrategy::Finalize() noexcept { int has_errors = static_cast(has_errors_); int has_been_called_from_threads = 0; - int has_been_called_from_threads_glob = 0; + pid_t first_thread_id = 0; @@ -133,10 +133,15 @@ void DetectionStrategy::Finalize() noexcept { } #ifdef WITH_MPI - - PMPI_Reduce(&has_errors_,&has_errors,1, MPI_INT, MPI_SUM,0,MPI_COMM_WORLD); // sending bool as if it was an int - PMPI_Reduce(&has_been_called_from_threads,&has_been_called_from_threads_glob,1, MPI_INT, MPI_SUM,0,MPI_COMM_WORLD); - + if(mpi_helper_.IsRankNumber(0)){ + PMPI_Reduce(MPI_IN_PLACE,&has_been_called_from_threads,1, MPI_INT, MPI_SUM,0,MPI_COMM_WORLD); + PMPI_Reduce(MPI_IN_PLACE,&has_errors,1, MPI_INT, MPI_SUM,0,MPI_COMM_WORLD); + } + else{ + int localUnused; + PMPI_Reduce(&has_been_called_from_threads,&localUnused,1, MPI_INT, MPI_SUM,0,MPI_COMM_WORLD); + PMPI_Reduce(&has_errors,&localUnused,1, MPI_INT, MPI_SUM,0,MPI_COMM_WORLD); + } #endif @@ -168,7 +173,7 @@ void DetectionStrategy::Finalize() noexcept { } std::cout << "################################ Thread Summary #################################################" << std::endl; std::cout << "# #" << std::endl; - if(has_been_called_from_threads_glob > 0 ){ + if(has_been_called_from_threads > 0 ){ std::cout << "# neSmiks annontation API has been called from more than one thread. #"<< std::endl; std::cout << "# Note, that youre backend needs to have multithreading support to generate proper results #"<< std::endl; std::cout << "# #" << std::endl; -- GitLab From e46981e5fb8ab24acd47e2ecfb6bd449e7827acb Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Mon, 17 Jun 2024 16:09:19 +0200 Subject: [PATCH 5/7] added timestamp --- src/backends/detection/detection.cpp | 19 +++++++++++++++++++ src/backends/detection/detection.hpp | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/backends/detection/detection.cpp b/src/backends/detection/detection.cpp index 4e53841..d9444ed 100644 --- a/src/backends/detection/detection.cpp +++ b/src/backends/detection/detection.cpp @@ -5,6 +5,8 @@ #include +#include + #include #ifdef WITH_MPI @@ -47,6 +49,19 @@ ThreadStore getThreadStoreOfCaller(){ return thread_store; } +double getTimeStamp(){ + #ifdef WITH_MPI + return MPI_Wtime(); + #else + using clock = std::chrono::system_clock; + auto now = clock::now(); + double seconds = std::chrono::duration_cast>(now.time_since_epoch()).count(); + return seconds; + + #endif + + } + DetectionStrategy::DetectionStrategy():mpi_helper_{}{ parallelism_descriptor_={ @@ -64,6 +79,7 @@ void DetectionStrategy::Init() noexcept { void DetectionStrategy::RegionStart( const ProperlyNestedRegionInformation ®ion) noexcept { RegionEventEntry start_entry; + start_entry.timestamp= getTimeStamp(); start_entry.region_name_=std::string(region.name); start_entry.stack_ = region.stack_; start_entry.thread_ = getThreadStoreOfCaller(); @@ -77,9 +93,12 @@ void DetectionStrategy::RegionStopLast( // first create an entry RegionEventEntry stop_entry; + stop_entry.timestamp= getTimeStamp(); stop_entry.region_name_ = std::string(region.name); + stop_entry.stack_ = region.stack_; stop_entry.thread_ = getThreadStoreOfCaller(); + std::lock_guard guard(ends_mutex_); ends_.push_back(stop_entry); diff --git a/src/backends/detection/detection.hpp b/src/backends/detection/detection.hpp index d302f07..1660b38 100644 --- a/src/backends/detection/detection.hpp +++ b/src/backends/detection/detection.hpp @@ -34,6 +34,8 @@ struct RegionEventEntry{ void to_json(json& j, const RegionEventEntry& p); void from_json(const json& j, RegionEventEntry& p); + + class DetectionStrategy : public ProperlyNestedAnnotationStrategy { private: -- GitLab From 7b1c6de5d2ba9fb1a73b67592591bf25c333cd53 Mon Sep 17 00:00:00 2001 From: VALENTIN SEITZ Date: Mon, 17 Jun 2024 17:24:55 +0200 Subject: [PATCH 6/7] Apply small typos --- src/backends/detection/detection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backends/detection/detection.cpp b/src/backends/detection/detection.cpp index d9444ed..4217fbc 100644 --- a/src/backends/detection/detection.cpp +++ b/src/backends/detection/detection.cpp @@ -194,10 +194,10 @@ void DetectionStrategy::Finalize() noexcept { std::cout << "# #" << std::endl; if(has_been_called_from_threads > 0 ){ std::cout << "# neSmiks annontation API has been called from more than one thread. #"<< std::endl; - std::cout << "# Note, that youre backend needs to have multithreading support to generate proper results #"<< std::endl; + std::cout << "# Note, that your backend needs to have multithreading support to generate proper results #"<< std::endl; std::cout << "# #" << std::endl; }else{ - std::cout << "# neSmiks annontation API has been NOT called from more than one thread. #"<< std::endl; + std::cout << "# neSmiks annotation API has been NOT called from more than one thread. #"<< std::endl; std::cout << "# #" << std::endl; } std::cout << "###################################################################################################" << std::endl; -- GitLab From f48a3e8e66704a5afe636009677571b67b7f4f20 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Mon, 17 Jun 2024 17:26:58 +0200 Subject: [PATCH 7/7] fix the typo --- src/delegator.cpp | 14 +++++++------- src/delegator.hpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/delegator.cpp b/src/delegator.cpp index 795148c..910ae94 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -68,7 +68,7 @@ void Delegator::Init(std::string_view nesting_mode, std::string_view backend) { // detect nesting mode requested by the user if (nesting_mode.compare("?") == 0) { - nesting_mode_ = NestingMode::Detecion; + nesting_mode_ = NestingMode::Detection; } else if (nesting_mode.compare("ProperlyNested") == 0) { nesting_mode_ = NestingMode::ProperlyNested; } else if (nesting_mode.compare("NotProperlyNested") == 0) { @@ -77,7 +77,7 @@ void Delegator::Init(std::string_view nesting_mode, std::string_view backend) { // Some debug output switch (nesting_mode_) { - case NestingMode::Detecion: + case NestingMode::Detection: std::cout << "Selecting nesting mode to: " << "detecting nesting behavior" << std::endl; break; @@ -93,7 +93,7 @@ void Delegator::Init(std::string_view nesting_mode, std::string_view backend) { // next choose backend switch (nesting_mode_) { - case NestingMode::Detecion: + case NestingMode::Detection: InitDetectionBackend(backend); break; case NestingMode::ProperlyNested: @@ -116,7 +116,7 @@ void Delegator::Init(std::string_view nesting_mode, std::string_view backend) { case NestingMode::NotProperlyNested: return npn_annotation_strategy_->Init(); break; - case NestingMode::Detecion: + case NestingMode::Detection: case NestingMode::ProperlyNested: return pn_annotation_strategy_->Init(); break; @@ -130,7 +130,7 @@ void Delegator::RegionStart(std::string_view name) { switch (nesting_mode_) { case NestingMode::NotProperlyNested: return npn_annotation_strategy_->RegionStart({name}); - case NestingMode::Detecion: + case NestingMode::Detection: case NestingMode::ProperlyNested: // First push to stack name_stack_.push(std::string(name)); @@ -144,7 +144,7 @@ void Delegator::RegionStop(std::string_view name) { case NestingMode::NotProperlyNested: return npn_annotation_strategy_->RegionStop({name}); break; - case NestingMode::Detecion: + case NestingMode::Detection: case NestingMode::ProperlyNested: pn_annotation_strategy_->RegionStopLast({name,name_stack_}); if(!name_stack_.empty()) {name_stack_.pop();} @@ -159,7 +159,7 @@ void Delegator::Finalize() { case NestingMode::NotProperlyNested: return npn_annotation_strategy_->Finalize(); break; - case NestingMode::Detecion: + case NestingMode::Detection: case NestingMode::ProperlyNested: return pn_annotation_strategy_->Finalize(); break; diff --git a/src/delegator.hpp b/src/delegator.hpp index 059d986..b942783 100644 --- a/src/delegator.hpp +++ b/src/delegator.hpp @@ -7,7 +7,7 @@ #include -enum class NestingMode { Detecion, ProperlyNested, NotProperlyNested }; +enum class NestingMode { Detection, ProperlyNested, NotProperlyNested }; class Delegator { private: @@ -18,7 +18,7 @@ private: inline static thread_local std::stack name_stack_; - inline static NestingMode nesting_mode_ = NestingMode::Detecion; + inline static NestingMode nesting_mode_ = NestingMode::Detection; public: static void Init(std::string_view nesting_mode, std::string_view backend); -- GitLab