From 89d487d785c99457fb0649b0c4be1c65286e386a Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Thu, 6 Jun 2024 21:07:16 +0200 Subject: [PATCH 1/5] Add the DLB TALP Tree backend --- src/backends/CMakeLists.txt | 2 +- src/backends/dlb/CMakeLists.txt | 2 + src/backends/dlb/dlb/CMakeLists.txt | 1 + src/backends/dlb/{ => dlb}/dlb.cpp | 0 src/backends/dlb/{ => dlb}/dlb.hpp | 4 + src/backends/dlb/dlb_talp_tree/CMakeLists.txt | 1 + .../dlb/dlb_talp_tree/dlb_talp_tree.cpp | 161 ++++++++++++++++++ .../dlb/dlb_talp_tree/dlb_talp_tree.hpp | 34 ++++ src/delegator.cpp | 6 +- 9 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 src/backends/dlb/dlb/CMakeLists.txt rename src/backends/dlb/{ => dlb}/dlb.cpp (100%) rename src/backends/dlb/{ => dlb}/dlb.hpp (86%) create mode 100644 src/backends/dlb/dlb_talp_tree/CMakeLists.txt create mode 100644 src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp create mode 100644 src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp diff --git a/src/backends/CMakeLists.txt b/src/backends/CMakeLists.txt index c18ed4e..43fa57b 100644 --- a/src/backends/CMakeLists.txt +++ b/src/backends/CMakeLists.txt @@ -6,4 +6,4 @@ endif() if(ENABLE_EXTRAE) add_subdirectory(extrae) -endif() \ No newline at end of file +endif() diff --git a/src/backends/dlb/CMakeLists.txt b/src/backends/dlb/CMakeLists.txt index 10aa568..88e76cf 100644 --- a/src/backends/dlb/CMakeLists.txt +++ b/src/backends/dlb/CMakeLists.txt @@ -6,4 +6,6 @@ target_include_directories(nesmik target_link_libraries(nesmik PUBLIC ${DLB_LIBRARIES}) target_compile_definitions(nesmik PRIVATE "ENABLE_DLB") +add_subdirectory(dlb) +add_subdirectory(dlb_talp_tree) endif() diff --git a/src/backends/dlb/dlb/CMakeLists.txt b/src/backends/dlb/dlb/CMakeLists.txt new file mode 100644 index 0000000..525d2b4 --- /dev/null +++ b/src/backends/dlb/dlb/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(sit PRIVATE dlb.cpp) diff --git a/src/backends/dlb/dlb.cpp b/src/backends/dlb/dlb/dlb.cpp similarity index 100% rename from src/backends/dlb/dlb.cpp rename to src/backends/dlb/dlb/dlb.cpp diff --git a/src/backends/dlb/dlb.hpp b/src/backends/dlb/dlb/dlb.hpp similarity index 86% rename from src/backends/dlb/dlb.hpp rename to src/backends/dlb/dlb/dlb.hpp index 5c843e4..ebdeb6c 100644 --- a/src/backends/dlb/dlb.hpp +++ b/src/backends/dlb/dlb/dlb.hpp @@ -1,3 +1,6 @@ +#ifndef SIT_DLB_H +#define SIT_DLB_H + #include class DLBTalpStrategy : public PNProfilingStrategy { @@ -9,3 +12,4 @@ public: virtual void init() noexcept; virtual void finalize() noexcept; }; +#endif // SIT_DLB_H diff --git a/src/backends/dlb/dlb_talp_tree/CMakeLists.txt b/src/backends/dlb/dlb_talp_tree/CMakeLists.txt new file mode 100644 index 0000000..3f699a4 --- /dev/null +++ b/src/backends/dlb/dlb_talp_tree/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(sit PRIVATE dlb_talp_tree.cpp) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp new file mode 100644 index 0000000..e2706fc --- /dev/null +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -0,0 +1,161 @@ +#include "dlb_talp_tree.hpp" +#include "dlb.h" +#include "dlb_talp.h" +#include +#include +#include +#include +#include + +void DLBTalpTreeStrategy::region_start( + const SITRegionInformation ®ion) noexcept { + + std::string region_name = std::string(region.name) + std::to_string(this->current_region); + std::size_t region_hash = std::hash{}(region_name); + + if (this->regions.count(region_hash) == 0) { + // Add the new region as a child to the current region + this->regions[this->current_region].childs.push_back(region_hash); + + // Add the new region in the map + this->regions[region_hash] = { + /* .name */ std::string(region.name), + /* .parent */ this->current_region, + /* .childs */ std::vector() + }; + } + + this->current_region = region_hash; + + std::string name = std::to_string(region_hash); + this->talp_profiling_strategy.region_start({name}); +} + +void DLBTalpTreeStrategy::region_stop( + const SITRegionInformation ®ion) noexcept { + + auto current_region = this->regions[this->current_region]; + + if (region.name != current_region.name) { + std::strstream error; + + error << "SIT:: Closing " << region.name << " would make "; + error << current_region.name << "not nested." << std::endl; + + error << "SIT:: Closing" << current_region.name << " instead." << std::endl; + + std::cerr << error.str(); + } + + std::string name = std::to_string(this->current_region); + + this->current_region = current_region.parent; + + this->talp_profiling_strategy.region_stop({name}); +} + +void DLBTalpTreeStrategy::init() noexcept { + + this->current_region = std::hash{}(this->top_region + "0"); + this->regions[this->current_region] = { + .name = this->top_region, + .parent = 0, + .childs = {}, + }; + + this->talp_profiling_strategy.init(); +} + +void DLBTalpTreeStrategy::finalize() noexcept { + + this->talp_profiling_strategy.region_stop({.name = this->top_region}); + + std::size_t max_width = 0; + + // First pass to format the names with the appropiate tree lines and to determine paddings. + { + std::queue regions_queue; + std::size_t top_region = std::hash{}(this->top_region + "0"); + regions_queue.push(top_region); + + std::queue regions_level; + regions_level.push(0); + + std::queue regions_tree_lines; + regions_tree_lines.push(""); + + + while (!regions_queue.empty()) { + int level = regions_level.front(); + regions_level.pop(); std::string tree_lines = regions_tree_lines.front(); + regions_tree_lines.pop(); + auto current_region = this->regions[regions_queue.front()]; + regions_queue.pop(); + + std::string next_tree_lines = " │ "; + if (level > regions_level.front()) { // If I am the last child I don't need to continue the line + next_tree_lines = " "; + } + + for (auto region : current_region.childs) { + regions_queue.push(region); + regions_level.push(level+1); + regions_tree_lines.push(tree_lines + next_tree_lines); + } + + if (level > regions_level.front()) { // If I am the last child I close the line + tree_lines += " └── "; + } else if (level != 0) { // If I am not the first level I continue the line + tree_lines += " ├── "; + } + + current_region.name = tree_lines + current_region.name; + max_width = std::max(max_width, current_region.name.length()); + } + } + + std::queue regions_queue; + std::size_t top_region = std::hash{}(this->top_region); + regions_queue.push(top_region); + + std::strstream region_stream; + + while (!regions_queue.empty()) { + auto current_region = this->regions[regions_queue.front()]; + regions_queue.pop(); + + for (auto region : current_region.childs) { + regions_queue.push(region); + } + + auto handle = DLB_MonitoringRegionRegister(current_region.name.c_str()); + dlb_pop_metrics_t pop_metrics; + int error = DLB_TALP_CollectPOPMetrics(handle, &pop_metrics); + + if (error != DLB_SUCCESS) { + + } + + region_stream << std::setw(max_width+3) << std::left << current_region.name; + region_stream << std::setprecision(2); + region_stream << std::setw(15) << std::right << pop_metrics.elapsed_time/1000000000 << "s"; + region_stream << std::setw(8) << std::right << pop_metrics.parallel_efficiency; + region_stream << std::setw(8) << std::right << pop_metrics.mpi_parallel_efficiency; + region_stream << std::setw(8) << std::right << pop_metrics.mpi_communication_efficiency; + region_stream << std::setw(8) << std::right << pop_metrics.mpi_load_balance; + region_stream << std::setw(8) << std::right << pop_metrics.mpi_load_balance_in; + region_stream << std::setw(8) << std::right << pop_metrics.mpi_load_balance_out; + + region_stream << std::setw(8) << std::right << pop_metrics.omp_parallel_efficiency; + region_stream << std::setw(8) << std::right << pop_metrics.omp_load_balance; + region_stream << std::setw(8) << std::right << pop_metrics.omp_scheduling_efficiency; + region_stream << std::setw(8) << std::right << pop_metrics.omp_serialization_efficiency; + region_stream << std::endl; + + //OMP-SCH OMP-SER OMP-LB + + } + std::cout << region_stream.str(); + + this->talp_profiling_strategy.finalize(); +} diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp new file mode 100644 index 0000000..50d8348 --- /dev/null +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp @@ -0,0 +1,34 @@ +#ifndef SIT_DLB_TALP_TREE_H +#define SIT_DLB_TALP_TREE_H + +#include "../dlb/dlb.hpp" +#include "sit_strategy.hpp" +#include +#include +#include + +struct TalpRegionNode { + std::string name; + std::size_t parent; + std::vector childs; +}; + +class DLBTalpTreeStrategy : public SITProfilingStrategy { + +private: + DLBTalpStrategy talp_profiling_strategy; + + inline static const std::string top_region = "Application"; + std::size_t current_region; + std::map regions; + + +public: + inline static const std::string_view name = "TALP-Tree"; + void region_start(const SITRegionInformation ®ion) noexcept override; + void region_stop(const SITRegionInformation ®ion) noexcept override; + virtual void init() noexcept; + virtual void finalize() noexcept; +}; + +#endif // DLB_TALP_TREE_H diff --git a/src/delegator.cpp b/src/delegator.cpp index 1461ed4..af64e40 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -9,7 +9,8 @@ #include "backends/default/default.hpp" #ifdef ENABLE_DLB -#include "backends/dlb/dlb.hpp" +#include "backends/dlb/dlb/dlb.hpp" +#include "backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp" #endif #ifdef ENABLE_EXTRAE @@ -31,6 +32,9 @@ void Delegator::init(std::string_view backend) { else if (backend.compare(DLBTalpStrategy::name) == 0) { pn_profiling_strategy = std::make_unique(); } + else if (backend.compare(DLBTalpTreeStrategy::name) == 0) { + profiling_strategy = std::make_unique(); + } #endif else { exit(1); // fail non gracefully for now -- GitLab From 714b345e66fe474da436a4ac23a192ef619e663c Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Thu, 6 Jun 2024 21:20:37 +0200 Subject: [PATCH 2/5] Fix DLB test after change to TALP. --- tests/cpp/TestCppDLB.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/cpp/TestCppDLB.cpp b/tests/cpp/TestCppDLB.cpp index ffb3197..3d5b394 100644 --- a/tests/cpp/TestCppDLB.cpp +++ b/tests/cpp/TestCppDLB.cpp @@ -1,8 +1,8 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("DLB"); - nesmik::region_start("Default"); - nesmik::region_stop("Default"); - nesmik::finalize(); -} \ No newline at end of file + sit::init("TALP"); + sit::region_start("Default"); + sit::region_stop("Default"); + sit::finalize(); +} -- GitLab From 832ba7b5bf08d15529dc25d44f96474c9f4385c8 Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Mon, 10 Jun 2024 21:05:27 +0200 Subject: [PATCH 3/5] Semi working version of TALP-Tree backend. It still prints some binary data, which I don't know where it comes from. --- src/backends/dlb/dlb/dlb.cpp | 1 - .../dlb/dlb_talp_tree/dlb_talp_tree.cpp | 168 +++++++++++------- .../dlb/dlb_talp_tree/dlb_talp_tree.hpp | 2 + tests/CMakeLists.txt | 9 +- tests/cpp/TestCppTalpTree.cpp | 18 ++ 5 files changed, 136 insertions(+), 62 deletions(-) create mode 100644 tests/cpp/TestCppTalpTree.cpp diff --git a/src/backends/dlb/dlb/dlb.cpp b/src/backends/dlb/dlb/dlb.cpp index ac577e7..3c8b5d9 100644 --- a/src/backends/dlb/dlb/dlb.cpp +++ b/src/backends/dlb/dlb/dlb.cpp @@ -18,7 +18,6 @@ void DLBTalpStrategy::region_stop( } void DLBTalpStrategy::init() noexcept { - DLB_Init(0, NULL, "--talp"); std::cout << "nesmik::" << name << " init()" << std::endl; } diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index e2706fc..5153af8 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -4,13 +4,20 @@ #include #include #include -#include +#include +#include #include void DLBTalpTreeStrategy::region_start( const SITRegionInformation ®ion) noexcept { - std::string region_name = std::string(region.name) + std::to_string(this->current_region); + // Construct the opening region hash by joining the name of the region with + // the current region (i.e. the parent) hash. + std::string region_name = std::string(region.name) + std::to_string((unsigned int) this->current_region); + if (region.name.compare(this->top_region) == 0) { + region_name = this->top_region; + } + std::size_t region_hash = std::hash{}(region_name); if (this->regions.count(region_hash) == 0) { @@ -19,15 +26,16 @@ void DLBTalpTreeStrategy::region_start( // Add the new region in the map this->regions[region_hash] = { - /* .name */ std::string(region.name), - /* .parent */ this->current_region, - /* .childs */ std::vector() + /* .name */ std::string(region.name), + /* .tree_lines */ "", + /* .parent */ this->current_region, + /* .childs */ std::vector() }; } this->current_region = region_hash; - std::string name = std::to_string(region_hash); + std::string name = std::to_string((unsigned int) region_hash); this->talp_profiling_strategy.region_start({name}); } @@ -36,18 +44,21 @@ void DLBTalpTreeStrategy::region_stop( auto current_region = this->regions[this->current_region]; - if (region.name != current_region.name) { + if (region.name.compare(current_region.name) != 0) { std::strstream error; error << "SIT:: Closing " << region.name << " would make "; error << current_region.name << "not nested." << std::endl; - error << "SIT:: Closing" << current_region.name << " instead." << std::endl; + error << "SIT:: Closing " << current_region.name << " instead." << std::endl; std::cerr << error.str(); } - std::string name = std::to_string(this->current_region); + std::string name = std::to_string((unsigned int)this->current_region); + if (current_region.name.compare(this->top_region) == 0) { + name = this->top_region; + } this->current_region = current_region.parent; @@ -56,11 +67,12 @@ void DLBTalpTreeStrategy::region_stop( void DLBTalpTreeStrategy::init() noexcept { - this->current_region = std::hash{}(this->top_region + "0"); + this->current_region = std::hash{}(this->top_region); this->regions[this->current_region] = { - .name = this->top_region, - .parent = 0, - .childs = {}, + /* .name */ this->top_region, + /* .tree_lines */ "", + /* .parent */ 0, + /* .childs */ {}, }; this->talp_profiling_strategy.init(); @@ -74,61 +86,75 @@ void DLBTalpTreeStrategy::finalize() noexcept { // First pass to format the names with the appropiate tree lines and to determine paddings. { - std::queue regions_queue; - std::size_t top_region = std::hash{}(this->top_region + "0"); - regions_queue.push(top_region); + std::size_t top_region = std::hash{}(this->top_region); + + std::stack regions_stack; + regions_stack.push(top_region); - std::queue regions_level; + std::stack regions_level; regions_level.push(0); - std::queue regions_tree_lines; + std::stack regions_tree_lines; regions_tree_lines.push(""); + while (!regions_stack.empty()) { + auto ¤t_region = this->regions[regions_stack.top()]; + //TalpRegionNode ¤t_region = this->regions[regions_stack.top()]; + int level = regions_level.top(); + std::string tree_lines = regions_tree_lines.top(); - while (!regions_queue.empty()) { - int level = regions_level.front(); - regions_level.pop(); std::string tree_lines = regions_tree_lines.front(); + regions_stack.pop(); + regions_level.pop(); regions_tree_lines.pop(); - auto current_region = this->regions[regions_queue.front()]; - regions_queue.pop(); - std::string next_tree_lines = " │ "; - if (level > regions_level.front()) { // If I am the last child I don't need to continue the line - next_tree_lines = " "; - } + // I am the last child either if the stack is empty or if the level of the following element + // in the stack is lower than mine. + bool last_child = regions_level.empty() || regions_level.top() < level; + + std::string next_tree_lines = " │ "; // By default I get the continuation line. + if (level == 0) next_tree_lines = ""; // If I am the root region I don't need line. + else if (last_child) next_tree_lines = " "; // If I am the last child I add space. for (auto region : current_region.childs) { - regions_queue.push(region); + regions_stack.push(region); regions_level.push(level+1); regions_tree_lines.push(tree_lines + next_tree_lines); } - if (level > regions_level.front()) { // If I am the last child I close the line - tree_lines += " └── "; - } else if (level != 0) { // If I am not the first level I continue the line - tree_lines += " ├── "; - } + if (level == 0) tree_lines += ""; // If I am the root I don't have lines + else if (last_child) tree_lines += " └─ "; // If I am the last child I close the line + else tree_lines += " ├─ "; // Otherwise i continue the line. - current_region.name = tree_lines + current_region.name; - max_width = std::max(max_width, current_region.name.length()); + current_region.tree_lines = tree_lines; + max_width = std::max(max_width, current_region.name.length() + + current_region.tree_lines.length()); } } - std::queue regions_queue; std::size_t top_region = std::hash{}(this->top_region); - regions_queue.push(top_region); + + std::stack regions_stack; + regions_stack.push(top_region); - std::strstream region_stream; + std::strstream region_stream_stdout; + std::strstream region_stream_csv; - while (!regions_queue.empty()) { - auto current_region = this->regions[regions_queue.front()]; - regions_queue.pop(); + while (!regions_stack.empty()) { + std::size_t current_region_hash = regions_stack.top(); + auto current_region = this->regions[current_region_hash]; + regions_stack.pop(); for (auto region : current_region.childs) { - regions_queue.push(region); + regions_stack.push(region); + } + + std::string name = std::to_string((unsigned int)current_region_hash); + if (current_region.name.compare(this->top_region) == 0) { + name = this->top_region; } - auto handle = DLB_MonitoringRegionRegister(current_region.name.c_str()); + auto handle = DLB_MonitoringRegionRegister(name.c_str()); + dlb_pop_metrics_t pop_metrics; int error = DLB_TALP_CollectPOPMetrics(handle, &pop_metrics); @@ -136,26 +162,48 @@ void DLBTalpTreeStrategy::finalize() noexcept { } - region_stream << std::setw(max_width+3) << std::left << current_region.name; - region_stream << std::setprecision(2); - region_stream << std::setw(15) << std::right << pop_metrics.elapsed_time/1000000000 << "s"; - region_stream << std::setw(8) << std::right << pop_metrics.parallel_efficiency; - region_stream << std::setw(8) << std::right << pop_metrics.mpi_parallel_efficiency; - region_stream << std::setw(8) << std::right << pop_metrics.mpi_communication_efficiency; - region_stream << std::setw(8) << std::right << pop_metrics.mpi_load_balance; - region_stream << std::setw(8) << std::right << pop_metrics.mpi_load_balance_in; - region_stream << std::setw(8) << std::right << pop_metrics.mpi_load_balance_out; + std::string name_with_tree_lines = current_region.tree_lines + current_region.name; + + region_stream_stdout << std::setw(max_width+3) << std::left << name_with_tree_lines; + region_stream_stdout << std::fixed << std::setprecision(2); + region_stream_stdout << std::setw(15) << std::right << 100 * pop_metrics.elapsed_time/1000000000 << "s"; + region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.parallel_efficiency; + region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.mpi_parallel_efficiency; + region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.mpi_communication_efficiency; + region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.mpi_load_balance; + region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.mpi_load_balance_in; + region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.mpi_load_balance_out; + + region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.omp_parallel_efficiency; + region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.omp_load_balance; + region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.omp_scheduling_efficiency; + region_stream_stdout << std::setw(8) << std::right << 100 * pop_metrics.omp_serialization_efficiency; + region_stream_stdout << std::endl; + + region_stream_csv << name_with_tree_lines; + region_stream_csv << std::fixed << std::setprecision(4); + region_stream_csv << "," << pop_metrics.elapsed_time/1000000000 << "s"; + region_stream_csv << "," << 100 * pop_metrics.parallel_efficiency; + region_stream_csv << "," << 100 * pop_metrics.mpi_parallel_efficiency; + region_stream_csv << "," << 100 * pop_metrics.mpi_communication_efficiency; + region_stream_csv << "," << 100 * pop_metrics.mpi_load_balance; + region_stream_csv << "," << 100 * pop_metrics.mpi_load_balance_in; + region_stream_csv << "," << 100 * pop_metrics.mpi_load_balance_out; + + region_stream_csv << "," << 100 * pop_metrics.omp_parallel_efficiency; + region_stream_csv << "," << 100 * pop_metrics.omp_load_balance; + region_stream_csv << "," << 100 * pop_metrics.omp_scheduling_efficiency; + region_stream_csv << "," << 100 * pop_metrics.omp_serialization_efficiency; + region_stream_csv << std::endl; + } - region_stream << std::setw(8) << std::right << pop_metrics.omp_parallel_efficiency; - region_stream << std::setw(8) << std::right << pop_metrics.omp_load_balance; - region_stream << std::setw(8) << std::right << pop_metrics.omp_scheduling_efficiency; - region_stream << std::setw(8) << std::right << pop_metrics.omp_serialization_efficiency; - region_stream << std::endl; + std::cout << region_stream_stdout.str() << std::endl; - //OMP-SCH OMP-SER OMP-LB + std::ofstream csv_stream; + csv_stream.open("nesmik_talp_tree.csv", std::ios::trunc); + csv_stream << region_stream_csv.str() << std::endl; - } - std::cout << region_stream.str(); + std::cout << "SIT:: TALP-Tree is done!" << std::endl; this->talp_profiling_strategy.finalize(); } diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp index 50d8348..7fbcd16 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp @@ -6,9 +6,11 @@ #include #include #include +#include struct TalpRegionNode { std::string name; + std::string tree_lines; std::size_t parent; std::vector childs; }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d3d642d..0e9f788 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,6 +16,13 @@ target_include_directories(TestCppDLB add_test(NAME TestCppDLB COMMAND TestCppDLB) +add_executable(TestCppTalpTree cpp/TestCppTalpTree.cpp) +target_link_libraries(TestCppTalpTree sit::sit) +target_include_directories(TestCppTalpTree + PRIVATE ${SIT_PUBLIC_HEADERS}) + +add_test(NAME TestCppTalpTree + COMMAND TestCppTalpTree) endif() @@ -57,4 +64,4 @@ if(BUILD_C_FORTRAN) add_test(NAME TestFortranLink COMMAND TestFortranLink) -endif() \ No newline at end of file +endif() diff --git a/tests/cpp/TestCppTalpTree.cpp b/tests/cpp/TestCppTalpTree.cpp new file mode 100644 index 0000000..e85c93a --- /dev/null +++ b/tests/cpp/TestCppTalpTree.cpp @@ -0,0 +1,18 @@ +#include "sit/sit.hpp" + +int main() { + sit::init("TALP-Tree"); + sit::region_start("Top"); + sit::region_start("child-1"); + sit::region_start("child-1.1"); + sit::region_stop("child-1.1"); + sit::region_start("child-1.2"); + sit::region_stop("child-1.2"); + sit::region_stop("child-1"); + sit::region_start("child-2"); + sit::region_start("child-2.1"); + sit::region_stop("child-2.1"); + sit::region_stop("child-2"); + sit::region_stop("Top"); + sit::finalize(); +} -- GitLab From a3940c509ed3d532b1c469c733022955077150ad Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Mon, 10 Jun 2024 21:41:28 +0200 Subject: [PATCH 4/5] Make it compile! --- src/backends/dlb/CMakeLists.txt | 1 - src/backends/dlb/dlb/CMakeLists.txt | 2 +- src/backends/dlb/dlb_talp_tree/CMakeLists.txt | 2 +- .../dlb/dlb_talp_tree/dlb_talp_tree.cpp | 18 +++++------ .../dlb/dlb_talp_tree/dlb_talp_tree.hpp | 8 ++--- src/delegator.cpp | 2 +- tests/CMakeLists.txt | 4 +-- tests/cpp/TestCppDLB.cpp | 8 ++--- tests/cpp/TestCppTalpTree.cpp | 30 +++++++++---------- 9 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/backends/dlb/CMakeLists.txt b/src/backends/dlb/CMakeLists.txt index 88e76cf..3a432c4 100644 --- a/src/backends/dlb/CMakeLists.txt +++ b/src/backends/dlb/CMakeLists.txt @@ -1,5 +1,4 @@ find_package(DLB REQUIRED) -target_sources(nesmik PRIVATE dlb.cpp) if(DLB_FOUND) target_include_directories(nesmik PRIVATE ${DLB_INCLUDE_DIRS}) diff --git a/src/backends/dlb/dlb/CMakeLists.txt b/src/backends/dlb/dlb/CMakeLists.txt index 525d2b4..9bb7520 100644 --- a/src/backends/dlb/dlb/CMakeLists.txt +++ b/src/backends/dlb/dlb/CMakeLists.txt @@ -1 +1 @@ -target_sources(sit PRIVATE dlb.cpp) +target_sources(nesmik PRIVATE dlb.cpp) diff --git a/src/backends/dlb/dlb_talp_tree/CMakeLists.txt b/src/backends/dlb/dlb_talp_tree/CMakeLists.txt index 3f699a4..160cc50 100644 --- a/src/backends/dlb/dlb_talp_tree/CMakeLists.txt +++ b/src/backends/dlb/dlb_talp_tree/CMakeLists.txt @@ -1 +1 @@ -target_sources(sit PRIVATE dlb_talp_tree.cpp) +target_sources(nesmik PRIVATE dlb_talp_tree.cpp) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index 5153af8..74552b3 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -3,13 +3,13 @@ #include "dlb_talp.h" #include #include -#include +#include #include #include #include void DLBTalpTreeStrategy::region_start( - const SITRegionInformation ®ion) noexcept { + const NPNRegionInformation ®ion) noexcept { // Construct the opening region hash by joining the name of the region with // the current region (i.e. the parent) hash. @@ -40,17 +40,17 @@ void DLBTalpTreeStrategy::region_start( } void DLBTalpTreeStrategy::region_stop( - const SITRegionInformation ®ion) noexcept { + const NPNRegionInformation ®ion) noexcept { auto current_region = this->regions[this->current_region]; if (region.name.compare(current_region.name) != 0) { - std::strstream error; + std::stringstream error; - error << "SIT:: Closing " << region.name << " would make "; + error << "neSmiK:: Closing " << region.name << " would make "; error << current_region.name << "not nested." << std::endl; - error << "SIT:: Closing " << current_region.name << " instead." << std::endl; + error << "neSmiK:: Closing " << current_region.name << " instead." << std::endl; std::cerr << error.str(); } @@ -136,8 +136,8 @@ void DLBTalpTreeStrategy::finalize() noexcept { std::stack regions_stack; regions_stack.push(top_region); - std::strstream region_stream_stdout; - std::strstream region_stream_csv; + std::stringstream region_stream_stdout; + std::stringstream region_stream_csv; while (!regions_stack.empty()) { std::size_t current_region_hash = regions_stack.top(); @@ -203,7 +203,5 @@ void DLBTalpTreeStrategy::finalize() noexcept { csv_stream.open("nesmik_talp_tree.csv", std::ios::trunc); csv_stream << region_stream_csv.str() << std::endl; - std::cout << "SIT:: TALP-Tree is done!" << std::endl; - this->talp_profiling_strategy.finalize(); } diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp index 7fbcd16..d0519ce 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp @@ -2,7 +2,7 @@ #define SIT_DLB_TALP_TREE_H #include "../dlb/dlb.hpp" -#include "sit_strategy.hpp" +#include "strategies.hpp" #include #include #include @@ -15,7 +15,7 @@ struct TalpRegionNode { std::vector childs; }; -class DLBTalpTreeStrategy : public SITProfilingStrategy { +class DLBTalpTreeStrategy : public NPNProfilingStrategy { private: DLBTalpStrategy talp_profiling_strategy; @@ -27,8 +27,8 @@ private: public: inline static const std::string_view name = "TALP-Tree"; - void region_start(const SITRegionInformation ®ion) noexcept override; - void region_stop(const SITRegionInformation ®ion) noexcept override; + void region_start(const NPNRegionInformation ®ion) noexcept override; + void region_stop(const NPNRegionInformation ®ion) noexcept override; virtual void init() noexcept; virtual void finalize() noexcept; }; diff --git a/src/delegator.cpp b/src/delegator.cpp index af64e40..5b65fdf 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -33,7 +33,7 @@ void Delegator::init(std::string_view backend) { pn_profiling_strategy = std::make_unique(); } else if (backend.compare(DLBTalpTreeStrategy::name) == 0) { - profiling_strategy = std::make_unique(); + npn_profiling_strategy = std::make_unique(); } #endif else { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0e9f788..c4c5e24 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,9 +17,9 @@ add_test(NAME TestCppDLB COMMAND TestCppDLB) add_executable(TestCppTalpTree cpp/TestCppTalpTree.cpp) -target_link_libraries(TestCppTalpTree sit::sit) +target_link_libraries(TestCppTalpTree nesmik::nesmik) target_include_directories(TestCppTalpTree - PRIVATE ${SIT_PUBLIC_HEADERS}) + PRIVATE ${NESMIK_PUBLIC_HEADERS}) add_test(NAME TestCppTalpTree COMMAND TestCppTalpTree) diff --git a/tests/cpp/TestCppDLB.cpp b/tests/cpp/TestCppDLB.cpp index 3d5b394..a91b6d7 100644 --- a/tests/cpp/TestCppDLB.cpp +++ b/tests/cpp/TestCppDLB.cpp @@ -1,8 +1,8 @@ #include "nesmik/nesmik.hpp" int main() { - sit::init("TALP"); - sit::region_start("Default"); - sit::region_stop("Default"); - sit::finalize(); + nesmik::init("TALP"); + nesmik::region_start("Default"); + nesmik::region_stop("Default"); + nesmik::finalize(); } diff --git a/tests/cpp/TestCppTalpTree.cpp b/tests/cpp/TestCppTalpTree.cpp index e85c93a..35610bc 100644 --- a/tests/cpp/TestCppTalpTree.cpp +++ b/tests/cpp/TestCppTalpTree.cpp @@ -1,18 +1,18 @@ -#include "sit/sit.hpp" +#include "nesmik/nesmik.hpp" int main() { - sit::init("TALP-Tree"); - sit::region_start("Top"); - sit::region_start("child-1"); - sit::region_start("child-1.1"); - sit::region_stop("child-1.1"); - sit::region_start("child-1.2"); - sit::region_stop("child-1.2"); - sit::region_stop("child-1"); - sit::region_start("child-2"); - sit::region_start("child-2.1"); - sit::region_stop("child-2.1"); - sit::region_stop("child-2"); - sit::region_stop("Top"); - sit::finalize(); + nesmik::init("TALP-Tree"); + nesmik::region_start("Top"); + nesmik::region_start("child-1"); + 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"); + nesmik::region_stop("Top"); + nesmik::finalize(); } -- GitLab From 882519e193b7207cbbc92c3e2c3a58802b7da43c Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Tue, 11 Jun 2024 18:28:24 +0200 Subject: [PATCH 5/5] DLBTalpTreeStrategy is acutally PN --- src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp | 4 ++-- src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp | 6 +++--- src/delegator.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp index 74552b3..292cd18 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -9,7 +9,7 @@ #include void DLBTalpTreeStrategy::region_start( - const NPNRegionInformation ®ion) noexcept { + const PNRegionInformation ®ion) noexcept { // Construct the opening region hash by joining the name of the region with // the current region (i.e. the parent) hash. @@ -40,7 +40,7 @@ void DLBTalpTreeStrategy::region_start( } void DLBTalpTreeStrategy::region_stop( - const NPNRegionInformation ®ion) noexcept { + const PNRegionInformation ®ion) noexcept { auto current_region = this->regions[this->current_region]; diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp index d0519ce..d2a58ca 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp @@ -15,7 +15,7 @@ struct TalpRegionNode { std::vector childs; }; -class DLBTalpTreeStrategy : public NPNProfilingStrategy { +class DLBTalpTreeStrategy : public PNProfilingStrategy { private: DLBTalpStrategy talp_profiling_strategy; @@ -27,8 +27,8 @@ private: public: inline static const std::string_view name = "TALP-Tree"; - void region_start(const NPNRegionInformation ®ion) noexcept override; - void region_stop(const NPNRegionInformation ®ion) noexcept override; + void region_start(const PNRegionInformation ®ion) noexcept override; + void region_stop(const PNRegionInformation ®ion) noexcept override; virtual void init() noexcept; virtual void finalize() noexcept; }; diff --git a/src/delegator.cpp b/src/delegator.cpp index 5b65fdf..2a651b2 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -33,7 +33,7 @@ void Delegator::init(std::string_view backend) { pn_profiling_strategy = std::make_unique(); } else if (backend.compare(DLBTalpTreeStrategy::name) == 0) { - npn_profiling_strategy = std::make_unique(); + pn_profiling_strategy = std::make_unique(); } #endif else { -- GitLab