diff --git a/README.md b/README.md index ac5a9a86db78b2971a8fb53ef4a49cd2aa477df9..7de28f5370b786dc77fdd3d71db16c0f91a27ba2 100644 --- a/README.md +++ b/README.md @@ -15,19 +15,19 @@ How to configure and install: #include "nesmik/nesmik.hpp" int main() { - nesmik::init("Default"); - nesmik::region_start("peter"); + nesmik::Init("Default"); + nesmik::RegionStart("peter"); - nesmik::region_start("marie"); + nesmik::RegionStart("marie"); - nesmik::region_stop("marie"); + nesmik::RegionStop("marie"); - nesmik::region_stop("peter"); - nesmik::finalize(); + nesmik::RegionStop("peter"); + nesmik::Finalize(); } ``` -You **must** call `nesmik::init` exactly once to init the datastructures before you can use the other functionality. +You **must** call `nesmik::Init` exactly once to Init the datastructures before you can use the other functionality. Also some backends require finalization, so please make sure to also call `finalize` in the end. To add it to your code, currently just install it and use something similar to: @@ -45,16 +45,16 @@ How to configure and install: ```fortran program test use nesmik_mod - call init("Default") - call region_start("test") - call region_stop("test") - call finalize() + call Init("Default") + call RegionStart("test") + call RegionStop("test") + call Finalize() end program test ``` -You **must** call `init` exactly once to init the datastructures before you can use the other functionality. +You **must** call `Init` exactly once to Init the datastructures before you can use the other functionality. Also some backends require finalization, so please make sure to also call `finalize` in the end. To add it to your code, currently just install it and use something similar to: @@ -74,4 +74,4 @@ Please note, that you may have to add the DLB location to the library path, but ### Usage -`nesmik::init("DLB")` +`nesmik::Init("DLB")` diff --git a/include/nesmik/nesmik.hpp b/include/nesmik/nesmik.hpp index bea43755a2c9f82989a368707cb310e13308fda2..e7d14eaf646eb078ff4a6e4a8f33177420e58012 100644 --- a/include/nesmik/nesmik.hpp +++ b/include/nesmik/nesmik.hpp @@ -1,7 +1,7 @@ #include namespace nesmik { -void init(const std::string &backend); +void init(const std::string &nesting_mode, const std::string &backend); void region_start(const std::string &name); void region_stop(const std::string &name); void finalize(); diff --git a/src/backends/default/default.cpp b/src/backends/default/default.cpp index ff113859dc55af2cc14a28aaad511751c50e29b8..d460168a6e98da4715be4adb45436dbd8ca111ed 100644 --- a/src/backends/default/default.cpp +++ b/src/backends/default/default.cpp @@ -3,19 +3,38 @@ #include "default.hpp" -void DefaultStrategy::region_start( - const PNRegionInformation ®ion) noexcept { +void PNDefault::RegionStart( + const ProperlyNestedRegionInformation ®ion) noexcept { std::cout << "Region start: " << region.name << std::endl; } -void DefaultStrategy::region_stop( - const PNRegionInformation ®ion) noexcept { +void PNDefault::RegionStopLast( + const ProperlyNestedRegionInformation ®ion) noexcept { std::cout << "Region stop: " << region.name << std::endl; } -void DefaultStrategy::init() noexcept { - std::cout << "nesmik_init() Backend: Default " << std::endl; +void PNDefault::Init() noexcept { + std::cout << "nesmik::Init() Backend: PN;Default " << std::endl; } -void DefaultStrategy::finalize() noexcept { - std::cout << "nesmik_finalize() Backend: Default " << std::endl; +void PNDefault::Finalize() noexcept { + std::cout << "nesmik::Finalize() Backend: PN;Default " << std::endl; } + +// NPN + +void NPNDefault::RegionStart( + const NotProperlyNestedRegionInformation ®ion) noexcept { + std::cout << "Region start: " << region.name << std::endl; +} + +void NPNDefault::RegionStop( + const NotProperlyNestedRegionInformation ®ion) noexcept { + std::cout << "Region stop: " << region.name << std::endl; +} + +void NPNDefault::Init() noexcept { + std::cout << "nesmik::Init() Backend: NPN;Default " << std::endl; +} +void NPNDefault::Finalize() noexcept { + std::cout << "nesmik::Finalize() Backend: NPN;Default " << std::endl; +} \ No newline at end of file diff --git a/src/backends/default/default.hpp b/src/backends/default/default.hpp index 2160aed56dca6e997a749079862e4b5461b725d2..9d8b8e48cc66a6e47ae93b4f3ace948d7fa4aaeb 100644 --- a/src/backends/default/default.hpp +++ b/src/backends/default/default.hpp @@ -1,12 +1,23 @@ #include "strategies.hpp" #include -class DefaultStrategy : public PNProfilingStrategy { +class PNDefault : public ProperlyNestedAnnotationStrategy { public: - inline static const std::string_view name = "Default"; - void region_start(const PNRegionInformation ®ion) noexcept override; - void region_stop(const PNRegionInformation ®ion) noexcept override; - virtual void init() noexcept; - virtual void finalize() noexcept; + inline static const std::string name = "Default"; + void RegionStart(const ProperlyNestedRegionInformation &info_to_start) noexcept override; + void RegionStopLast(const ProperlyNestedRegionInformation &info_to_stop) noexcept override; + virtual void Init() noexcept; + virtual void Finalize() noexcept; +}; + + +class NPNDefault : public NotProperlyNestedAnnotationStrategy { + +public: + inline static const std::string name = "Default"; + virtual void RegionStart(const NotProperlyNestedRegionInformation &info_to_start) noexcept override; + virtual void RegionStop(const NotProperlyNestedRegionInformation &info_to_stop) noexcept override; + virtual void Init() noexcept; + virtual void Finalize() noexcept; }; diff --git a/src/backends/dlb/dlb/dlb.cpp b/src/backends/dlb/dlb/dlb.cpp index 3c8b5d93da978ec158a6804d2337a917930abf4b..3a7b07607586db3695cda10274b34d6ccd5ded01 100644 --- a/src/backends/dlb/dlb/dlb.cpp +++ b/src/backends/dlb/dlb/dlb.cpp @@ -3,25 +3,26 @@ #include "dlb_talp.h" #include -void DLBTalpStrategy::region_start( - const PNRegionInformation ®ion) noexcept { +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); } -void DLBTalpStrategy::region_stop( - const PNRegionInformation ®ion) noexcept { +void DLBTalpStrategy::RegionStop( + const NotProperlyNestedRegionInformation ®ion) noexcept { auto handle = DLB_MonitoringRegionRegister(std::string(region.name).c_str()); DLB_MonitoringRegionStop(handle); } -void DLBTalpStrategy::init() noexcept { +void DLBTalpStrategy::Init() noexcept { + DLB_Init(0, NULL, "--talp"); std::cout << "nesmik::" << name << " init()" << std::endl; } -void DLBTalpStrategy::finalize() noexcept { +void DLBTalpStrategy::Finalize() noexcept { DLB_Finalize(); - std::cout << "nesmik::" << name << " finalize()" << std::endl; + std::cout << "nesmik::" << name << " Finalize()" << std::endl; } diff --git a/src/backends/dlb/dlb/dlb.hpp b/src/backends/dlb/dlb/dlb.hpp index ebdeb6c14e68cb3d272f673f979ed0cab206bc4d..83201cc72914688be3da9a58e901e9fa182e28b2 100644 --- a/src/backends/dlb/dlb/dlb.hpp +++ b/src/backends/dlb/dlb/dlb.hpp @@ -3,13 +3,13 @@ #include -class DLBTalpStrategy : public PNProfilingStrategy { +class DLBTalpStrategy : public NotProperlyNestedAnnotationStrategy { public: - inline static const std::string_view name = "TALP"; - void region_start(const PNRegionInformation ®ion) noexcept override; - void region_stop(const PNRegionInformation ®ion) noexcept override; - virtual void init() noexcept; - virtual void finalize() noexcept; + inline static const std::string name = "TALP"; + virtual void RegionStart(const NotProperlyNestedRegionInformation ®ion) noexcept override; + virtual void RegionStop(const NotProperlyNestedRegionInformation ®ion) noexcept override; + virtual void Init() noexcept; + virtual void Finalize() noexcept; }; #endif // SIT_DLB_H 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 292cd182753065782539d1541cbc3990fc2b13cf..cefe614e0ff6e776165b6b2c2a36dc360d7ee5af 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.cpp @@ -8,8 +8,8 @@ #include #include -void DLBTalpTreeStrategy::region_start( - const PNRegionInformation ®ion) noexcept { +void DLBTalpTreeStrategy::RegionStart( + const ProperlyNestedRegionInformation ®ion) noexcept { // Construct the opening region hash by joining the name of the region with // the current region (i.e. the parent) hash. @@ -36,11 +36,11 @@ void DLBTalpTreeStrategy::region_start( this->current_region = region_hash; std::string name = std::to_string((unsigned int) region_hash); - this->talp_profiling_strategy.region_start({name}); + this->talp_profiling_strategy.RegionStart({name}); } -void DLBTalpTreeStrategy::region_stop( - const PNRegionInformation ®ion) noexcept { +void DLBTalpTreeStrategy::RegionStopLast( + const ProperlyNestedRegionInformation ®ion) noexcept { auto current_region = this->regions[this->current_region]; @@ -62,10 +62,10 @@ void DLBTalpTreeStrategy::region_stop( this->current_region = current_region.parent; - this->talp_profiling_strategy.region_stop({name}); + this->talp_profiling_strategy.RegionStart({name}); } -void DLBTalpTreeStrategy::init() noexcept { +void DLBTalpTreeStrategy::Init() noexcept { this->current_region = std::hash{}(this->top_region); this->regions[this->current_region] = { @@ -75,12 +75,12 @@ void DLBTalpTreeStrategy::init() noexcept { /* .childs */ {}, }; - this->talp_profiling_strategy.init(); + this->talp_profiling_strategy.Init(); } -void DLBTalpTreeStrategy::finalize() noexcept { +void DLBTalpTreeStrategy::Finalize() noexcept { - this->talp_profiling_strategy.region_stop({.name = this->top_region}); + this->talp_profiling_strategy.RegionStop({.name = this->top_region}); std::size_t max_width = 0; @@ -203,5 +203,5 @@ void DLBTalpTreeStrategy::finalize() noexcept { csv_stream.open("nesmik_talp_tree.csv", std::ios::trunc); csv_stream << region_stream_csv.str() << std::endl; - this->talp_profiling_strategy.finalize(); + 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 d2a58ca5eb6c022b0a627d493f11a8a81a68a0f8..a1c7823364122d5e916c946842ad07b19be93d44 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 PNProfilingStrategy { +class DLBTalpTreeStrategy : public ProperlyNestedAnnotationStrategy { private: DLBTalpStrategy talp_profiling_strategy; @@ -27,10 +27,10 @@ private: public: inline static const std::string_view name = "TALP-Tree"; - void region_start(const PNRegionInformation ®ion) noexcept override; - void region_stop(const PNRegionInformation ®ion) noexcept override; - virtual void init() noexcept; - virtual void finalize() noexcept; + void RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept override; + void RegionStopLast(const ProperlyNestedRegionInformation ®ion) noexcept override; + virtual void Init() noexcept; + virtual void Finalize() noexcept; }; #endif // DLB_TALP_TREE_H diff --git a/src/backends/extrae/extrae_type_stack.cpp b/src/backends/extrae/extrae_type_stack.cpp index 31eb53685c29662c03a2c102656ce83a31f8a3dc..ab690087a4e5dc3384a6d1b823aac0239b571477 100644 --- a/src/backends/extrae/extrae_type_stack.cpp +++ b/src/backends/extrae/extrae_type_stack.cpp @@ -100,7 +100,7 @@ window_filter_module evt_type 1 NESMIK_REPLACE_EVENT_TYPE )"; -void ExtraeTypeStackStrategy::init() noexcept { +void ExtraeTypeStackStrategy::Init() noexcept { auto isInitializedVal = Extrae_is_initialized(); if (isInitializedVal == 0) { @@ -143,8 +143,8 @@ ExtraeTypeStackStrategy::get_value_by_region_name(const std::string &name) { } } -void ExtraeTypeStackStrategy::region_start( - const PNRegionInformation ®ion) noexcept { +void ExtraeTypeStackStrategy::RegionStart( + const ProperlyNestedRegionInformation ®ion) noexcept { // First push to stack const auto regionName = std::string(region.name); @@ -159,8 +159,8 @@ void ExtraeTypeStackStrategy::region_start( Extrae_eventandcounters(type, value); } -void ExtraeTypeStackStrategy::region_stop( - const PNRegionInformation ®ion) noexcept { +void ExtraeTypeStackStrategy::RegionStopLast( + const ProperlyNestedRegionInformation ®ion) noexcept { if (regionStackData.regionNameStack.empty()) { // whoops @@ -182,7 +182,7 @@ void ExtraeTypeStackStrategy::region_stop( } } -void ExtraeTypeStackStrategy::finalize() noexcept { +void ExtraeTypeStackStrategy::Finalize() noexcept { unsigned int numberOfRegionsRegistered = regionMapData.regionNameToValue.size(); @@ -260,7 +260,7 @@ void ExtraeTypeStackStrategy::finalize() noexcept { if (didInitialize) { // Assumption is that if we needed to initialize the lib we also need to - // finalize it + // Finalize it Extrae_fini(); } } diff --git a/src/backends/extrae/extrae_type_stack.hpp b/src/backends/extrae/extrae_type_stack.hpp index 9b86450999fec42626cacc7f865fac786b7a9881..7906dd3f2d1abe1034e60aa118c52d8d96505414 100644 --- a/src/backends/extrae/extrae_type_stack.hpp +++ b/src/backends/extrae/extrae_type_stack.hpp @@ -16,7 +16,7 @@ struct RegionMapData{ }; -class ExtraeTypeStackStrategy : public PNProfilingStrategy { +class ExtraeTypeStackStrategy : public ProperlyNestedAnnotationStrategy { private: inline static bool EXTRAE_WRITE_CONFIG_FILE=false; @@ -33,8 +33,8 @@ private: public: inline static const std::string_view name = "Extrae::TypeStack"; - void region_start(const PNRegionInformation ®ion) noexcept override; - void region_stop(const PNRegionInformation ®ion) noexcept override; - virtual void init() noexcept; - virtual void finalize() noexcept; + virtual void RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept override; + virtual void RegionStopLast(const ProperlyNestedRegionInformation ®ion) noexcept override; + virtual void Init() noexcept; + virtual void Finalize() noexcept; }; diff --git a/src/bindings/nesmik.json b/src/bindings/nesmik.json index 9eb5a9eb85cad5449dddfde9e4c30ac10023f800..f124649f4cb99034b597e41d11bfe558094fa40d 100644 --- a/src/bindings/nesmik.json +++ b/src/bindings/nesmik.json @@ -18,6 +18,25 @@ }, "name": "init", "params": [ + { + "const": true, + "declarator": { + "metaattrs": { + "intent": "in" + }, + "name": "nesting_mode", + "pointer": [ + { + "ptr": "&" + } + ], + "typemap_name": "std::string" + }, + "specifier": [ + "std::string" + ], + "typemap_name": "std::string" + }, { "const": true, "declarator": { @@ -45,8 +64,8 @@ ], "typemap_name": "void" }, - "decl": "void init(const std::string &backend)", - "declgen": "void init(const std::string & backend)", + "decl": "void init(const std::string &nesting_mode, const std::string &backend)", + "declgen": "void init(const std::string & nesting_mode, const std::string & backend)", "linenumber": 8, "name": "init", "options": {}, @@ -83,20 +102,49 @@ "f_var": "backend", "sh_type": "SH_TYPE_OTHER" } + }, + "nesting_mode": { + "fmtc": { + "c_addr": "", + "c_const": "const ", + "c_deref": "*", + "c_member": "->", + "c_type": "char", + "c_var": "nesting_mode", + "cfi_type": "CFI_type_other", + "cxx_addr": "&", + "cxx_member": ".", + "cxx_nonconst_ptr": "const_cast\t(&SHCXX_nesting_mode)", + "cxx_type": "std::string", + "cxx_var": "SHCXX_nesting_mode", + "idtor": "0", + "sh_type": "SH_TYPE_OTHER", + "stmt0": "c_in_string_&", + "stmt1": "c_in_string_&" + }, + "fmtf": { + "F_C_var": "nesting_mode", + "c_var": "nesting_mode", + "f_intent": "IN", + "f_kind": "C_CHAR", + "f_type": "character(*)", + "f_var": "nesting_mode", + "sh_type": "SH_TYPE_OTHER" + } } }, "zz_fmtdict": { - "C_call_list": "SHCXX_backend", + "C_call_list": "SHCXX_nesting_mode,\t SHCXX_backend", "C_name": "nesmik_init", "C_name_api": "init", - "C_prototype": "const char * backend", + "C_prototype": "const char * nesting_mode,\t const char * backend", "C_return_type": "void", - "F_C_arguments": "backend", + "F_C_arguments": "nesting_mode,\t backend", "F_C_call": "c_init_bufferify", "F_C_name": "c_init", "F_C_subprogram": "subroutine", - "F_arg_c_call": "backend,\t SHT_backend_len", - "F_arguments": "backend", + "F_arg_c_call": "nesting_mode,\t SHT_nesting_mode_len,\t backend,\t SHT_backend_len", + "F_arguments": "nesting_mode,\t backend", "F_name_api": "init", "F_name_function": "init", "F_name_generic": "init", @@ -119,6 +167,26 @@ }, "name": "init", "params": [ + { + "const": true, + "declarator": { + "metaattrs": { + "api": "buf", + "intent": "in" + }, + "name": "nesting_mode", + "pointer": [ + { + "ptr": "&" + } + ], + "typemap_name": "std::string" + }, + "specifier": [ + "std::string" + ], + "typemap_name": "std::string" + }, { "const": true, "declarator": { @@ -147,8 +215,8 @@ ], "typemap_name": "void" }, - "decl": "void init(const std::string &backend)", - "declgen": "void init(const std::string & backend)", + "decl": "void init(const std::string &nesting_mode, const std::string &backend)", + "declgen": "void init(const std::string & nesting_mode, const std::string & backend)", "linenumber": 8, "name": "init", "options": {}, @@ -193,15 +261,51 @@ "stmtc0": "c_in_string_&_buf", "stmtc1": "c_in_string_&_buf" } + }, + "nesting_mode": { + "fmtc": { + "c_addr": "", + "c_const": "const ", + "c_deref": "*", + "c_member": "->", + "c_type": "char", + "c_var": "nesting_mode", + "c_var_len": "SHT_nesting_mode_len", + "cfi_type": "CFI_type_other", + "cxx_addr": "&", + "cxx_member": ".", + "cxx_nonconst_ptr": "const_cast\t(&SHCXX_nesting_mode)", + "cxx_type": "std::string", + "cxx_var": "SHCXX_nesting_mode", + "hnamefunc0": "ShroudLenTrim", + "idtor": "0", + "sh_type": "SH_TYPE_OTHER", + "stmt0": "c_in_string_&_buf", + "stmt1": "c_in_string_&_buf" + }, + "fmtf": { + "F_C_var": "nesting_mode", + "c_var": "nesting_mode", + "c_var_len": "SHT_nesting_mode_len", + "f_intent": "IN", + "f_kind": "C_CHAR", + "f_type": "character(*)", + "f_var": "nesting_mode", + "sh_type": "SH_TYPE_OTHER", + "stmt0": "f_in_string_&_buf", + "stmt1": "f_in_string_&_buf", + "stmtc0": "c_in_string_&_buf", + "stmtc1": "c_in_string_&_buf" + } } }, "zz_fmtdict": { - "C_call_list": "SHCXX_backend", + "C_call_list": "SHCXX_nesting_mode,\t SHCXX_backend", "C_name": "nesmik_init_bufferify", "C_name_api": "init", - "C_prototype": "char *backend,\t int SHT_backend_len", + "C_prototype": "char *nesting_mode,\t int SHT_nesting_mode_len,\t char *backend,\t int SHT_backend_len", "C_return_type": "void", - "F_C_arguments": "backend,\t SHT_backend_len", + "F_C_arguments": "nesting_mode,\t SHT_nesting_mode_len,\t backend,\t SHT_backend_len", "F_C_name": "c_init_bufferify", "F_C_subprogram": "subroutine", "F_name_api": "init", diff --git a/src/bindings/nesmik.log b/src/bindings/nesmik.log index d2cf65630c69517bd29199ce6656de0152af5fb3..d90a031cc56849b692b3158349baadc778f46c32 100644 --- a/src/bindings/nesmik.log +++ b/src/bindings/nesmik.log @@ -1,6 +1,6 @@ Read yaml nesmik.yaml -C void init(const std::string & backend) +intent(subroutine) -C void init(const std::string & backend) +intent(subroutine) +C void init(const std::string & nesting_mode, const std::string & backend) +intent(subroutine) +C void init(const std::string & nesting_mode, const std::string & backend) +intent(subroutine) C void region_start(const std::string & name) +intent(subroutine) C void region_start(const std::string & name) +intent(subroutine) C void region_stop(const std::string & name) +intent(subroutine) @@ -8,12 +8,12 @@ C void region_stop(const std::string & name) +intent(subroutine) C void finalize(void) +intent(subroutine) Close wrapnesmik.h Close wrapnesmik.cpp -Fortran void init(const std::string & backend) +intent(subroutine) +Fortran void init(const std::string & nesting_mode, const std::string & backend) +intent(subroutine) Fortran void region_start(const std::string & name) +intent(subroutine) Fortran void region_stop(const std::string & name) +intent(subroutine) Fortran void finalize(void) +intent(subroutine) -C-interface void init(const std::string & backend) +intent(subroutine) -C-interface void init(const std::string & backend) +intent(subroutine) +C-interface void init(const std::string & nesting_mode, const std::string & backend) +intent(subroutine) +C-interface void init(const std::string & nesting_mode, const std::string & backend) +intent(subroutine) C-interface void region_start(const std::string & name) +intent(subroutine) C-interface void region_start(const std::string & name) +intent(subroutine) C-interface void region_stop(const std::string & name) +intent(subroutine) diff --git a/src/bindings/nesmik.yaml b/src/bindings/nesmik.yaml index a599075ba817305e8995f6cde6354e407c06035e..2905d1df04c43d6604e900a47290e3936af6eeec 100644 --- a/src/bindings/nesmik.yaml +++ b/src/bindings/nesmik.yaml @@ -5,7 +5,7 @@ format: C_prefix: 'nesmik_' declarations: -- decl: void init(const std::string &backend) +- decl: void init(const std::string &nesting_mode, const std::string &backend) - decl: void region_start(const std::string &name) - decl: void region_stop(const std::string &name) - decl: void finalize() \ No newline at end of file diff --git a/src/bindings/wrapfnesmik.f b/src/bindings/wrapfnesmik.f index c04ff1b3d7c7cd68007853e00ac04f8b0a825d89..74029b18382d67da8ba226397d59e05ee608d135 100644 --- a/src/bindings/wrapfnesmik.f +++ b/src/bindings/wrapfnesmik.f @@ -16,17 +16,21 @@ module nesmik_mod interface - subroutine c_init(backend) & + subroutine c_init(nesting_mode, backend) & bind(C, name="nesmik_init") use iso_c_binding, only : C_CHAR implicit none + character(kind=C_CHAR), intent(IN) :: nesting_mode(*) character(kind=C_CHAR), intent(IN) :: backend(*) end subroutine c_init - subroutine c_init_bufferify(backend, SHT_backend_len) & + subroutine c_init_bufferify(nesting_mode, SHT_nesting_mode_len, & + backend, SHT_backend_len) & bind(C, name="nesmik_init_bufferify") use iso_c_binding, only : C_CHAR, C_INT implicit none + character(kind=C_CHAR), intent(IN) :: nesting_mode(*) + integer(C_INT), value, intent(IN) :: SHT_nesting_mode_len character(kind=C_CHAR), intent(IN) :: backend(*) integer(C_INT), value, intent(IN) :: SHT_backend_len end subroutine c_init_bufferify @@ -72,13 +76,17 @@ module nesmik_mod contains - subroutine init(backend) + subroutine init(nesting_mode, backend) use iso_c_binding, only : C_INT + character(len=*), intent(IN) :: nesting_mode character(len=*), intent(IN) :: backend ! splicer begin function.init + integer(C_INT) SHT_nesting_mode_len integer(C_INT) SHT_backend_len + SHT_nesting_mode_len = len(nesting_mode, kind=C_INT) SHT_backend_len = len(backend, kind=C_INT) - call c_init_bufferify(backend, SHT_backend_len) + call c_init_bufferify(nesting_mode, SHT_nesting_mode_len, & + backend, SHT_backend_len) ! splicer end function.init end subroutine init diff --git a/src/bindings/wrapnesmik.cpp b/src/bindings/wrapnesmik.cpp index 03e841b73dd4d2a84d440ec337f97ef7331f53e7..925312841d989a69df05eca5621cd398ef35f936 100644 --- a/src/bindings/wrapnesmik.cpp +++ b/src/bindings/wrapnesmik.cpp @@ -29,20 +29,24 @@ static int ShroudLenTrim(const char *src, int nsrc) { // splicer begin C_definitions // splicer end C_definitions -void nesmik_init(const char * backend) +void nesmik_init(const char * nesting_mode, const char * backend) { // splicer begin function.init + const std::string SHCXX_nesting_mode(nesting_mode); const std::string SHCXX_backend(backend); - nesmik::init(SHCXX_backend); + nesmik::init(SHCXX_nesting_mode, SHCXX_backend); // splicer end function.init } -void nesmik_init_bufferify(char *backend, int SHT_backend_len) +void nesmik_init_bufferify(char *nesting_mode, int SHT_nesting_mode_len, + char *backend, int SHT_backend_len) { // splicer begin function.init_bufferify + const std::string SHCXX_nesting_mode(nesting_mode, + ShroudLenTrim(nesting_mode, SHT_nesting_mode_len)); const std::string SHCXX_backend(backend, ShroudLenTrim(backend, SHT_backend_len)); - nesmik::init(SHCXX_backend); + nesmik::init(SHCXX_nesting_mode, SHCXX_backend); // splicer end function.init_bufferify } diff --git a/src/bindings/wrapnesmik.h b/src/bindings/wrapnesmik.h index 30f4f2d71758cb1dd081bb5648e6bf49de6f690a..d8833afa498edbbd05bbd229be50c22fb91927f6 100644 --- a/src/bindings/wrapnesmik.h +++ b/src/bindings/wrapnesmik.h @@ -21,9 +21,10 @@ extern "C" { // splicer begin C_declarations // splicer end C_declarations -void nesmik_init(const char * backend); +void nesmik_init(const char * nesting_mode, const char * backend); -void nesmik_init_bufferify(char *backend, int SHT_backend_len); +void nesmik_init_bufferify(char *nesting_mode, int SHT_nesting_mode_len, + char *backend, int SHT_backend_len); void nesmik_region_start(const char * name); diff --git a/src/delegator.cpp b/src/delegator.cpp index 2a651b213c7115a5a5161bef0211660b1344bec4..f389174153ff5415bb0cf3a9898fbe140f19926d 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -1,13 +1,14 @@ #include +#include #include #include +#include "backends/default/default.hpp" #include +#include #include -#include "backends/default/default.hpp" - #ifdef ENABLE_DLB #include "backends/dlb/dlb/dlb.hpp" #include "backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp" @@ -17,38 +18,139 @@ #include "backends/extrae/extrae_type_stack.hpp" #endif -void Delegator::init(std::string_view backend) { - std::cout << backend << std::endl; - if (backend.compare(DefaultStrategy::name) == 0) { - std::cout << "alloc" << std::endl; - pn_profiling_strategy = std::make_unique(); +void Delegator::InitDetectionBackend(const std::string_view backend) { + std::cout << "Not supported currnently, come back later pls" << std::endl; + exit(1); +} + +void Delegator::InitNonProperlyNestedBackends(const std::string_view backend) { + // check if backend is supplied + + if (backend.compare(NPNDefault::name) == 0) { + npn_annotation_strategy_ = std::make_unique(); + } +#ifdef ENABLE_DLB + else if (backend.compare(DLBTalpStrategy::name) == 0) { + npn_annotation_strategy_ = std::make_unique(); + } +#endif + else { + npn_annotation_strategy_ = std::make_unique(); + + std::cout << "Could not find a matching PNP backend with name" << backend + << " now selecting the Default" << std::endl; + } +} + +void Delegator::InitProperlyNestedBackends(const std::string_view backend) { + if (backend.compare(PNDefault::name) == 0) { + pn_annotation_strategy_ = std::make_unique(); } #ifdef ENABLE_EXTRAE else if (backend.compare(ExtraeTypeStackStrategy::name) == 0) { - pn_profiling_strategy = std::make_unique(); + pn_annotation_strategy_ = std::make_unique(); } #endif #ifdef ENABLE_DLB - else if (backend.compare(DLBTalpStrategy::name) == 0) { - pn_profiling_strategy = std::make_unique(); - } else if (backend.compare(DLBTalpTreeStrategy::name) == 0) { - pn_profiling_strategy = std::make_unique(); + pn_annotation_strategy_ = std::make_unique(); } #endif else { - exit(1); // fail non gracefully for now + std::cout << "Could not find a matching properly nested backend with name" + << backend << " skipping." << std::endl; + } +} + +void Delegator::Init(std::string_view nesting_mode, std::string_view backend) { + + std::cout << nesting_mode << "Backend:" << backend << std::endl; + + // detect nesting mode requested by the user + if (nesting_mode.compare("?") == 0) { + nesting_mode_ = NestingMode::Detecion; + } else if (nesting_mode.compare("ProperlyNested") == 0) { + nesting_mode_ = NestingMode::ProperlyNested; + } else if (nesting_mode.compare("NotProperlyNested") == 0) { + nesting_mode_ = NestingMode::NotProperlyNested; + } + + // Some debug output + switch (nesting_mode_) { + case NestingMode::Detecion: + std::cout << "Selecting nesting mode to: " + << "detecting nesting behavior" << std::endl; + break; + case NestingMode::NotProperlyNested: + std::cout << "Selecting nesting mode to: " + << "non properly nested behavior" << std::endl; + break; + case NestingMode::ProperlyNested: + std::cout << "Selecting nesting mode to: " + << "assume properly nested behavior" << std::endl; + break; } - return pn_profiling_strategy->init(); + // next choose backend + switch (nesting_mode_) { + case NestingMode::Detecion: + InitDetectionBackend(backend); + break; + case NestingMode::ProperlyNested: + case NestingMode::NotProperlyNested: + // we preferably use a Propely nested backend, + // but if this is not possible, we will select the not properly nested one + InitProperlyNestedBackends(backend); + if (pn_annotation_strategy_ == nullptr) { + std::cout << "No ProperlyNested backend found, proceeding with Not " + "Properly Nested Backend" + << std::endl; + InitNonProperlyNestedBackends(backend); + nesting_mode_ = NestingMode::NotProperlyNested; + } + break; + } + + switch (nesting_mode_) { + case NestingMode::Detecion: + case NestingMode::NotProperlyNested: + return npn_annotation_strategy_->Init(); + case NestingMode::ProperlyNested: + return pn_annotation_strategy_->Init(); + break; + } } // should be thread safe to call? -void Delegator::region_start(std::string_view name) { - pn_profiling_strategy->region_start({name}); +void Delegator::RegionStart(std::string_view name) { + switch (nesting_mode_) { + case NestingMode::Detecion: + case NestingMode::NotProperlyNested: + return npn_annotation_strategy_->RegionStart({name}); + case NestingMode::ProperlyNested: + return pn_annotation_strategy_->RegionStart({name}); + break; + } } -void Delegator::region_stop(std::string_view name) { - pn_profiling_strategy->region_stop({name}); +void Delegator::RegionStop(std::string_view name) { + switch (nesting_mode_) { + case NestingMode::Detecion: + case NestingMode::NotProperlyNested: + return npn_annotation_strategy_->RegionStop({name}); + case NestingMode::ProperlyNested: + return pn_annotation_strategy_->RegionStopLast({name}); + break; + } }; -void Delegator::finalize() { pn_profiling_strategy->finalize(); }; +void Delegator::Finalize() { + + switch (nesting_mode_) { + case NestingMode::Detecion: + case NestingMode::NotProperlyNested: + return npn_annotation_strategy_->Finalize(); + case NestingMode::ProperlyNested: + return pn_annotation_strategy_->Finalize(); + break; + } +}; diff --git a/src/delegator.hpp b/src/delegator.hpp index bfc8f761f6eb33eefa60e481154b0c5eef42655c..1e67cf03fd34c0f49493c10df2263bd92ee4e5ab 100644 --- a/src/delegator.hpp +++ b/src/delegator.hpp @@ -3,18 +3,31 @@ #include #include +#include #include +enum class NestingMode { Detecion, ProperlyNested, NotProperlyNested }; + class Delegator { private: - inline static std::unique_ptr pn_profiling_strategy; - inline static std::unique_ptr npn_profiling_strategy; - + inline static std::unique_ptr + pn_annotation_strategy_; + inline static std::unique_ptr + npn_annotation_strategy_; + inline static NestingMode nesting_mode_ = NestingMode::Detecion; + public: - static void init(std::string_view backend); - static void region_start(std::string_view name); - static void region_stop(std::string_view name); - static void finalize(); + static void Init(std::string_view nesting_mode, std::string_view backend); + static void RegionStart(std::string_view name); + static void RegionStop(std::string_view name); + static void Finalize(); + +private: + static std::vector SplitString(const std::string &str, + char delimiter); + static void InitDetectionBackend(const std::string_view backend); + static void InitNonProperlyNestedBackends(const std::string_view backend); + static void InitProperlyNestedBackends(const std::string_view backend); }; #endif // NESMIK_DELEGATOR_HPP \ No newline at end of file diff --git a/src/nesmik.cpp b/src/nesmik.cpp index 3f4186a4b4f5cb2a43b560ef7c076c4e8fb9eeb5..34fa94204e77de733d70717533bd7a6b42a9ebef 100644 --- a/src/nesmik.cpp +++ b/src/nesmik.cpp @@ -1,17 +1,19 @@ -#include #include #include +#include -// provides a c-like way to call things with just a fuction compared to instanciate a class. +// provides a c-like way to call things with just a fuction compared to +// instanciate a class. namespace nesmik { -void init(const std::string &backend) { return Delegator::init(backend); +void init(const std::string &nesting_mode, const std::string &backend) { + return Delegator::Init(nesting_mode, backend); } void region_start(const std::string &name) { - return Delegator::region_start(name); + return Delegator::RegionStart(name); } void region_stop(const std::string &name) { - return Delegator::region_stop(name); + return Delegator::RegionStop(name); } -void finalize() { return Delegator::finalize(); } +void finalize() { return Delegator::Finalize(); } } // namespace nesmik diff --git a/src/strategies.hpp b/src/strategies.hpp index 4d639827878584d81c2c8c03ae21f11de440d1dd..7880da03221c022037e7d669e01674faf23ce86d 100644 --- a/src/strategies.hpp +++ b/src/strategies.hpp @@ -5,34 +5,35 @@ #include #include -struct PNRegionInformation { +struct ProperlyNestedRegionInformation { std::string_view name; }; - -struct NPNRegionInformation { +struct NotProperlyNestedRegionInformation { std::string_view name; }; - // A backend implementing the Properly Nested Profiling -class PNProfilingStrategy { +class ProperlyNestedAnnotationStrategy { public: - virtual ~PNProfilingStrategy() = default; - virtual void region_start(const PNRegionInformation ®ion) noexcept = 0; - virtual void region_stop(const PNRegionInformation ®ion) noexcept = 0; - virtual void init() noexcept = 0; - virtual void finalize() noexcept = 0; + virtual ~ProperlyNestedAnnotationStrategy() = default; + virtual void Init() noexcept = 0; + virtual void + RegionStart(const ProperlyNestedRegionInformation ®ion) noexcept = 0; + virtual void + RegionStopLast(const ProperlyNestedRegionInformation ®ion) noexcept = 0; + virtual void Finalize() noexcept = 0; }; -class NPNProfilingStrategy { +class NotProperlyNestedAnnotationStrategy { public: - virtual ~NPNProfilingStrategy() = default; - virtual void region_start(const NPNRegionInformation ®ion) noexcept = 0; - virtual void region_stop(const NPNRegionInformation ®ion) noexcept = 0; - virtual void init() noexcept = 0; - virtual void finalize() noexcept = 0; + virtual void Init() noexcept = 0; + virtual ~NotProperlyNestedAnnotationStrategy() = default; + virtual void + RegionStart(const NotProperlyNestedRegionInformation ®ion) noexcept = 0; + virtual void + RegionStop(const NotProperlyNestedRegionInformation ®ion) noexcept = 0; + virtual void Finalize() noexcept = 0; }; - #endif // NESMIK_STRATEGY_HPP \ No newline at end of file diff --git a/tests/cpp/TestCppDLB.cpp b/tests/cpp/TestCppDLB.cpp index a91b6d78966d9923884054e7a593ed695b109472..2ba1cba70273d9d7f2f579b806bed82653f28f7c 100644 --- a/tests/cpp/TestCppDLB.cpp +++ b/tests/cpp/TestCppDLB.cpp @@ -1,7 +1,7 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("TALP"); + nesmik::init("NotProperlyNested","TALP"); nesmik::region_start("Default"); nesmik::region_stop("Default"); nesmik::finalize(); diff --git a/tests/cpp/TestCppExtraeTypeStack.cpp b/tests/cpp/TestCppExtraeTypeStack.cpp index d88f34f597f1153559155fda4c4703ecf598404b..25bb92f369bb29f21971568bc34c6195ed7ad2b4 100644 --- a/tests/cpp/TestCppExtraeTypeStack.cpp +++ b/tests/cpp/TestCppExtraeTypeStack.cpp @@ -1,7 +1,7 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("Extrae::TypeStack"); + nesmik::init("ProperlyNested","Extrae::TypeStack"); nesmik::region_start("init"); nesmik::region_start("init_ts"); diff --git a/tests/cpp/TestCppLink.cpp b/tests/cpp/TestCppLink.cpp index 1a0dfe01159ce68b0514737e70472298871f760a..79d5ae2484b74e1066e548938630abd4a2a3943e 100644 --- a/tests/cpp/TestCppLink.cpp +++ b/tests/cpp/TestCppLink.cpp @@ -1,7 +1,7 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("Default"); + nesmik::init("ProperlyNested","Default"); nesmik::region_start("Default"); nesmik::region_stop("Default"); nesmik::finalize(); diff --git a/tests/cpp/TestCppTalpTree.cpp b/tests/cpp/TestCppTalpTree.cpp index 35610bc7f0eccc9d1b596da7e66064ab615e8a05..bfe90d2e8f5fb519c45e9a4c3b33afa9b8501b6d 100644 --- a/tests/cpp/TestCppTalpTree.cpp +++ b/tests/cpp/TestCppTalpTree.cpp @@ -1,7 +1,7 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("TALP-Tree"); + nesmik::init("ProperlyNested","TALP-Tree"); nesmik::region_start("Top"); nesmik::region_start("child-1"); nesmik::region_start("child-1.1"); diff --git a/tests/fortran/TestFortranModule.f90 b/tests/fortran/TestFortranModule.f90 index e742b0edb779a01cf28c970aa94f0e9499bd9250..f20187357273da4dfa63b3324d80cdf3e9f9c7ab 100644 --- a/tests/fortran/TestFortranModule.f90 +++ b/tests/fortran/TestFortranModule.f90 @@ -1,5 +1,5 @@ program do_sample use nesmik_mod - call init("Default") + call init("ProperlyNested","Default") call region_start("test") end program do_sample \ No newline at end of file