From cedffee0356ce440e000c6cfda6598f0e2cd8e96 Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Tue, 1 Oct 2024 20:05:18 +0200 Subject: [PATCH 1/6] Restructure CMake and add nesmik help Restructures the CMake to compile the nesmik binary without the extrae and dlb dependencies. It adds infrastructure to easily gather the environment variable names and descriptions. TODO Properly separate the dlb and extrae wrappers so that are clean interfaces without having to expose them to the rest of the code. --- CMakeLists.txt | 137 ++++++++++++------ src/CMakeLists.txt | 16 +- src/backends/CMakeLists.txt | 9 +- src/backends/default/default.hpp | 9 +- src/backends/detection/detection.hpp | 5 + src/backends/dlb_talp/CMakeLists.txt | 6 +- src/backends/dlb_talp/dlb_talp.cpp | 18 +-- src/backends/dlb_talp/dlb_talp.hpp | 8 + src/backends/dlb_talp_tree/CMakeLists.txt | 6 +- src/backends/dlb_talp_tree/dlb_talp_tree.cpp | 18 ++- src/backends/dlb_talp_tree/dlb_talp_tree.hpp | 16 +- .../dlb_talp_tree_ascii_serializer.cpp | 7 +- .../dlb_talp_tree_json_serializer.cpp | 2 + .../extrae_partial_tracer/CMakeLists.txt | 6 +- .../extrae_partial_tracer.cpp | 4 + .../extrae_partial_tracer.hpp | 6 + src/backends/extrae_type_stack/CMakeLists.txt | 6 +- .../extrae_type_stack/extrae_type_stack.cpp | 2 + .../extrae_type_stack/extrae_type_stack.hpp | 5 + src/backends/wrappers/CMakeLists.txt | 9 +- src/backends/wrappers/dlb/CMakeLists.txt | 6 +- src/backends/wrappers/dlb/dlb_wrapper.cpp | 38 +++++ src/backends/wrappers/dlb/dlb_wrapper.hpp | 25 ++++ src/backends/wrappers/extrae/CMakeLists.txt | 6 +- .../wrappers/extrae/extrae_wrapper.cpp | 20 ++- src/nesmik_app.cpp | 13 ++ src/strategies.hpp | 15 ++ src/utils/environment_variable.hpp | 31 +++- 28 files changed, 354 insertions(+), 95 deletions(-) create mode 100644 src/nesmik_app.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f08fa4c..7b2e58f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,19 +36,52 @@ if(INSTALL_WITH_RPATH) SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) endif() -add_library(${PROJECT_NAME} SHARED) +add_library(nesmik SHARED) +set_property(TARGET nesmik PROPERTY OUTPUT_NAME nesmik_core) + +add_library(nesmik_lib SHARED) +set_property(TARGET nesmik_lib PROPERTY OUTPUT_NAME nesmik) +target_link_libraries(nesmik_lib PRIVATE nesmik) + +add_executable(nesmik_app) +set_property(TARGET nesmik_app PROPERTY OUTPUT_NAME nesmik) +target_link_libraries(nesmik_app PRIVATE nesmik) +target_link_libraries(nesmik_app PRIVATE nesmik_dlb_stripped) +target_link_libraries(nesmik_app PRIVATE nesmik_extrae_stripped) set(NESMIK_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include) -target_include_directories(${PROJECT_NAME} PUBLIC +target_include_directories(nesmik_lib PUBLIC $ $ $ $ ) +include(FetchContent) + +# Define the PathTOJson variable with an empty default value +set(NLOHMAN_JSON_PATH "" CACHE STRING "Path to the local nlohmann json release file") + +if(NLOHMAN_JSON_PATH) + FetchContent_Declare( + json + URL ${NLOHMAN_JSON_PATH} + ) +else() + FetchContent_Declare( + json + URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz + ) +endif() + +# FetchContent configuration +FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz) +FetchContent_MakeAvailable(json) +target_link_libraries(nesmik PRIVATE nlohmann_json::nlohmann_json) +target_link_libraries(nesmik_lib PRIVATE nlohmann_json::nlohmann_json) if(BUILD_C_FORTRAN AND SPLIT_FORTRAN_LIBRARY) add_library(nesmik_f) @@ -57,69 +90,64 @@ endif() if(WITH_MPI) find_package(MPI REQUIRED COMPONENTS CXX) - target_link_libraries(${PROJECT_NAME} PRIVATE MPI::MPI_CXX) - target_compile_definitions(nesmik PRIVATE "WITH_MPI") + target_link_libraries(nesmik_lib PRIVATE MPI::MPI_CXX) + target_compile_definitions(nesmik_lib PRIVATE "WITH_MPI") endif() if(ENABLE_EXTRAE) find_package(EXTRAE REQUIRED) if(EXTRAE_FOUND) - target_include_directories(nesmik - PRIVATE ${EXTRAE_INCLUDE_DIRS}) - # We link publicy with seqtrace, as we need it to be in the right order to libc to find malloc with dlsym .. - target_link_libraries(nesmik PUBLIC ${EXTRAE_LIBRARIES}) - target_compile_definitions(nesmik PRIVATE "ENABLE_EXTRAE") + # Create the Extrae Wrapper library + add_library(nesmik_extrae SHARED) + + #Include and link with Extrae + target_include_directories(nesmik_extrae + PRIVATE ${EXTRAE_INCLUDE_DIRS}) + # We link publicy with seqtrace, as we need it to be in the right order to + # libc to find malloc with dlsym .. + target_link_libraries(nesmik_extrae PUBLIC ${EXTRAE_LIBRARIES}) + target_compile_definitions(nesmik_extrae PRIVATE "ENABLE_EXTRAE") + # And link libnesmik.so with it. + target_link_libraries(nesmik_lib PRIVATE nesmik_extrae) + # Link JSON library with it + target_link_libraries(nesmik_extrae PRIVATE nlohmann_json::nlohmann_json) else() - message(FATAL_ERROR "Couldn't find Extrae") + message(FATAL_ERROR "Couldn't find Extrae") endif() endif() +add_library(nesmik_extrae_stripped SHARED) +target_link_libraries(nesmik_extrae_stripped PRIVATE nlohmann_json::nlohmann_json) if(ENABLE_DLB) find_package(DLB REQUIRED) if(DLB_FOUND) - target_include_directories(nesmik - PRIVATE ${DLB_INCLUDE_DIRS}) - target_link_libraries(nesmik PRIVATE ${DLB_LIBRARIES}) - target_compile_definitions(nesmik PRIVATE "ENABLE_DLB") - else() - message(FATAL_ERROR "Couldn't find DLB") - endif() -endif() + # Create the DLB Wrapper library + add_library(nesmik_dlb SHARED) + # Include and link with DLB + target_include_directories(nesmik_dlb + PRIVATE ${DLB_INCLUDE_DIRS}) + target_link_libraries(nesmik_dlb PRIVATE ${DLB_LIBRARIES}) -include(FetchContent) + # Enable DLB guards + target_compile_definitions(nesmik_dlb PRIVATE "ENABLE_DLB") - -# Define the PathTOJson variable with an empty default value -set(NLOHMAN_JSON_PATH "" CACHE STRING "Path to the local nlohmann json release file") - -if(NLOHMAN_JSON_PATH) - FetchContent_Declare( - json - URL ${NLOHMAN_JSON_PATH} - ) -else() - FetchContent_Declare( - json - URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz - ) + # Link libnesmik.so with DLB + target_link_libraries(nesmik_lib PRIVATE nesmik_dlb) + # Link JSON library with it + target_link_libraries(nesmik_dlb PRIVATE nlohmann_json::nlohmann_json) + else() + message(FATAL_ERROR "Couldn't find DLB") + endif() endif() - -# FetchContent configuration - -FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz) -FetchContent_MakeAvailable(json) - -target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json::nlohmann_json) - +add_library(nesmik_dlb_stripped SHARED) +target_link_libraries(nesmik_dlb_stripped PRIVATE nlohmann_json::nlohmann_json) add_subdirectory(src) - enable_testing() add_subdirectory(tests) - # # Install Targets for nesmik # @@ -128,11 +156,30 @@ add_subdirectory(tests) include(GNUInstallDirs) message(STATUS ${CMAKE_INSTALL_INCLUDEDIR}) +if(ENABLE_EXTRAE) +install(TARGETS nesmik_extrae + EXPORT nesmikTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} + ) +endif() + +if(ENABLE_DLB) +install(TARGETS nesmik_dlb + EXPORT nesmikTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} + ) +endif() if(BUILD_C_FORTRAN AND SPLIT_FORTRAN_LIBRARY) -install(TARGETS ${PROJECT_NAME} nesmik_f +install(TARGETS nesmik_lib nesmik nesmik_f EXPORT nesmikTargets LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -140,7 +187,7 @@ install(TARGETS ${PROJECT_NAME} nesmik_f INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} ) else() -install(TARGETS ${PROJECT_NAME} +install(TARGETS nesmik_lib nesmik EXPORT nesmikTargets FILE_SET HEADERS LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3be7aed..f10fbeb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,20 @@ add_subdirectory(backends) add_subdirectory(utils) -target_sources(nesmik PRIVATE delegator.cpp nesmik.cpp) +target_sources(nesmik_lib PRIVATE delegator.cpp nesmik.cpp) +target_sources(nesmik_app PRIVATE nesmik_app.cpp) + +target_include_directories(nesmik PRIVATE ".") +target_include_directories(nesmik_app PRIVATE ".") + +if(ENABLE_EXTRAE) + target_include_directories(nesmik_extrae PRIVATE ".") +endif() +target_include_directories(nesmik_extrae_stripped PRIVATE ".") + +if(ENABLE_DLB) + target_include_directories(nesmik_dlb PRIVATE ".") +endif() +target_include_directories(nesmik_dlb_stripped PRIVATE ".") if(BUILD_C_FORTRAN) add_subdirectory(bindings) diff --git a/src/backends/CMakeLists.txt b/src/backends/CMakeLists.txt index 270833a..7aecfa2 100644 --- a/src/backends/CMakeLists.txt +++ b/src/backends/CMakeLists.txt @@ -1,12 +1,13 @@ add_subdirectory(default) add_subdirectory(detection) add_subdirectory(wrappers) -if(ENABLE_DLB) + +#if(ENABLE_DLB) add_subdirectory(dlb_talp) add_subdirectory(dlb_talp_tree) -endif() +#endif() -if(ENABLE_EXTRAE) +#if(ENABLE_EXTRAE) add_subdirectory(extrae_partial_tracer) add_subdirectory(extrae_type_stack) -endif() +#endif() diff --git a/src/backends/default/default.hpp b/src/backends/default/default.hpp index 7158c24..4e2cda3 100644 --- a/src/backends/default/default.hpp +++ b/src/backends/default/default.hpp @@ -1,7 +1,6 @@ +#include #include -#include "strategies.hpp" - class NPNDefault : public NotProperlyNestedAnnotationStrategy { public: NPNDefault(); @@ -12,4 +11,10 @@ class NPNDefault : public NotProperlyNestedAnnotationStrategy { const NotProperlyNestedRegionInformation &info_to_stop) noexcept override; virtual void Init() noexcept; virtual void Finalize() noexcept; + + EnvironmentVariableStorage getEnvironmentVariablesDescription() + const noexcept { + EnvironmentVariableStorage storage; + return storage; + } }; diff --git a/src/backends/detection/detection.hpp b/src/backends/detection/detection.hpp index ed7f499..daa86c3 100644 --- a/src/backends/detection/detection.hpp +++ b/src/backends/detection/detection.hpp @@ -53,5 +53,10 @@ class DetectionStrategy : public ProperlyNestedAnnotationStrategy { const ProperlyNestedRegionInformation& region) noexcept override; virtual void Init() noexcept; virtual void Finalize() noexcept; + EnvironmentVariableStorage getEnvironmentVariablesDescription() + const noexcept { + EnvironmentVariableStorage storage; + return storage; + } }; #endif // NESMIK_DETECTION_H diff --git a/src/backends/dlb_talp/CMakeLists.txt b/src/backends/dlb_talp/CMakeLists.txt index 56f83f6..04b652a 100644 --- a/src/backends/dlb_talp/CMakeLists.txt +++ b/src/backends/dlb_talp/CMakeLists.txt @@ -1 +1,5 @@ -target_sources(nesmik PRIVATE dlb_talp.cpp) +if (ENABLE_DLB) + target_sources(nesmik_dlb PRIVATE dlb_talp.cpp) +endif() + +target_sources(nesmik_dlb_stripped PRIVATE dlb_talp.cpp) diff --git a/src/backends/dlb_talp/dlb_talp.cpp b/src/backends/dlb_talp/dlb_talp.cpp index 3af603b..3f1d71c 100644 --- a/src/backends/dlb_talp/dlb_talp.cpp +++ b/src/backends/dlb_talp/dlb_talp.cpp @@ -3,9 +3,6 @@ #include #include -#include "dlb.h" -#include "dlb_talp.h" - DLBTalpStrategy::DLBTalpStrategy() { parallelism_descriptor_ = { .mpi_descriptor_ = MPIDescriptor::DontCare, @@ -16,17 +13,12 @@ DLBTalpStrategy::DLBTalpStrategy() { void DLBTalpStrategy::RegionStart( const NotProperlyNestedRegionInformation ®ion) noexcept { - // we have to create a small std::string thing because we cannot assume that - // the string_view passed is properly null terminated - auto handle = DLB_MonitoringRegionRegister(std::string(region.name).c_str()); - DLB_MonitoringRegionStart(handle); + dlb_wrapper_.StartMonitoringRegion(std::string(region.name)); } void DLBTalpStrategy::RegionStop( - const NotProperlyNestedRegionInformation ®ion) noexcept { - auto handle = DLB_MonitoringRegionRegister(std::string(region.name).c_str()); - DLB_MonitoringRegionStop(handle); -} + const NotProperlyNestedRegionInformation ®ion) noexcept {} + +void DLBTalpStrategy::Init() noexcept { dlb_wrapper_.Init(0, "--talp"); } -void DLBTalpStrategy::Init() noexcept { DLB_Init(0, NULL, "--talp"); } -void DLBTalpStrategy::Finalize() noexcept { DLB_Finalize(); } +void DLBTalpStrategy::Finalize() noexcept { dlb_wrapper_.Finalize(); } diff --git a/src/backends/dlb_talp/dlb_talp.hpp b/src/backends/dlb_talp/dlb_talp.hpp index d6a4abd..7268ed9 100644 --- a/src/backends/dlb_talp/dlb_talp.hpp +++ b/src/backends/dlb_talp/dlb_talp.hpp @@ -1,10 +1,13 @@ #ifndef NESMIK_DLB_H #define NESMIK_DLB_H +#include #include class DLBTalpStrategy : public NotProperlyNestedAnnotationStrategy { public: + DLBWrapper dlb_wrapper_; + DLBTalpStrategy(); inline static const std::string name = "TALP"; virtual void RegionStart( @@ -13,5 +16,10 @@ class DLBTalpStrategy : public NotProperlyNestedAnnotationStrategy { const NotProperlyNestedRegionInformation ®ion) noexcept override; virtual void Init() noexcept; virtual void Finalize() noexcept; + EnvironmentVariableStorage getEnvironmentVariablesDescription() + const noexcept { + EnvironmentVariableStorage storage; + return storage; + } }; #endif // NESMIK_DLB_H diff --git a/src/backends/dlb_talp_tree/CMakeLists.txt b/src/backends/dlb_talp_tree/CMakeLists.txt index fc44ff5..7622fe2 100644 --- a/src/backends/dlb_talp_tree/CMakeLists.txt +++ b/src/backends/dlb_talp_tree/CMakeLists.txt @@ -1 +1,5 @@ -target_sources(nesmik PRIVATE dlb_talp_tree.cpp dlb_talp_tree_json_serializer.cpp dlb_talp_tree_ascii_serializer.cpp) +if (ENABLE_DLB) + target_sources(nesmik_dlb PRIVATE dlb_talp_tree.cpp dlb_talp_tree_json_serializer.cpp dlb_talp_tree_ascii_serializer.cpp) +endif() + +target_sources(nesmik_dlb_stripped PRIVATE dlb_talp_tree.cpp dlb_talp_tree_json_serializer.cpp dlb_talp_tree_ascii_serializer.cpp) diff --git a/src/backends/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb_talp_tree/dlb_talp_tree.cpp index 50802a7..9f6a0f8 100644 --- a/src/backends/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb_talp_tree/dlb_talp_tree.cpp @@ -10,8 +10,8 @@ #include #include -#include "dlb.h" -#include "dlb_talp.h" +// #include "dlb.h" +// #include "dlb_talp.h" #include "dlb_talp_tree_ascii_serializer.hpp" #include "dlb_talp_tree_json_serializer.hpp" @@ -24,9 +24,13 @@ using json = nlohmann::json; DLBTalpTreeStrategy::DLBTalpTreeStrategy() : mpi_helper_{} { - parallelism_descriptor_ = { - .mpi_descriptor_ = MPIDescriptor::Aware, - .thread_descriptor_ = ThreadDescriptor::Unsupported}; + // description = { + // .name_ = "TALP::Tree", + // .description_ = "asdfkj;laksdf", + // .parallelism_descriptor_ = + // .mpi_descriptor_ = MPIDescriptor::Aware, + // .thread_descriptor_ = ThreadDescriptor::Unsupported} + // } } std::string region_hash_to_string(std::size_t region_hash) { @@ -167,8 +171,8 @@ void DLBTalpTreeStrategy::Finalize() noexcept { name = top_region_; } - auto handle = DLB_MonitoringRegionRegister(name.c_str()); - int dlb_error = DLB_TALP_CollectPOPMetrics(handle, ®ion.pop_metrics); + int dlb_error = talp_profiling_strategy_.dlb_wrapper_.CollectPOPMetrics( + name, ®ion.pop_metrics); if (dlb_error != DLB_SUCCESS) { // Warn about the error trying to close region name with hash diff --git a/src/backends/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb_talp_tree/dlb_talp_tree.hpp index 8cc923d..37962d7 100644 --- a/src/backends/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb_talp_tree/dlb_talp_tree.hpp @@ -8,9 +8,10 @@ #include #include -#include "../dlb_talp/dlb_talp.hpp" -#include "dlb.h" -#include "dlb_talp.h" +// #include "dlb.h" +// #include "dlb_talp.h" +#include + #include "strategies.hpp" struct TalpRegionNode { @@ -58,6 +59,15 @@ class DLBTalpTreeStrategy : public ProperlyNestedAnnotationStrategy { const ProperlyNestedRegionInformation ®ion) noexcept override; virtual void Init() noexcept; virtual void Finalize() noexcept; + + EnvironmentVariableStorage getEnvironmentVariablesDescription() + const noexcept { + EnvironmentVariableStorage storage; + storage.add(env_json_file_name_); + storage.add(env_enable_json_); + storage.add(env_enable_ascii_); + return storage; + } }; #endif // DLB_TALP_TREE_H diff --git a/src/backends/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp b/src/backends/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp index 10267e6..1e68f31 100644 --- a/src/backends/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp +++ b/src/backends/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp @@ -20,6 +20,7 @@ struct RegionStackEntry { }; std::size_t DLBTalpTreeASCIISerializer::compute_tree_lines() { +#if defined(ENABLE_DLB) std::stack regions_stack; regions_stack.push({.hash = this->top_region, .level = 0, .tree_lines = ""}); @@ -65,14 +66,15 @@ std::size_t DLBTalpTreeASCIISerializer::compute_tree_lines() { tree_lines.length()); } return max_width; +#endif } std::string DLBTalpTreeASCIISerializer::generate_tree_view(int name_width) { + std::stringstream region_stream; +#if defined(ENABLE_DLB) std::stack regions_stack; regions_stack.push(this->top_region); - std::stringstream region_stream; - while (!regions_stack.empty()) { std::size_t current_region_hash = regions_stack.top(); regions_stack.pop(); @@ -117,6 +119,7 @@ std::string DLBTalpTreeASCIISerializer::generate_tree_view(int name_width) { region_stream << std::endl; } +#endif return region_stream.str(); } diff --git a/src/backends/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp b/src/backends/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp index 89191f9..8c653de 100644 --- a/src/backends/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp +++ b/src/backends/dlb_talp_tree/dlb_talp_tree_json_serializer.cpp @@ -13,6 +13,7 @@ DLBTalpTreeJSONSerializer::DLBTalpTreeJSONSerializer( void treeToJSON(const TalpRegionNode& node, json& talp_json, std::map const& regions) { +#if defined(ENABLE_DLB) talp_json["regionName"] = node.name; talp_json["metrics"] = { {"elapsedTime", node.pop_metrics.elapsed_time}, @@ -38,6 +39,7 @@ void treeToJSON(const TalpRegionNode& node, json& talp_json, treeToJSON(regions.at(child), childJSON, regions); talp_json["subregions"].push_back(childJSON); } +#endif } std::string DLBTalpTreeJSONSerializer::dump() { diff --git a/src/backends/extrae_partial_tracer/CMakeLists.txt b/src/backends/extrae_partial_tracer/CMakeLists.txt index dff45e3..104063f 100644 --- a/src/backends/extrae_partial_tracer/CMakeLists.txt +++ b/src/backends/extrae_partial_tracer/CMakeLists.txt @@ -1 +1,5 @@ -target_sources(nesmik PRIVATE extrae_partial_tracer.cpp) +if (ENABLE_EXTRAE) + target_sources(nesmik_extrae PRIVATE extrae_partial_tracer.cpp) +endif() + +target_sources(nesmik_extrae_stripped PRIVATE extrae_partial_tracer.cpp) diff --git a/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp b/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp index b59040c..03bcb7d 100644 --- a/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp +++ b/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp @@ -24,7 +24,9 @@ void ExtraePartialTracer::shutdown(bool annotate) noexcept { std::cout << "neSmiK Partial Tracer: Shutting down" << std::endl; } if (annotate) extrae_wrapper_.StopWithTypeAndRegionName(state_type_, "ON"); +#if defined(ENABLE_EXTRAE) Extrae_shutdown(); +#endif is_shutdown_ = true; } @@ -32,9 +34,11 @@ void ExtraePartialTracer::start(bool annotate) noexcept { if (debug_output_.getValue().value_or(false) && mpi_helper_.IsRankNumber(0)) { std::cout << "neSmiK Partial Tracer: Starting up" << std::endl; } +#if defined(ENABLE_EXTRAE) Extrae_restart(); if (annotate) extrae_wrapper_.StartWithTypeAndRegionName(state_type_, "ON"); is_shutdown_ = false; +#endif } void ExtraePartialTracer::Init() noexcept { diff --git a/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp b/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp index 5b7d74d..7feb612 100644 --- a/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp +++ b/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp @@ -70,4 +70,10 @@ class ExtraePartialTracer : public ProperlyNestedAnnotationStrategy { const ProperlyNestedRegionInformation ®ion) noexcept override; virtual void Init() noexcept override; virtual void Finalize() noexcept override; + + EnvironmentVariableStorage getEnvironmentVariablesDescription() + const noexcept { + EnvironmentVariableStorage storage; + return storage; + } }; diff --git a/src/backends/extrae_type_stack/CMakeLists.txt b/src/backends/extrae_type_stack/CMakeLists.txt index 319ef9c..63dd356 100644 --- a/src/backends/extrae_type_stack/CMakeLists.txt +++ b/src/backends/extrae_type_stack/CMakeLists.txt @@ -1 +1,5 @@ -target_sources(nesmik PRIVATE extrae_type_stack.cpp) +if (ENABLE_EXTRAE) + target_sources(nesmik_extrae PRIVATE extrae_type_stack.cpp) +endif() + +target_sources(nesmik_extrae_stripped PRIVATE extrae_type_stack.cpp) diff --git a/src/backends/extrae_type_stack/extrae_type_stack.cpp b/src/backends/extrae_type_stack/extrae_type_stack.cpp index 7b61177..ebd59c6 100644 --- a/src/backends/extrae_type_stack/extrae_type_stack.cpp +++ b/src/backends/extrae_type_stack/extrae_type_stack.cpp @@ -10,9 +10,11 @@ #include #include +#if defined(EXTRAE_ENABLED) extern "C" { #include } +#endif inline std::string getLevelString(const std::size_t level) { return "Level: " + std::to_string(level); diff --git a/src/backends/extrae_type_stack/extrae_type_stack.hpp b/src/backends/extrae_type_stack/extrae_type_stack.hpp index c8ccf25..7828856 100644 --- a/src/backends/extrae_type_stack/extrae_type_stack.hpp +++ b/src/backends/extrae_type_stack/extrae_type_stack.hpp @@ -37,5 +37,10 @@ class ExtraeTypeStackStrategy : public ProperlyNestedAnnotationStrategy { const ProperlyNestedRegionInformation ®ion) noexcept override; virtual void Init() noexcept override; virtual void Finalize() noexcept override; + EnvironmentVariableStorage getEnvironmentVariablesDescription() + const noexcept { + EnvironmentVariableStorage storage; + return storage; + } }; #endif // NESMIK_EXTRAE_TYPE_STACK_HPP diff --git a/src/backends/wrappers/CMakeLists.txt b/src/backends/wrappers/CMakeLists.txt index 9f5951d..a125889 100644 --- a/src/backends/wrappers/CMakeLists.txt +++ b/src/backends/wrappers/CMakeLists.txt @@ -1,7 +1,2 @@ -if(ENABLE_DLB) - add_subdirectory(dlb) -endif() - -if(ENABLE_EXTRAE) - add_subdirectory(extrae) -endif() +add_subdirectory(dlb) +add_subdirectory(extrae) diff --git a/src/backends/wrappers/dlb/CMakeLists.txt b/src/backends/wrappers/dlb/CMakeLists.txt index 3bb5847..1bebbfe 100644 --- a/src/backends/wrappers/dlb/CMakeLists.txt +++ b/src/backends/wrappers/dlb/CMakeLists.txt @@ -1 +1,5 @@ -target_sources(nesmik PRIVATE dlb_wrapper.cpp) +if(ENABLE_DLB) + target_sources(nesmik_dlb PRIVATE dlb_wrapper.cpp) +endif() + +target_sources(nesmik_dlb_stripped PRIVATE dlb_wrapper.cpp) diff --git a/src/backends/wrappers/dlb/dlb_wrapper.cpp b/src/backends/wrappers/dlb/dlb_wrapper.cpp index e69de29..d21d36d 100644 --- a/src/backends/wrappers/dlb/dlb_wrapper.cpp +++ b/src/backends/wrappers/dlb/dlb_wrapper.cpp @@ -0,0 +1,38 @@ + +#include "dlb_wrapper.hpp" + +void DLBWrapper::Init(int ncpus, std::string dlb_args) { +#if defined(ENABLE_DLB) + DLB_Init(ncpus, NULL, dlb_args.c_str()); +#endif +} + +void DLBWrapper::Finalize() { +#if defined(ENABLE_DLB) + DLB_Finalize(); +#endif +} + +void DLBWrapper::StartMonitoringRegion(std::string region_name) { +#if defined(ENABLE_DLB) + auto handle = DLB_MonitoringRegionRegister(region_name.c_str()); + DLB_MonitoringRegionStart(handle); +#endif +} + +void DLBWrapper::StopMonitoringRegion(std::string region_name) { +#if defined(ENABLE_DLB) + auto handle = DLB_MonitoringRegionRegister(region.name.c_str()); + DLB_MonitoringRegionStop(handle); +#endif +} + +int DLBWrapper::CollectPOPMetrics(std::string region_name, + dlb_pop_metrics_t *metrics) { +#if defined(ENABLE_DLB) + auto handle = DLB_MonitoringRegionRegister(region_name.c_str()); + return DLB_TALP_CollectPOPMetrics(handle, metrics); +#else + return 0; +#endif +} diff --git a/src/backends/wrappers/dlb/dlb_wrapper.hpp b/src/backends/wrappers/dlb/dlb_wrapper.hpp index e69de29..81f326e 100644 --- a/src/backends/wrappers/dlb/dlb_wrapper.hpp +++ b/src/backends/wrappers/dlb/dlb_wrapper.hpp @@ -0,0 +1,25 @@ +#ifndef NESMIK_DLB_WRAPPER_H +#define NESMIK_DLB_WRAPPER_H + +#include + +#if defined(ENABLE_DLB) +#include "dlb.h" +#include "dlb_talp.h" +#else +typedef void *dlb_pop_metrics_t; +#define DLB_SUCCESS 0 +#endif + +class DLBWrapper { + public: + void Init(int ncpus, std::string dlb_args); + void Finalize(); + + void StartMonitoringRegion(std::string region_name); + void StopMonitoringRegion(std::string region_name); + + int CollectPOPMetrics(std::string region_name, dlb_pop_metrics_t *metrics); +}; + +#endif /* NESMIK_DLB_WRAPPER_H */ diff --git a/src/backends/wrappers/extrae/CMakeLists.txt b/src/backends/wrappers/extrae/CMakeLists.txt index ba3bc11..4db7bba 100644 --- a/src/backends/wrappers/extrae/CMakeLists.txt +++ b/src/backends/wrappers/extrae/CMakeLists.txt @@ -1 +1,5 @@ -target_sources(nesmik PRIVATE extrae_wrapper.cpp paraver_config.cpp) +if(ENABLE_EXTRAE) + target_sources(nesmik_extrae PRIVATE extrae_wrapper.cpp paraver_config.cpp) +endif() + +target_sources(nesmik_extrae_stripped PRIVATE extrae_wrapper.cpp paraver_config.cpp) diff --git a/src/backends/wrappers/extrae/extrae_wrapper.cpp b/src/backends/wrappers/extrae/extrae_wrapper.cpp index 1eab24e..a8283a2 100644 --- a/src/backends/wrappers/extrae/extrae_wrapper.cpp +++ b/src/backends/wrappers/extrae/extrae_wrapper.cpp @@ -20,6 +20,7 @@ extern "C" { ExtraeWrapper::ExtraeWrapper(actual_extrae_type base_type) : base_type_(base_type) { +#if defined(ENABLE_EXTRAE) auto isInitializedVal = Extrae_is_initialized(); if (isInitializedVal == 0) { // Extrae is not initialized yet see @@ -28,10 +29,12 @@ ExtraeWrapper::ExtraeWrapper(actual_extrae_type base_type) did_init_extrae_ = true; std::cout << "neSmiK forced to Initialize extrae" << std::endl; } +#endif } actual_extrae_value ExtraeWrapper::getValueByName(actual_extrae_type type, const std::string &name) { +#if defined(ENABLE_EXTRAE) value_map_t &value_map = string_to_value_; if (value_map.count(name) > 0) { return value_map[name]; @@ -48,45 +51,57 @@ actual_extrae_value ExtraeWrapper::getValueByName(actual_extrae_type type, value_map[name] = downcasted_hash; return downcasted_hash; } +#endif } void ExtraeWrapper::RegisterTypeWithDescription( const std::string &type_description, actual_extrae_type type) { +#if defined(ENABLE_EXTRAE) type_map_[type_description] = type; +#endif } void ExtraeWrapper::StartWithTypeAndRegionName(actual_extrae_type type, const std::string &value_str) { +#if defined(ENABLE_EXTRAE) const auto value = getValueByName(type, value_str); // write it in type specific map type_to_value_map_[type][value_str] = value; Extrae_eventandcounters(static_cast(type), static_cast(value)); +#endif } void ExtraeWrapper::StopWithTypeAndRegionName(actual_extrae_type type, const std::string &value_str) { +#if defined(ENABLE_EXTRAE) Extrae_eventandcounters(static_cast(type), 0); +#endif } void ExtraeWrapper::StopWithTypeNameAndRegionName( const std::string &type_description, const std::string &value_str) { +#if defined(ENABLE_EXTRAE) // if this assertion fails, the type with that description has not been // registered before and not started. assert(type_map_.count(type_description) > 0); return StopWithTypeAndRegionName(type_map_[type_description], value_str); +#endif } void ExtraeWrapper::StartWithTypeNameAndRegionName( const std::string &type_description, const std::string &value_str) { +#if defined(ENABLE_EXTRAE) if (type_map_.count(type_description) == 0) { const auto new_type = type_map_.size(); type_map_[type_description] = base_type_ + new_type; } return StartWithTypeAndRegionName(type_map_[type_description], value_str); +#endif } void ExtraeWrapper::Finalize() { - // for ever type define the event types: +#if defined(ENABLE_EXTRAE) + // now for every type define the event types: for (const auto &[description, type_from_map] : type_map_) { // For every type registered: extrae_type_t type = static_cast(type_from_map); @@ -127,9 +142,11 @@ void ExtraeWrapper::Finalize() { // Finalize it Extrae_fini(); } +#endif } std::string ExtraeWrapper::getParaverConfig(ExtraeParaverConfig config) { +#if defined(ENABLE_EXTRAE) ParaverConfig paraver_config(config.description); // create arrays @@ -160,4 +177,5 @@ std::string ExtraeWrapper::getParaverConfig(ExtraeParaverConfig config) { paraver_config.addTimeline(window); return paraver_config.getString(); +#endif } diff --git a/src/nesmik_app.cpp b/src/nesmik_app.cpp new file mode 100644 index 0000000..5220201 --- /dev/null +++ b/src/nesmik_app.cpp @@ -0,0 +1,13 @@ +#include +#include + +void showUsages() { + DLBTalpTreeStrategy dlb_talp_tree_strategy; + for (auto description : + dlb_talp_tree_strategy.getEnvironmentVariablesDescription()) { + std::cout << description.variable_name_ << ": " << description.description_ + << std::endl; + } +} + +int main() { showUsages(); } diff --git a/src/strategies.hpp b/src/strategies.hpp index e19425d..392803d 100644 --- a/src/strategies.hpp +++ b/src/strategies.hpp @@ -5,6 +5,7 @@ #include #include #include +#include /* Describes the Strategy behavior with respect to MPI. @@ -40,6 +41,12 @@ struct NotProperlyNestedRegionInformation { std::string_view name; }; +// struct StrategyDescription { +// std::string name_; +// std::string description_; +// ParallelismDescriptor parallelism_descriptor; +// }; + // A backend implementing the Properly Nested Profiling class ProperlyNestedAnnotationStrategy { public: @@ -51,6 +58,10 @@ class ProperlyNestedAnnotationStrategy { const ProperlyNestedRegionInformation ®ion) noexcept = 0; virtual void Finalize() noexcept = 0; + // virtual const &StrategyDescription getDescription() const noexcept = 0; + virtual EnvironmentVariableStorage getEnvironmentVariablesDescription() + const noexcept = 0; + ParallelismDescriptor parallelism_descriptor_; }; @@ -64,6 +75,10 @@ class NotProperlyNestedAnnotationStrategy { const NotProperlyNestedRegionInformation ®ion) noexcept = 0; virtual void Finalize() noexcept = 0; + // virtual const &StrategyDescription getDescription() const noexcept = 0; + // virtual EnvironmentVariableStorage& getEnvironmentVariablesDescription() + // const noexcept = 0; + ParallelismDescriptor parallelism_descriptor_; }; diff --git a/src/utils/environment_variable.hpp b/src/utils/environment_variable.hpp index 3f6f3f4..4690bc8 100644 --- a/src/utils/environment_variable.hpp +++ b/src/utils/environment_variable.hpp @@ -24,8 +24,19 @@ template <> std::optional> fromEnvString( const std::string &env_string); +class EnvironmentVariableDescription { + public: + std::string variable_name_; + std::string description_; + + EnvironmentVariableDescription() {} + EnvironmentVariableDescription(std::string variable_name, + std::string description) + : variable_name_(variable_name), description_(description) {} +}; + template -class EnvironmentVariable { +class EnvironmentVariable : public EnvironmentVariableDescription { inline static std::string PREFIX = "NESMIK_"; public: @@ -34,7 +45,7 @@ class EnvironmentVariable { */ EnvironmentVariable(const std::string &variable_name, const std::string &description, bool required = false) - : variable_name_(variable_name), description_(description) { + : EnvironmentVariableDescription(PREFIX + variable_name, description) { const std::string variable_to_query = EnvironmentVariable::PREFIX + variable_name_; @@ -52,8 +63,6 @@ class EnvironmentVariable { EnvironmentVariable() = delete; private: - std::string variable_name_; - std::string description_; std::optional value_{std::nullopt}; public: @@ -64,4 +73,18 @@ class EnvironmentVariable { } }; +class EnvironmentVariableStorage { + private: + std::vector storage_; + + public: + EnvironmentVariableStorage() {} + void add(EnvironmentVariableDescription description) { + storage_.push_back(description); + } + + auto begin() { return storage_.begin(); } + auto end() { return storage_.end(); } +}; + #endif // NESMIK_ENVIROMENT_VARIABLE_HPP -- GitLab From 2c9137a49b683040f8b8103520e508a9361ad358 Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Tue, 22 Oct 2024 11:33:00 +0200 Subject: [PATCH 2/6] Add basic usage. Uncommited changes --- CMakeLists.txt | 2 + src/backends/default/default.cpp | 5 - src/backends/default/default.hpp | 17 ++- src/backends/detection/CMakeLists.txt | 1 + src/backends/detection/detection.cpp | 5 - src/backends/detection/detection.hpp | 22 ++- src/backends/dlb_talp/dlb_talp.cpp | 8 - src/backends/dlb_talp/dlb_talp.hpp | 21 ++- src/backends/dlb_talp_tree/dlb_talp_tree.cpp | 10 -- src/backends/dlb_talp_tree/dlb_talp_tree.hpp | 25 +++- .../extrae_partial_tracer.cpp | 11 -- .../extrae_partial_tracer.hpp | 29 +++- .../extrae_type_stack/extrae_type_stack.cpp | 7 - .../extrae_type_stack/extrae_type_stack.hpp | 21 ++- src/delegator.cpp | 20 +-- src/nesmik_app.cpp | 141 +++++++++++++++++- src/strategies.hpp | 92 +++++++++--- src/utils/environment_variable.hpp | 13 +- 18 files changed, 341 insertions(+), 109 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b2e58f..576b117 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ set_property(TARGET nesmik_app PROPERTY OUTPUT_NAME nesmik) target_link_libraries(nesmik_app PRIVATE nesmik) target_link_libraries(nesmik_app PRIVATE nesmik_dlb_stripped) target_link_libraries(nesmik_app PRIVATE nesmik_extrae_stripped) +target_compile_definitions(nesmik_app PRIVATE "NESMIK_APP") set(NESMIK_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include) @@ -82,6 +83,7 @@ FetchContent_MakeAvailable(json) target_link_libraries(nesmik PRIVATE nlohmann_json::nlohmann_json) target_link_libraries(nesmik_lib PRIVATE nlohmann_json::nlohmann_json) +target_link_libraries(nesmik_app PRIVATE nlohmann_json::nlohmann_json) if(BUILD_C_FORTRAN AND SPLIT_FORTRAN_LIBRARY) add_library(nesmik_f) diff --git a/src/backends/default/default.cpp b/src/backends/default/default.cpp index d3e50e3..9054829 100644 --- a/src/backends/default/default.cpp +++ b/src/backends/default/default.cpp @@ -3,11 +3,6 @@ #include #include -NPNDefault::NPNDefault() { - parallelism_descriptor_ = {.mpi_descriptor_ = MPIDescriptor::DontCare, - .thread_descriptor_ = ThreadDescriptor::Supported}; -} - void NPNDefault::RegionStart( const NotProperlyNestedRegionInformation ®ion) noexcept { std::cout << "neSmiK: DefaultBackend region_start: " << region.name diff --git a/src/backends/default/default.hpp b/src/backends/default/default.hpp index 4e2cda3..0d60ad2 100644 --- a/src/backends/default/default.hpp +++ b/src/backends/default/default.hpp @@ -3,8 +3,15 @@ class NPNDefault : public NotProperlyNestedAnnotationStrategy { public: - NPNDefault(); - inline static const std::string name = "Default"; + NPNDefault() : NotProperlyNestedAnnotationStrategy() {} + + inline static const struct StrategyDescription description = { + .name = "Default", + .description = "TODO", + .parallelism_descriptor = { + .mpi_descriptor = MPIDescriptor::DontCare, + .thread_descriptor = ThreadDescriptor::Supported}}; + virtual void RegionStart(const NotProperlyNestedRegionInformation &info_to_start) noexcept override; virtual void RegionStop( @@ -12,8 +19,12 @@ class NPNDefault : public NotProperlyNestedAnnotationStrategy { virtual void Init() noexcept; virtual void Finalize() noexcept; + struct StrategyDescription getDescription() const noexcept override { + return description; + } + EnvironmentVariableStorage getEnvironmentVariablesDescription() - const noexcept { + const noexcept override { EnvironmentVariableStorage storage; return storage; } diff --git a/src/backends/detection/CMakeLists.txt b/src/backends/detection/CMakeLists.txt index e7f4975..2bccf91 100644 --- a/src/backends/detection/CMakeLists.txt +++ b/src/backends/detection/CMakeLists.txt @@ -1 +1,2 @@ target_sources(nesmik PRIVATE detection.cpp) +target_sources(nesmik PRIVATE detection.cpp) diff --git a/src/backends/detection/detection.cpp b/src/backends/detection/detection.cpp index 2be1c92..33fc284 100644 --- a/src/backends/detection/detection.cpp +++ b/src/backends/detection/detection.cpp @@ -56,11 +56,6 @@ double getTimeStamp() { #endif } -DetectionStrategy::DetectionStrategy() : mpi_helper_{} { - parallelism_descriptor_ = {.mpi_descriptor_ = MPIDescriptor::Aware, - .thread_descriptor_ = ThreadDescriptor::Supported}; -} - void DetectionStrategy::Init() noexcept {} void DetectionStrategy::RegionStart( diff --git a/src/backends/detection/detection.hpp b/src/backends/detection/detection.hpp index daa86c3..c25efd8 100644 --- a/src/backends/detection/detection.hpp +++ b/src/backends/detection/detection.hpp @@ -45,17 +45,33 @@ class DetectionStrategy : public ProperlyNestedAnnotationStrategy { bool has_errors_ = false; public: - DetectionStrategy(); - inline static const std::string name = "Detection"; + DetectionStrategy() : mpi_helper_{} {} + + inline static const struct StrategyDescription description = { + .name = "Detection", + .description = + "automatically detect the nesting mode (ProperlyNested or " + "NotProperlyNested) and find which regions break the ProperlyNested " + "if aplicable.", + .parallelism_descriptor = { + .mpi_descriptor = MPIDescriptor::Aware, + .thread_descriptor = ThreadDescriptor::Supported}}; + virtual void RegionStart( const ProperlyNestedRegionInformation& region) noexcept override; virtual void RegionStopLast( const ProperlyNestedRegionInformation& region) noexcept override; virtual void Init() noexcept; virtual void Finalize() noexcept; + + struct StrategyDescription getDescription() const noexcept override { + return description; + } + EnvironmentVariableStorage getEnvironmentVariablesDescription() - const noexcept { + const noexcept override { EnvironmentVariableStorage storage; + storage.add(verbose_mode_); return storage; } }; diff --git a/src/backends/dlb_talp/dlb_talp.cpp b/src/backends/dlb_talp/dlb_talp.cpp index 3f1d71c..d6eb62c 100644 --- a/src/backends/dlb_talp/dlb_talp.cpp +++ b/src/backends/dlb_talp/dlb_talp.cpp @@ -3,14 +3,6 @@ #include #include -DLBTalpStrategy::DLBTalpStrategy() { - parallelism_descriptor_ = { - .mpi_descriptor_ = MPIDescriptor::DontCare, - .thread_descriptor_ = ThreadDescriptor::Supported // Even though it makes - // no semantical sense - }; -} - void DLBTalpStrategy::RegionStart( const NotProperlyNestedRegionInformation ®ion) noexcept { dlb_wrapper_.StartMonitoringRegion(std::string(region.name)); diff --git a/src/backends/dlb_talp/dlb_talp.hpp b/src/backends/dlb_talp/dlb_talp.hpp index 7268ed9..ca743a9 100644 --- a/src/backends/dlb_talp/dlb_talp.hpp +++ b/src/backends/dlb_talp/dlb_talp.hpp @@ -8,16 +8,31 @@ class DLBTalpStrategy : public NotProperlyNestedAnnotationStrategy { public: DLBWrapper dlb_wrapper_; - DLBTalpStrategy(); - inline static const std::string name = "TALP"; + DLBTalpStrategy() {} + + inline static const struct StrategyDescription description = { + .name = "TALP", + .description = "a backend that directly wraps the TALP API.", + .parallelism_descriptor = { + .mpi_descriptor = MPIDescriptor::DontCare, + .thread_descriptor = + ThreadDescriptor::Supported // Even though it makes + // no semantical sense + }}; + virtual void RegionStart( const NotProperlyNestedRegionInformation ®ion) noexcept override; virtual void RegionStop( const NotProperlyNestedRegionInformation ®ion) noexcept override; virtual void Init() noexcept; virtual void Finalize() noexcept; + + struct StrategyDescription getDescription() const noexcept override { + return description; + } + EnvironmentVariableStorage getEnvironmentVariablesDescription() - const noexcept { + const noexcept override { EnvironmentVariableStorage storage; return storage; } diff --git a/src/backends/dlb_talp_tree/dlb_talp_tree.cpp b/src/backends/dlb_talp_tree/dlb_talp_tree.cpp index 9f6a0f8..43b5026 100644 --- a/src/backends/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb_talp_tree/dlb_talp_tree.cpp @@ -23,16 +23,6 @@ using json = nlohmann::json; -DLBTalpTreeStrategy::DLBTalpTreeStrategy() : mpi_helper_{} { - // description = { - // .name_ = "TALP::Tree", - // .description_ = "asdfkj;laksdf", - // .parallelism_descriptor_ = - // .mpi_descriptor_ = MPIDescriptor::Aware, - // .thread_descriptor_ = ThreadDescriptor::Unsupported} - // } -} - std::string region_hash_to_string(std::size_t region_hash) { // We need to cast the std::size_t before conversion to get // decimal representation in the string. diff --git a/src/backends/dlb_talp_tree/dlb_talp_tree.hpp b/src/backends/dlb_talp_tree/dlb_talp_tree.hpp index 37962d7..46aaf05 100644 --- a/src/backends/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb_talp_tree/dlb_talp_tree.hpp @@ -42,7 +42,7 @@ class DLBTalpTreeStrategy : public ProperlyNestedAnnotationStrategy { inline static const bool def_enable_json_ = true; EnvironmentVariable env_enable_json_ = EnvironmentVariable( - "JSON_OUTPUT", "Enables output to a JSON file.", false); + "JSON_OUTPUT", "Enables output to a JSON file. (default: on)", false); inline static const bool def_enable_ascii_ = false; EnvironmentVariable env_enable_ascii_ = EnvironmentVariable( @@ -51,8 +51,17 @@ class DLBTalpTreeStrategy : public ProperlyNestedAnnotationStrategy { false); public: - DLBTalpTreeStrategy(); - inline static const std::string name = "TALP::Tree"; + DLBTalpTreeStrategy() : mpi_helper_{} {} + + inline static const struct StrategyDescription description = { + .name = "TALP::Tree", + .description = + "creates TALP regions differantiating regions by \"callpath\", and " + "reporting the metrics values as well as the region hierarchy.", + .parallelism_descriptor = { + .mpi_descriptor = MPIDescriptor::Aware, + .thread_descriptor = ThreadDescriptor::Unsupported}}; + void RegionStart( const ProperlyNestedRegionInformation ®ion) noexcept override; void RegionStopLast( @@ -60,12 +69,16 @@ class DLBTalpTreeStrategy : public ProperlyNestedAnnotationStrategy { virtual void Init() noexcept; virtual void Finalize() noexcept; + struct StrategyDescription getDescription() const noexcept override { + return description; + } + EnvironmentVariableStorage getEnvironmentVariablesDescription() - const noexcept { + const noexcept override { EnvironmentVariableStorage storage; - storage.add(env_json_file_name_); - storage.add(env_enable_json_); storage.add(env_enable_ascii_); + storage.add(env_enable_json_); + storage.add(env_json_file_name_); return storage; } }; diff --git a/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp b/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp index 03bcb7d..1f1384e 100644 --- a/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp +++ b/src/backends/extrae_partial_tracer/extrae_partial_tracer.cpp @@ -2,23 +2,12 @@ #include #include -#include #include extern "C" { #include } #include -ExtraePartialTracer::ExtraePartialTracer() - : mpi_helper_{}, extrae_wrapper_{state_type_} { - parallelism_descriptor_ = { - .mpi_descriptor_ = MPIDescriptor::Aware, - .thread_descriptor_ = ThreadDescriptor::Unsupported}; - - type_stack_strategy_ = std::make_unique(); - extrae_wrapper_.RegisterTypeWithDescription(type_description_, state_type_); -} - void ExtraePartialTracer::shutdown(bool annotate) noexcept { if (debug_output_.getValue().value_or(false) && mpi_helper_.IsRankNumber(0)) { std::cout << "neSmiK Partial Tracer: Shutting down" << std::endl; diff --git a/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp b/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp index 7feb612..dc51e4c 100644 --- a/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp +++ b/src/backends/extrae_partial_tracer/extrae_partial_tracer.hpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -35,8 +36,8 @@ class ExtraePartialTracer : public ProperlyNestedAnnotationStrategy { "should stop", true); - EnvironmentVariable debug_output_ = - EnvironmentVariable("PARTIAL_TRACER_DEBUG", "DEBUG output", false); + EnvironmentVariable debug_output_ = EnvironmentVariable( + "PARTIAL_TRACER_DEBUG", "prints debug information", false); EnvironmentVariable write_config_file_ = EnvironmentVariable( "EXTRAE_WRITE_CONFIG_FILE", @@ -61,8 +62,17 @@ class ExtraePartialTracer : public ProperlyNestedAnnotationStrategy { const std::string type_description_ = "Extrae::PartialTracer State"; public: - ExtraePartialTracer(); - inline static const std::string name = "Extrae::PartialTracer"; + ExtraePartialTracer() : mpi_helper_{}, extrae_wrapper_{state_type_} { + type_stack_strategy_ = std::make_unique(); + extrae_wrapper_.RegisterTypeWithDescription(type_description_, state_type_); + } + + inline static const struct StrategyDescription description = { + .name = "Extrae::PartialTracer", + .description = "TODO", + .parallelism_descriptor = { + .mpi_descriptor = MPIDescriptor::Aware, + .thread_descriptor = ThreadDescriptor::Unsupported}}; virtual void RegionStart( const ProperlyNestedRegionInformation ®ion) noexcept override; @@ -71,9 +81,18 @@ class ExtraePartialTracer : public ProperlyNestedAnnotationStrategy { virtual void Init() noexcept override; virtual void Finalize() noexcept override; + struct StrategyDescription getDescription() const noexcept override { + return description; + } + EnvironmentVariableStorage getEnvironmentVariablesDescription() - const noexcept { + const noexcept override { EnvironmentVariableStorage storage; + storage.add(region_names_env_); + storage.add(regions_start_at_env_); + storage.add(regions_stop_at_env_); + storage.add(debug_output_); + storage.add(write_config_file_); return storage; } }; diff --git a/src/backends/extrae_type_stack/extrae_type_stack.cpp b/src/backends/extrae_type_stack/extrae_type_stack.cpp index ebd59c6..4352d86 100644 --- a/src/backends/extrae_type_stack/extrae_type_stack.cpp +++ b/src/backends/extrae_type_stack/extrae_type_stack.cpp @@ -20,13 +20,6 @@ inline std::string getLevelString(const std::size_t level) { return "Level: " + std::to_string(level); } -ExtraeTypeStackStrategy::ExtraeTypeStackStrategy() - : mpi_helper_{}, extrae_wrapper_{base_type_} { - parallelism_descriptor_ = { - .mpi_descriptor_ = MPIDescriptor::Aware, - .thread_descriptor_ = ThreadDescriptor::Unsupported}; -} - void ExtraeTypeStackStrategy::Init() noexcept { // initialize the stack levels up to MAX_STACK_LEVELS for (std::size_t i = 0; i < MAX_STACK_LEVELS; i++) { diff --git a/src/backends/extrae_type_stack/extrae_type_stack.hpp b/src/backends/extrae_type_stack/extrae_type_stack.hpp index 7828856..5147043 100644 --- a/src/backends/extrae_type_stack/extrae_type_stack.hpp +++ b/src/backends/extrae_type_stack/extrae_type_stack.hpp @@ -18,7 +18,8 @@ class ExtraeTypeStackStrategy : public ProperlyNestedAnnotationStrategy { EnvironmentVariable write_config_file_ = EnvironmentVariable( "EXTRAE_WRITE_CONFIG_FILE", - "Write corresponding Paraver .cfg file if set to True", false); + "Write corresponding Paraver .cfg file when enabled. (default: off)", + false); MPIHelper mpi_helper_; ExtraeWrapper extrae_wrapper_; @@ -28,8 +29,14 @@ class ExtraeTypeStackStrategy : public ProperlyNestedAnnotationStrategy { std::size_t max_stack_size{0}; public: - ExtraeTypeStackStrategy(); - inline static const std::string name = "Extrae::TypeStack"; + ExtraeTypeStackStrategy() : mpi_helper_{}, extrae_wrapper_{base_type_} {} + + inline static const struct StrategyDescription description = { + .name = "Extrae::TypeStack", + .description = "TODO", + .parallelism_descriptor = { + .mpi_descriptor = MPIDescriptor::Aware, + .thread_descriptor = ThreadDescriptor::Unsupported}}; virtual void RegionStart( const ProperlyNestedRegionInformation ®ion) noexcept override; @@ -37,9 +44,15 @@ class ExtraeTypeStackStrategy : public ProperlyNestedAnnotationStrategy { const ProperlyNestedRegionInformation ®ion) noexcept override; virtual void Init() noexcept override; virtual void Finalize() noexcept override; + + struct StrategyDescription getDescription() const noexcept override { + return description; + } + EnvironmentVariableStorage getEnvironmentVariablesDescription() - const noexcept { + const noexcept override { EnvironmentVariableStorage storage; + storage.add(write_config_file_); return storage; } }; diff --git a/src/delegator.cpp b/src/delegator.cpp index d9e8e9c..02e7f38 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -24,29 +24,29 @@ void Delegator::InitNonProperlyNestedBackends(const std::string &backend) { // check if backend is supplied - if (backend.compare(NPNDefault::name) == 0) { + if (backend.compare(NPNDefault::description.name) == 0) { npn_annotation_strategy_ = std::make_unique(); } #ifdef ENABLE_DLB - else if (backend.compare(DLBTalpStrategy::name) == 0) { + else if (backend.compare(DLBTalpStrategy::description.name) == 0) { npn_annotation_strategy_ = std::make_unique(); } #endif } void Delegator::TryInitProperlyNestedBackend(const std::string &backend) { - if (backend.compare(DetectionStrategy::name) == 0) { + if (backend.compare(DetectionStrategy::description.name) == 0) { pn_annotation_strategy_ = std::make_unique(); } #ifdef ENABLE_EXTRAE - else if (backend.compare(ExtraeTypeStackStrategy::name) == 0) { + else if (backend.compare(ExtraeTypeStackStrategy::description.name) == 0) { pn_annotation_strategy_ = std::make_unique(); - } else if (backend.compare(ExtraePartialTracer::name) == 0) { + } else if (backend.compare(ExtraePartialTracer::description.name) == 0) { pn_annotation_strategy_ = std::make_unique(); } #endif #ifdef ENABLE_DLB - else if (backend.compare(DLBTalpTreeStrategy::name) == 0) { + else if (backend.compare(DLBTalpTreeStrategy::description.name) == 0) { pn_annotation_strategy_ = std::make_unique(); } #endif @@ -54,12 +54,12 @@ void Delegator::TryInitProperlyNestedBackend(const std::string &backend) { const std::vector Delegator::available_backends = { #ifdef ENABLE_DLB - DLBTalpTreeStrategy::name, - DLBTalpStrategy::name, + DLBTalpTreeStrategy::description.name, + DLBTalpStrategy::description.name, #endif #ifdef ENABLE_EXTRAE - ExtraeTypeStackStrategy::name, - ExtraePartialTracer::name, + ExtraeTypeStackStrategy::description.name, + ExtraePartialTracer::description.name, #endif "Default", "Detection"}; diff --git a/src/nesmik_app.cpp b/src/nesmik_app.cpp index 5220201..a1a8697 100644 --- a/src/nesmik_app.cpp +++ b/src/nesmik_app.cpp @@ -1,12 +1,143 @@ +#include +#include #include +#include +#include #include +#include + +void printWithIndentation(int level, std::string text) { + std::string indentation = std::string(level * 4, ' '); + + std::stringstream ss(text); + std::string word; + + bool new_line = true; + int max_width = 100; + int cur_width = 0; + while (ss >> word) { + // Check if word fits + if (cur_width + word.size() > max_width) { + std::cout << std::endl; // Break the line + cur_width = 0; + new_line = true; + } + + if (new_line) { + new_line = false; + + std::cout << indentation; // Add the indentation + cur_width += indentation.size(); + // If the word still does not fit, we have a problem + if (cur_width + word.size() > max_width) { + std::cout << std::endl << std::endl; + std::cout << "Fatal: Cannot fit text with this level of indentation. " + "Next word was: " + << word << std::endl + << std::endl; + } + } + + // Add the word + std::cout << word << ' '; + cur_width += word.size() + 1; + } + std::cout << std::endl; +} + +void printStrategyUsage(struct StrategyDescription description, + EnvironmentVariableStorage variables) { + printWithIndentation(1, description.name); + std::cout << std::endl; + + printWithIndentation(2, description.description); + std::cout << std::endl; + + printWithIndentation(2, "FEATURES"); + printWithIndentation( + 3, "MPI:\t" + MPIDescriptorUsage( + description.parallelism_descriptor.mpi_descriptor) + .getName()); + printWithIndentation( + 3, + "Threading:\t" + ThreadDescriptorUsage( + description.parallelism_descriptor.thread_descriptor) + .getName()); + std::cout << std::endl; + + if (variables.getSize() > 0) { + printWithIndentation(2, "ENVIRONMENT VARIABLES"); + std::cout << std::endl; + + for (auto var_desc : variables) { + std::string indicator = ""; + if (var_desc.required_) indicator = "(required)"; + + printWithIndentation( + 2, "NESMIK_" + var_desc.variable_name_ + " " + indicator); + printWithIndentation(3, var_desc.description_); + std::cout << std::endl; + } + } +} void showUsages() { - DLBTalpTreeStrategy dlb_talp_tree_strategy; - for (auto description : - dlb_talp_tree_strategy.getEnvironmentVariablesDescription()) { - std::cout << description.variable_name_ << ": " << description.description_ - << std::endl; + std::cout << std::endl; + printWithIndentation( + 0, + "To use the neSmiK annotations of your code set the NESMIK_BACKEND " + "environment variable to the desired backend name. When this variable is " + "not set calls to the neSmiK API have no effect."); + std::cout << std::endl; + std::cout << std::endl; + printWithIndentation(0, + "Following you will find all the available backends " + "names, their description and usage guide."); + std::cout << std::endl; + std::cout << std::endl; + + { + DetectionStrategy strategy; + printStrategyUsage(strategy.getDescription(), + strategy.getEnvironmentVariablesDescription()); + } + + std::cout << std::endl + << "Following you will find backends that support both kinds of " + "annotations." + << std::endl; + + { + NPNDefault strategy; + printStrategyUsage(strategy.getDescription(), + strategy.getEnvironmentVariablesDescription()); + } + + { + DLBTalpStrategy strategy; + printStrategyUsage(strategy.getDescription(), + strategy.getEnvironmentVariablesDescription()); + } + + std::cout << "Following you will find backends that require ProperlyNested " + "annotation." + << std::endl; + + { + ExtraeTypeStackStrategy strategy; + printStrategyUsage(strategy.getDescription(), + strategy.getEnvironmentVariablesDescription()); + } + { + ExtraePartialTracer strategy; + printStrategyUsage(strategy.getDescription(), + strategy.getEnvironmentVariablesDescription()); + } + + { + DLBTalpTreeStrategy strategy; + printStrategyUsage(strategy.getDescription(), + strategy.getEnvironmentVariablesDescription()); } } diff --git a/src/strategies.hpp b/src/strategies.hpp index 392803d..e94968d 100644 --- a/src/strategies.hpp +++ b/src/strategies.hpp @@ -10,11 +10,37 @@ /* Describes the Strategy behavior with respect to MPI. */ -enum class MPIDescriptor { - DontCare, // Strategy does not know and does not care - Aware, // Strategy knows about MPI and can use the PMPI Interface to do e.g. - // reductions. - Required // Strategy requires MPI (should be safeguareded by build options) +enum class MPIDescriptor { DontCare, Aware, Required }; + +class MPIDescriptorUsage { + public: + MPIDescriptor descriptor; + + MPIDescriptorUsage(MPIDescriptor descriptor) : descriptor(descriptor) {} + + std::string getName() const { + switch (descriptor) { + case MPIDescriptor::DontCare: + return "Don't care"; + case MPIDescriptor::Aware: + return "Aware"; + case MPIDescriptor::Required: + return "Required"; + } + } + + std::string getDescription() const { + switch (descriptor) { + case MPIDescriptor::DontCare: + return "the strategy does not know if MPI is present but can support " + "it."; + case MPIDescriptor::Aware: + return "the strategy will know if MPI is present and when present " + "might enable features."; + case MPIDescriptor::Required: + return "the strategy requires MPI to be present."; + } + } }; /* @@ -24,12 +50,38 @@ enum class MPIDescriptor { */ enum class ThreadDescriptor { Supported, Unsupported }; +class ThreadDescriptorUsage { + public: + ThreadDescriptor descriptor; + ThreadDescriptorUsage(ThreadDescriptor descriptor) : descriptor(descriptor) {} + + std::string getName() const { + switch (descriptor) { + case ThreadDescriptor::Supported: + return "Supported"; + case ThreadDescriptor::Unsupported: + return "Unsupported"; + } + } + + std::string getDescription() const { + switch (descriptor) { + case ThreadDescriptor::Supported: + return "the strategy supports starting and closing regions from " + "multiple threads."; + case ThreadDescriptor::Unsupported: + return "the strategy does NOT supports starting and closing regions " + "from multiple threads."; + } + } +}; + /* Bundles the above enums into a nice struct */ struct ParallelismDescriptor { - MPIDescriptor mpi_descriptor_ = MPIDescriptor::DontCare; - ThreadDescriptor thread_descriptor_ = ThreadDescriptor::Unsupported; + MPIDescriptor mpi_descriptor = MPIDescriptor::DontCare; + ThreadDescriptor thread_descriptor = ThreadDescriptor::Unsupported; }; struct ProperlyNestedRegionInformation { @@ -41,15 +93,16 @@ struct NotProperlyNestedRegionInformation { std::string_view name; }; -// struct StrategyDescription { -// std::string name_; -// std::string description_; -// ParallelismDescriptor parallelism_descriptor; -// }; +struct StrategyDescription { + std::string name; + std::string description; + ParallelismDescriptor parallelism_descriptor; +}; // A backend implementing the Properly Nested Profiling class ProperlyNestedAnnotationStrategy { public: + ProperlyNestedAnnotationStrategy() {} virtual ~ProperlyNestedAnnotationStrategy() = default; virtual void Init() noexcept = 0; virtual void RegionStart( @@ -58,28 +111,25 @@ class ProperlyNestedAnnotationStrategy { const ProperlyNestedRegionInformation ®ion) noexcept = 0; virtual void Finalize() noexcept = 0; - // virtual const &StrategyDescription getDescription() const noexcept = 0; + virtual struct StrategyDescription getDescription() const noexcept = 0; virtual EnvironmentVariableStorage getEnvironmentVariablesDescription() const noexcept = 0; - - ParallelismDescriptor parallelism_descriptor_; }; class NotProperlyNestedAnnotationStrategy { public: - virtual void Init() noexcept = 0; + NotProperlyNestedAnnotationStrategy() {} virtual ~NotProperlyNestedAnnotationStrategy() = default; + virtual void Init() noexcept = 0; virtual void RegionStart( const NotProperlyNestedRegionInformation ®ion) noexcept = 0; virtual void RegionStop( const NotProperlyNestedRegionInformation ®ion) noexcept = 0; virtual void Finalize() noexcept = 0; - // virtual const &StrategyDescription getDescription() const noexcept = 0; - // virtual EnvironmentVariableStorage& getEnvironmentVariablesDescription() - // const noexcept = 0; - - ParallelismDescriptor parallelism_descriptor_; + virtual struct StrategyDescription getDescription() const noexcept = 0; + virtual EnvironmentVariableStorage getEnvironmentVariablesDescription() + const noexcept = 0; }; #endif // NESMIK_STRATEGY_HPP diff --git a/src/utils/environment_variable.hpp b/src/utils/environment_variable.hpp index 4690bc8..6e466c8 100644 --- a/src/utils/environment_variable.hpp +++ b/src/utils/environment_variable.hpp @@ -28,11 +28,14 @@ class EnvironmentVariableDescription { public: std::string variable_name_; std::string description_; + bool required_; EnvironmentVariableDescription() {} EnvironmentVariableDescription(std::string variable_name, - std::string description) - : variable_name_(variable_name), description_(description) {} + std::string description, bool required) + : variable_name_(variable_name), + description_(description), + required_(required) {} }; template @@ -45,7 +48,7 @@ class EnvironmentVariable : public EnvironmentVariableDescription { */ EnvironmentVariable(const std::string &variable_name, const std::string &description, bool required = false) - : EnvironmentVariableDescription(PREFIX + variable_name, description) { + : EnvironmentVariableDescription(variable_name, description, required) { const std::string variable_to_query = EnvironmentVariable::PREFIX + variable_name_; @@ -54,11 +57,13 @@ class EnvironmentVariable : public EnvironmentVariableDescription { if (env_string != nullptr) { value_ = fromEnvString(std::string(env_string)); } +#ifndef NESMIK_APP if (required && !value_.has_value()) { std::cout << "neSmiK Error: " << variable_to_query << " not set, restart application and set it" << std::endl; exit(1); } +#endif } EnvironmentVariable() = delete; @@ -83,6 +88,8 @@ class EnvironmentVariableStorage { storage_.push_back(description); } + std::size_t getSize() const { return storage_.size(); } + auto begin() { return storage_.begin(); } auto end() { return storage_.end(); } }; -- GitLab From a822ea423947eed46c1020f876d333fb7c9b823c Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Mon, 21 Oct 2024 20:20:26 +0200 Subject: [PATCH 3/6] Add create backend template. --- src/nesmik_app.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++- src/strategies.hpp | 4 ++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/nesmik_app.cpp b/src/nesmik_app.cpp index a1a8697..d99267b 100644 --- a/src/nesmik_app.cpp +++ b/src/nesmik_app.cpp @@ -81,6 +81,31 @@ void printStrategyUsage(struct StrategyDescription description, } } +void printStrategyTemplate(struct StrategyDescription description, + EnvironmentVariableStorage variables) { + std::cout << "# This is an autogenerated template for the " + << description.name << " backend." << std::endl; + std::cout << "# Optional variables are commented." << std::endl; + std::cout << std::endl; + std::cout << "export NESMIK_BACKEND=\"" << description.name << "\"" + << std::endl; + std::cout << std::endl; + + if (variables.getSize() > 0) { + for (auto var_desc : variables) { + std::cout << "# " << var_desc.description_ << std::endl; + + std::string required = "# "; + if (var_desc.required_) { + required = ""; + } + std::cout << required << "export NESMIK_" << var_desc.variable_name_ + << "=" << std::endl; + std::cout << std::endl; + } + } +} + void showUsages() { std::cout << std::endl; printWithIndentation( @@ -141,4 +166,24 @@ void showUsages() { } } -int main() { showUsages(); } +int main() { + // Display the ussage. + // TODO: Add command line options to pick what ussage to print. + // Options are: + // - Print all the usage. (Done) + // - Print just a lies with all backends and their theseriptions. + // - Print the usage for one backend. + // - Print a template for just one backend. + // Example of how to print a template + // std::cout << std::endl; + // { + // ExtraePartialTracer strategy; + // printStrategyTemplate(strategy.getDescription(), + // strategy.getEnvironmentVariablesDescription()); + // } + // + // ------------------------ + // + // Print all the usage! + showUsages(); +} diff --git a/src/strategies.hpp b/src/strategies.hpp index e94968d..a84c27a 100644 --- a/src/strategies.hpp +++ b/src/strategies.hpp @@ -27,6 +27,7 @@ class MPIDescriptorUsage { case MPIDescriptor::Required: return "Required"; } + return ""; } std::string getDescription() const { @@ -40,6 +41,7 @@ class MPIDescriptorUsage { case MPIDescriptor::Required: return "the strategy requires MPI to be present."; } + return ""; } }; @@ -62,6 +64,7 @@ class ThreadDescriptorUsage { case ThreadDescriptor::Unsupported: return "Unsupported"; } + return ""; } std::string getDescription() const { @@ -73,6 +76,7 @@ class ThreadDescriptorUsage { return "the strategy does NOT supports starting and closing regions " "from multiple threads."; } + return ""; } }; -- GitLab From 0a63ffc464b7a7c03bab36408f9969ec390d6ee1 Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Tue, 22 Oct 2024 16:02:04 +0200 Subject: [PATCH 4/6] Fix CMake to link with the nlohmann_json --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 576b117..2e4dea4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,6 +108,7 @@ if(ENABLE_EXTRAE) # We link publicy with seqtrace, as we need it to be in the right order to # libc to find malloc with dlsym .. target_link_libraries(nesmik_extrae PUBLIC ${EXTRAE_LIBRARIES}) + target_compile_definitions(nesmik_lib PRIVATE "ENABLE_EXTRAE") target_compile_definitions(nesmik_extrae PRIVATE "ENABLE_EXTRAE") # And link libnesmik.so with it. target_link_libraries(nesmik_lib PRIVATE nesmik_extrae) @@ -131,7 +132,12 @@ if(ENABLE_DLB) PRIVATE ${DLB_INCLUDE_DIRS}) target_link_libraries(nesmik_dlb PRIVATE ${DLB_LIBRARIES}) + # TODO: Remove when the DLB wrapper fully decouples TALP structs. + target_include_directories(nesmik_lib + PRIVATE ${DLB_INCLUDE_DIRS}) + # Enable DLB guards + target_compile_definitions(nesmik_lib PRIVATE "ENABLE_DLB") target_compile_definitions(nesmik_dlb PRIVATE "ENABLE_DLB") # Link libnesmik.so with DLB -- GitLab From 739e0475a4ae04b505b7649b47b7b3d0f152e0ed Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Tue, 22 Oct 2024 14:41:49 +0200 Subject: [PATCH 5/6] Fix dlb_wrapper compiler error --- src/backends/wrappers/dlb/dlb_wrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/wrappers/dlb/dlb_wrapper.cpp b/src/backends/wrappers/dlb/dlb_wrapper.cpp index d21d36d..baf56c7 100644 --- a/src/backends/wrappers/dlb/dlb_wrapper.cpp +++ b/src/backends/wrappers/dlb/dlb_wrapper.cpp @@ -22,7 +22,7 @@ void DLBWrapper::StartMonitoringRegion(std::string region_name) { void DLBWrapper::StopMonitoringRegion(std::string region_name) { #if defined(ENABLE_DLB) - auto handle = DLB_MonitoringRegionRegister(region.name.c_str()); + auto handle = DLB_MonitoringRegionRegister(region_name.c_str()); DLB_MonitoringRegionStop(handle); #endif } -- GitLab From 2ae3875d80c7c677fba8d610ec55bfb6b79f65bf Mon Sep 17 00:00:00 2001 From: JOAN VINYALS YLLA CATALA Date: Tue, 22 Oct 2024 16:05:29 +0200 Subject: [PATCH 6/6] Fix CMake to run tests correctly Add Detection backend test fix Fix detection backend --- tests/CMakeLists.txt | 113 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 98 insertions(+), 15 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2ac8198..de6a796 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,44 +1,53 @@ + +# +# Add generic tests +# add_executable(TestCppLink cpp/TestCppLink.cpp) -target_link_libraries(TestCppLink nesmik::nesmik) +target_link_libraries(TestCppLink nesmik_lib) target_include_directories(TestCppLink PRIVATE ${NESMIK_PUBLIC_HEADERS}) -add_test(NAME TestCppLink - COMMAND TestCppLink) - +add_test(NAME TestCppLinkDefault COMMAND TestCppLink) +add_test(NAME TestCppLinkDetection COMMAND TestCppLink) add_executable(TestRegionStopLast cpp/TestRegionStopLast.cpp) -target_link_libraries(TestRegionStopLast nesmik::nesmik) +target_link_libraries(TestRegionStopLast nesmik_lib) target_include_directories(TestRegionStopLast PRIVATE ${NESMIK_PUBLIC_HEADERS}) add_test(NAME TestRegionStopLast COMMAND TestRegionStopLast) +add_executable(TestCppNotNested cpp/TestCppNotNested.cpp) +target_link_libraries(TestCppNotNested nesmik_lib) +target_include_directories(TestCppNotNested + PRIVATE ${NESMIK_PUBLIC_HEADERS}) +add_test(NAME TestCppLinkNotNested COMMAND TestCppNotNested) if(ENABLE_DLB) add_executable(TestCppDLB cpp/TestCppDLB.cpp) -target_link_libraries(TestCppDLB nesmik::nesmik) +target_link_libraries(TestCppDLB nesmik_lib) target_include_directories(TestCppDLB PRIVATE ${NESMIK_PUBLIC_HEADERS}) add_test(NAME TestCppDLB - COMMAND TestCppDLB) + COMMAND TestCppDLB) + add_executable(TestCppTalpTree cpp/TestCppTalpTree.cpp) -target_link_libraries(TestCppTalpTree nesmik::nesmik) +target_link_libraries(TestCppTalpTree nesmik_lib) target_include_directories(TestCppTalpTree PRIVATE ${NESMIK_PUBLIC_HEADERS}) add_test(NAME TestCppTalpTree - COMMAND TestCppTalpTree) + COMMAND TestCppTalpTree) endif() if(WITH_MPI AND WITH_MPI_TESTS) add_executable(TestCppTalpTreeMPI cpp/TestCppTalpTreeMPI.cpp) - target_link_libraries(TestCppTalpTreeMPI nesmik::nesmik MPI::MPI_CXX) + target_link_libraries(TestCppTalpTreeMPI nesmik_lib MPI::MPI_CXX) target_include_directories(TestCppTalpTreeMPI PRIVATE ${NESMIK_PUBLIC_HEADERS}) @@ -46,7 +55,7 @@ if(WITH_MPI AND WITH_MPI_TESTS) COMMAND TestCppTalpTree) add_executable(TestCppTalpTreeMPI_MPMD cpp/TestCppTalpTreeMPI_MPMD.cpp) - target_link_libraries(TestCppTalpTreeMPI_MPMD nesmik::nesmik MPI::MPI_CXX) + target_link_libraries(TestCppTalpTreeMPI_MPMD nesmik_lib MPI::MPI_CXX) target_include_directories(TestCppTalpTreeMPI_MPMD PRIVATE ${NESMIK_PUBLIC_HEADERS}) @@ -59,12 +68,13 @@ endif() if(ENABLE_EXTRAE) add_executable(TestCppExtraeTypeStack cpp/TestCppExtraeTypeStack.cpp) -target_link_libraries(TestCppExtraeTypeStack nesmik::nesmik) +target_link_libraries(TestCppExtraeTypeStack nesmik_lib) target_include_directories(TestCppExtraeTypeStack PRIVATE ${NESMIK_PUBLIC_HEADERS}) add_test(NAME TestCppExtraeTypeStack - COMMAND TestCppExtraeTypeStack) + COMMAND TestCppExtraeTypeStack) + endif() @@ -81,8 +91,6 @@ if(BUILD_C_FORTRAN) COMMAND TestCLink) - - add_executable(TestFortranLink fortran/TestFortranModule.f90) if(SPLIT_FORTRAN_LIBRARY) target_link_libraries(TestFortranLink nesmik nesmik_f) @@ -95,4 +103,79 @@ if(BUILD_C_FORTRAN) add_test(NAME TestFortranLink COMMAND TestFortranLink) + +endif() + +set_property(TEST TestCppLinkDefault PROPERTY ENVIRONMENT "NESMIK_BACKEND=Default") + +set_property(TEST TestCppLinkDetection PROPERTY ENVIRONMENT "NESMIK_BACKEND=Detection") + +set_property(TEST TestRegionStopLast PROPERTY ENVIRONMENT "NESMIK_BACKEND=Detection") + +set_property(TEST TestCppLinkNotNested PROPERTY ENVIRONMENT "NESMIK_BACKEND=Detection") + +if(ENABLE_EXTRAE) + set_property(TEST TestCppExtraeTypeStack PROPERTY ENVIRONMENT "NESMIK_BACKEND=Extrae::TypeStack;EXTRAE_ON=1;LD_PRELOAD=${EXTRAE_DIR}/lib/libseqtrace.so") +endif() + +if(ENABLE_DLB) +set_property(TEST TestCppDLB PROPERTY ENVIRONMENT "NESMIK_BACKEND=TALP;DLB_ARGS=--talp;LD_PRELOAD=${DLB_HOME}/lib/libdlb.so;") +set_property(TEST TestCppTalpTree PROPERTY ENVIRONMENT "NESMIK_BACKEND=TALP::Tree;DLB_ARGS=--talp;LD_PRELOAD=${DLB_HOME}/lib/libdlb.so;") +endif() + +if(ENABLE_DLB AND WITH_MPI AND WITH_MPI_TESTS) + +endif() + +if(BUILD_C_FORTRAN) + set_property(TEST TestCLink PROPERTY ENVIRONMENT "NESMIK_BACKEND=Detection") + set_property(TEST TestFortranLink PROPERTY ENVIRONMENT "NESMIK_BACKEND=Detection") +endif() + +# +# Disable extrae autoinitialize for all the tests to avoid the malloc error +# +if(ENABLE_EXTRAE) + +set(skip_extrae "EXTRAE_SKIP_AUTO_LIBRARY_INITIALIZE=1") + +get_property(env TEST TestCppLinkDefault PROPERTY ENVIRONMENT) +set_property(TEST TestCppLinkDefault PROPERTY ENVIRONMENT "${env};${skip_extrae}") + +get_property(env TEST TestCppLinkDetection PROPERTY ENVIRONMENT) +set_property(TEST TestCppLinkDetection PROPERTY ENVIRONMENT "${env};${skip_extrae}") + +get_property(env TEST TestRegionStopLast PROPERTY ENVIRONMENT) +set_property(TEST TestRegionStopLast PROPERTY ENVIRONMENT "${env};${skip_extrae}") + +get_property(env TEST TestCppExtraeTypeStack PROPERTY ENVIRONMENT) +set_property(TEST TestCppExtraeTypeStack PROPERTY ENVIRONMENT "${env};${skip_extrae}") + +get_property(env TEST TestCppLinkNotNested PROPERTY ENVIRONMENT) +set_property(TEST TestCppLinkNotNested PROPERTY ENVIRONMENT "${env};${skip_extrae}") + +if(ENABLE_DLB) +get_property(env TEST TestCppDLB PROPERTY ENVIRONMENT) +set_property(TEST TestCppDLB PROPERTY ENVIRONMENT "${env};${skip_extrae}") + +get_property(env TEST TestCppTalpTree PROPERTY ENVIRONMENT) +set_property(TEST TestCppTalpTree PROPERTY ENVIRONMENT "${env};${skip_extrae}") +endif() + +if(ENABLE_DLB AND WITH_MPI AND WITH_MPI_TESTS) +get_property(env TEST TestCppTalpTreeMPI PROPERTY ENVIRONMENT) +set_property(TEST TestCppTalpTreeMPI PROPERTY ENVIRONMENT "${env};${skip_extrae}") + +get_property(env TEST TestCppTalpTreeMPI_MPMD PROPERTY ENVIRONMENT) +set_property(TEST TestCppTalpTreeMPI_MPMD PROPERTY ENVIRONMENT "${env};${skip_extrae}") +endif() + +if(BUILD_C_FORTRAN) +get_property(env TEST TestCLink PROPERTY ENVIRONMENT) +set_property(TEST TestCLink PROPERTY ENVIRONMENT "${env};${skip_extrae}") + +get_property(env TEST TestFortranLink PROPERTY ENVIRONMENT) +set_property(TEST TestFortranLink PROPERTY ENVIRONMENT "${env};${skip_extrae}") +endif() + endif() -- GitLab