diff --git a/include/nesmik/nesmik.hpp b/include/nesmik/nesmik.hpp index 80b192e82314541203ea19b03e2a1a8abb73a37e..0f69bb305eda9258e1959f8a2694cf15ec0471f2 100644 --- a/include/nesmik/nesmik.hpp +++ b/include/nesmik/nesmik.hpp @@ -1,9 +1,8 @@ #include - namespace nesmik { -void init(const std::string &nesting_mode, const std::string &backend); +void nesmik_init(); void region_start(const std::string &name); void region_stop(const std::string &name); void region_stop_last(void); // only supported in PN backends -void finalize(); +void nesmik_finalize(); } // namespace nesmik diff --git a/src/backends/default/default.cpp b/src/backends/default/default.cpp index 0fe3a459cdf4f46de739e993216a7168b942f381..d3e50e3a63b7238ea9a71cd0f62590b0d7e820cb 100644 --- a/src/backends/default/default.cpp +++ b/src/backends/default/default.cpp @@ -10,17 +10,19 @@ NPNDefault::NPNDefault() { void NPNDefault::RegionStart( const NotProperlyNestedRegionInformation ®ion) noexcept { - std::cout << "Region start: " << region.name << std::endl; + std::cout << "neSmiK: DefaultBackend region_start: " << region.name + << std::endl; } void NPNDefault::RegionStop( const NotProperlyNestedRegionInformation ®ion) noexcept { - std::cout << "Region stop: " << region.name << std::endl; + std::cout << "neSmiK: DefaultBackend region_stop: " << region.name + << std::endl; } void NPNDefault::Init() noexcept { - std::cout << "nesmik::Init() Backend: Default " << std::endl; + std::cout << "neSmiK: DefaultBackend Init()" << std::endl; } void NPNDefault::Finalize() noexcept { - std::cout << "nesmik::Finalize() Backend: Default " << std::endl; + std::cout << "neSmiK: DefaultBackend Finalize()" << std::endl; } diff --git a/src/backends/detection/detection.hpp b/src/backends/detection/detection.hpp index e1d87582e2d2f52046fa0e987b060145784abef8..ed7f499f9acd598a33a89456939dc0ca9782ce1c 100644 --- a/src/backends/detection/detection.hpp +++ b/src/backends/detection/detection.hpp @@ -40,7 +40,7 @@ class DetectionStrategy : public ProperlyNestedAnnotationStrategy { std::mutex ends_mutex_; EnvironmentVariable verbose_mode_ = EnvironmentVariable( "DETECTION_VERBOSE", "Enables the verbose mode in the detection backend", - true); + false); bool has_errors_ = false; diff --git a/src/backends/dlb/dlb/dlb.cpp b/src/backends/dlb/dlb/dlb.cpp index dc35e99fa91b83be61aed423abc6f720bbc57ce9..a120bf56ec81d62bcc3aa2905b5e988dcd5e2d44 100644 --- a/src/backends/dlb/dlb/dlb.cpp +++ b/src/backends/dlb/dlb/dlb.cpp @@ -27,11 +27,5 @@ void DLBTalpStrategy::RegionStop( DLB_MonitoringRegionStop(handle); } -void DLBTalpStrategy::Init() noexcept { - DLB_Init(0, NULL, "--talp"); - std::cout << "nesmik::" << name << " init()" << std::endl; -} -void DLBTalpStrategy::Finalize() noexcept { - DLB_Finalize(); - std::cout << "nesmik::" << name << " Finalize()" << std::endl; -} +void DLBTalpStrategy::Init() noexcept { DLB_Init(0, NULL, "--talp"); } +void DLBTalpStrategy::Finalize() noexcept { DLB_Finalize(); } diff --git a/src/backends/dlb/dlb/dlb.hpp b/src/backends/dlb/dlb/dlb.hpp index 876a524a293131df2a7284b48b869fc421d1ed2e..d6a4abdbf0f9d1ff4b9353a712f1c166661d1da6 100644 --- a/src/backends/dlb/dlb/dlb.hpp +++ b/src/backends/dlb/dlb/dlb.hpp @@ -1,5 +1,5 @@ -#ifndef SIT_DLB_H -#define SIT_DLB_H +#ifndef NESMIK_DLB_H +#define NESMIK_DLB_H #include @@ -14,4 +14,4 @@ class DLBTalpStrategy : public NotProperlyNestedAnnotationStrategy { virtual void Init() noexcept; virtual void Finalize() noexcept; }; -#endif // SIT_DLB_H +#endif // NESMIK_DLB_H 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 f013186f93d88e5f4143c4e3ac1ea0bc1ad5f4f0..a5073a15f1cebcde2462876a7a7f91f09a37cc23 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp @@ -51,7 +51,7 @@ class DLBTalpTreeStrategy : public ProperlyNestedAnnotationStrategy { public: DLBTalpTreeStrategy(); - inline static const std::string_view name = "TALP::Tree"; + inline static const std::string name = "TALP::Tree"; void RegionStart( const ProperlyNestedRegionInformation ®ion) noexcept override; void RegionStopLast( diff --git a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp index dcfbeccea5ebfb0435c05a538a669804462ed795..10267e6e204f862d7c16e3053572244830cd61e5 100644 --- a/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp +++ b/src/backends/dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp @@ -64,6 +64,7 @@ std::size_t DLBTalpTreeASCIISerializer::compute_tree_lines() { this->regions.at(current_region.hash).name.length() + tree_lines.length()); } + return max_width; } std::string DLBTalpTreeASCIISerializer::generate_tree_view(int name_width) { diff --git a/src/backends/extrae/extrae_type_stack.hpp b/src/backends/extrae/extrae_type_stack.hpp index df59582b596a63f58982b412a0a04707810fd6fb..02370f8fb1d9ee34a9de8348d614256e97baec90 100644 --- a/src/backends/extrae/extrae_type_stack.hpp +++ b/src/backends/extrae/extrae_type_stack.hpp @@ -43,7 +43,7 @@ class ExtraeTypeStackStrategy : public ProperlyNestedAnnotationStrategy { public: ExtraeTypeStackStrategy(); - inline static const std::string_view name = "Extrae::TypeStack"; + inline static const std::string name = "Extrae::TypeStack"; virtual void RegionStart( const ProperlyNestedRegionInformation ®ion) noexcept override; diff --git a/src/bindings/nesmik.json b/src/bindings/nesmik.json index 96f8aba20b89291ad9d49d1a7f9bfaaa0694ca83..4048e9f4847c881e58502ed6758da60b5039e887 100644 --- a/src/bindings/nesmik.json +++ b/src/bindings/nesmik.json @@ -7,56 +7,13 @@ "functions": [ { "": "0 ****************************************", - "C_generated_path": [ - "arg_to_buffer" - ], - "_PTR_F_C_index": "5", "ast": { "declarator": { "metaattrs": { "intent": "subroutine" }, - "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": { - "metaattrs": { - "intent": "in" - }, - "name": "backend", - "pointer": [ - { - "ptr": "&" - } - ], - "typemap_name": "std::string" - }, - "specifier": [ - "std::string" - ], - "typemap_name": "std::string" - } - ], + "name": "nesmik_init", + "params": [], "typemap_name": "void" }, "specifier": [ @@ -64,263 +21,44 @@ ], "typemap_name": "void" }, - "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", + "decl": "void nesmik_init()", + "declgen": "void nesmik_init(void)", + "linenumber": 9, + "name": "nesmik_init", "options": {}, "wrap": { "c": true, + "f_c": true, "fortran": true }, - "zz_fmtargs": { - "backend": { - "fmtc": { - "c_addr": "", - "c_const": "const ", - "c_deref": "*", - "c_member": "->", - "c_type": "char", - "c_var": "backend", - "cfi_type": "CFI_type_other", - "cxx_addr": "&", - "cxx_member": ".", - "cxx_nonconst_ptr": "const_cast\t(&SHCXX_backend)", - "cxx_type": "std::string", - "cxx_var": "SHCXX_backend", - "idtor": "0", - "sh_type": "SH_TYPE_OTHER", - "stmt0": "c_in_string_&", - "stmt1": "c_in_string_&" - }, - "fmtf": { - "F_C_var": "backend", - "c_var": "backend", - "f_intent": "IN", - "f_kind": "C_CHAR", - "f_type": "character(*)", - "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_nesting_mode,\t SHCXX_backend", - "C_name": "nesmik_init", - "C_name_api": "init", - "C_prototype": "const char * nesting_mode,\t const char * backend", + "C_name": "c_nesmik_init", + "C_name_api": "nesmik_init", + "C_prototype": "void", "C_return_type": "void", - "F_C_arguments": "nesting_mode,\t backend", - "F_C_call": "c_init_bufferify", - "F_C_name": "c_init", + "F_C_arguments": "", + "F_C_call": "c_nesmik_init", + "F_C_name": "nesmik_init", "F_C_subprogram": "subroutine", - "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", - "F_name_impl": "init", + "F_arguments": "", + "F_name_api": "nesmik_init", + "F_name_function": "nesmik_init", + "F_name_generic": "nesmik_init", + "F_name_impl": "nesmik_init", "F_subprogram": "subroutine", - "function_name": "init", + "function_name": "nesmik_init", "stmt0": "f_subroutine", "stmt1": "f_subroutine", "stmtc0": "c_subroutine", "stmtc1": "c_subroutine" } }, - { - "": "5 ****************************************", - "_generated": "arg_to_buffer", - "ast": { - "declarator": { - "metaattrs": { - "intent": "subroutine" - }, - "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": { - "metaattrs": { - "api": "buf", - "intent": "in" - }, - "name": "backend", - "pointer": [ - { - "ptr": "&" - } - ], - "typemap_name": "std::string" - }, - "specifier": [ - "std::string" - ], - "typemap_name": "std::string" - } - ], - "typemap_name": "void" - }, - "specifier": [ - "void" - ], - "typemap_name": "void" - }, - "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": {}, - "splicer_group": "buf", - "wrap": { - "c": true, - "f_c": true - }, - "zz_fmtargs": { - "backend": { - "fmtc": { - "c_addr": "", - "c_const": "const ", - "c_deref": "*", - "c_member": "->", - "c_type": "char", - "c_var": "backend", - "c_var_len": "SHT_backend_len", - "cfi_type": "CFI_type_other", - "cxx_addr": "&", - "cxx_member": ".", - "cxx_nonconst_ptr": "const_cast\t(&SHCXX_backend)", - "cxx_type": "std::string", - "cxx_var": "SHCXX_backend", - "hnamefunc0": "ShroudLenTrim", - "idtor": "0", - "sh_type": "SH_TYPE_OTHER", - "stmt0": "c_in_string_&_buf", - "stmt1": "c_in_string_&_buf" - }, - "fmtf": { - "F_C_var": "backend", - "c_var": "backend", - "c_var_len": "SHT_backend_len", - "f_intent": "IN", - "f_kind": "C_CHAR", - "f_type": "character(*)", - "f_var": "backend", - "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" - } - }, - "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_nesting_mode,\t SHCXX_backend", - "C_name": "nesmik_init_bufferify", - "C_name_api": "init", - "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": "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", - "function_name": "init", - "function_suffix": "_bufferify", - "stmt0": "c_subroutine", - "stmt1": "c_subroutine" - } - }, { "": "1 ****************************************", "C_generated_path": [ "arg_to_buffer" ], - "_PTR_F_C_index": "6", + "_PTR_F_C_index": "5", "ast": { "declarator": { "metaattrs": { @@ -357,7 +95,7 @@ }, "decl": "void region_start(const std::string &name)", "declgen": "void region_start(const std::string & name)", - "linenumber": 9, + "linenumber": 10, "name": "region_start", "options": {}, "wrap": { @@ -397,7 +135,7 @@ }, "zz_fmtdict": { "C_call_list": "SHCXX_name", - "C_name": "nesmik_region_start", + "C_name": "c_region_start", "C_name_api": "region_start", "C_prototype": "const char * name", "C_return_type": "void", @@ -420,7 +158,7 @@ } }, { - "": "6 ****************************************", + "": "5 ****************************************", "_PTR_C_CXX_index": "1", "_generated": "arg_to_buffer", "ast": { @@ -460,7 +198,7 @@ }, "decl": "void region_start(const std::string &name)", "declgen": "void region_start(const std::string & name)", - "linenumber": 9, + "linenumber": 10, "name": "region_start", "options": {}, "splicer_group": "buf", @@ -508,7 +246,7 @@ }, "zz_fmtdict": { "C_call_list": "SHCXX_name", - "C_name": "nesmik_region_start_bufferify", + "C_name": "c_region_start_bufferify", "C_name_api": "region_start", "C_prototype": "char *name,\t int SHT_name_len", "C_return_type": "void", @@ -527,7 +265,7 @@ "C_generated_path": [ "arg_to_buffer" ], - "_PTR_F_C_index": "7", + "_PTR_F_C_index": "6", "ast": { "declarator": { "metaattrs": { @@ -564,7 +302,7 @@ }, "decl": "void region_stop(const std::string &name)", "declgen": "void region_stop(const std::string & name)", - "linenumber": 10, + "linenumber": 11, "name": "region_stop", "options": {}, "wrap": { @@ -604,7 +342,7 @@ }, "zz_fmtdict": { "C_call_list": "SHCXX_name", - "C_name": "nesmik_region_stop", + "C_name": "c_region_stop", "C_name_api": "region_stop", "C_prototype": "const char * name", "C_return_type": "void", @@ -627,7 +365,7 @@ } }, { - "": "7 ****************************************", + "": "6 ****************************************", "_PTR_C_CXX_index": "2", "_generated": "arg_to_buffer", "ast": { @@ -667,7 +405,7 @@ }, "decl": "void region_stop(const std::string &name)", "declgen": "void region_stop(const std::string & name)", - "linenumber": 10, + "linenumber": 11, "name": "region_stop", "options": {}, "splicer_group": "buf", @@ -715,7 +453,7 @@ }, "zz_fmtdict": { "C_call_list": "SHCXX_name", - "C_name": "nesmik_region_stop_bufferify", + "C_name": "c_region_stop_bufferify", "C_name_api": "region_stop", "C_prototype": "char *name,\t int SHT_name_len", "C_return_type": "void", @@ -747,7 +485,7 @@ }, "decl": "void region_stop_last(void)", "declgen": "void region_stop_last(void)", - "linenumber": 11, + "linenumber": 12, "name": "region_stop_last", "options": {}, "wrap": { @@ -756,7 +494,7 @@ "fortran": true }, "zz_fmtdict": { - "C_name": "nesmik_region_stop_last", + "C_name": "c_region_stop_last", "C_name_api": "region_stop_last", "C_prototype": "void", "C_return_type": "void", @@ -784,7 +522,7 @@ "metaattrs": { "intent": "subroutine" }, - "name": "finalize", + "name": "nesmik_finalize", "params": [], "typemap_name": "void" }, @@ -793,10 +531,10 @@ ], "typemap_name": "void" }, - "decl": "void finalize()", - "declgen": "void finalize(void)", - "linenumber": 12, - "name": "finalize", + "decl": "void nesmik_finalize()", + "declgen": "void nesmik_finalize(void)", + "linenumber": 13, + "name": "nesmik_finalize", "options": {}, "wrap": { "c": true, @@ -804,21 +542,21 @@ "fortran": true }, "zz_fmtdict": { - "C_name": "nesmik_finalize", - "C_name_api": "finalize", + "C_name": "c_nesmik_finalize", + "C_name_api": "nesmik_finalize", "C_prototype": "void", "C_return_type": "void", "F_C_arguments": "", - "F_C_call": "c_finalize", - "F_C_name": "finalize", + "F_C_call": "c_nesmik_finalize", + "F_C_name": "nesmik_finalize", "F_C_subprogram": "subroutine", "F_arguments": "", - "F_name_api": "finalize", - "F_name_function": "finalize", - "F_name_generic": "finalize", - "F_name_impl": "finalize", + "F_name_api": "nesmik_finalize", + "F_name_function": "nesmik_finalize", + "F_name_generic": "nesmik_finalize", + "F_name_impl": "nesmik_finalize", "F_subprogram": "subroutine", - "function_name": "finalize", + "function_name": "nesmik_finalize", "stmt0": "f_subroutine", "stmt1": "f_subroutine", "stmtc0": "c_subroutine", @@ -954,10 +692,10 @@ "CXX_template": "", "CXX_this": "SH_this", "CXX_this_call": "", - "C_array_type": "nesmik_SHROUD_array", + "C_array_type": "c_SHROUD_array", "C_bufferify_suffix": "_bufferify", "C_call_list": "", - "C_capsule_data_type": "nesmik_SHROUD_capsule_data", + "C_capsule_data_type": "c_SHROUD_capsule_data", "C_cfi_suffix": "_CFI", "C_custom_return_type": "", "C_header_filename": "wrapnesmik.h", @@ -967,12 +705,12 @@ "C_impl_filename_suffix": "cpp", "C_impl_utility": "utilnesmik.cpp", "C_local": "SHC_", - "C_memory_dtor_function": "nesmik_SHROUD_memory_destructor", + "C_memory_dtor_function": "c_SHROUD_memory_destructor", "C_name_scope": "", "C_name_typedef": "", "C_post_call": "", "C_pre_call": "", - "C_prefix": "nesmik_", + "C_prefix": "c_", "C_result": "rv", "C_string_result_as_arg": "SHF_rv", "C_this": "self", @@ -981,11 +719,11 @@ "F_C_pure_clause": "", "F_C_result_clause": "", "F_arg_c_call": "", - "F_array_type": "nesmik_SHROUD_array", - "F_capsule_data_type": "nesmik_SHROUD_capsule_data", + "F_array_type": "c_SHROUD_array", + "F_capsule_data_type": "c_SHROUD_capsule_data", "F_capsule_delete_function": "SHROUD_capsule_delete", "F_capsule_final_function": "SHROUD_capsule_final", - "F_capsule_type": "nesmik_SHROUD_capsule", + "F_capsule_type": "c_SHROUD_capsule", "F_derived_member": "cxxmem", "F_derived_member_base": "", "F_filename_suffix": "f", diff --git a/src/bindings/nesmik.log b/src/bindings/nesmik.log index 3fbcba94a3995538c754aa0300f16915e513f183..7c263beef11bbc265de700712b2bed3d33fb063f 100644 --- a/src/bindings/nesmik.log +++ b/src/bindings/nesmik.log @@ -1,27 +1,25 @@ Read yaml nesmik.yaml -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 nesmik_init(void) +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) C void region_stop(const std::string & name) +intent(subroutine) C void region_stop_last(void) +intent(subroutine) -C void finalize(void) +intent(subroutine) +C void nesmik_finalize(void) +intent(subroutine) Close wrapnesmik.h Close wrapnesmik.cpp -Fortran void init(const std::string & nesting_mode, const std::string & backend) +intent(subroutine) +Fortran void nesmik_init(void) +intent(subroutine) Fortran void region_start(const std::string & name) +intent(subroutine) Fortran void region_stop(const std::string & name) +intent(subroutine) Fortran void region_stop_last(void) +intent(subroutine) -Fortran void finalize(void) +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) +Fortran void nesmik_finalize(void) +intent(subroutine) +C-interface void nesmik_init(void) +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) C-interface void region_stop(const std::string & name) +intent(subroutine) C-interface void region_stop_last(void) +intent(subroutine) -C-interface void finalize(void) +intent(subroutine) +C-interface void nesmik_finalize(void) +intent(subroutine) Close wrapfnesmik.f Close utilnesmik.cpp Close typesnesmik.h diff --git a/src/bindings/nesmik.yaml b/src/bindings/nesmik.yaml index 57662bedd9695e7fcb5e46a4a0fb4b2120636079..173e2f4e91143b5de76b46e4d66cfb7b38056ab7 100644 --- a/src/bindings/nesmik.yaml +++ b/src/bindings/nesmik.yaml @@ -2,11 +2,12 @@ library: nesmik namespace: nesmik cxx_header: nesmik/nesmik.hpp format: - C_prefix: 'nesmik_' + C_prefix: 'c_' + declarations: -- decl: void init(const std::string &nesting_mode, const std::string &backend) +- decl: void nesmik_init() - decl: void region_start(const std::string &name) - decl: void region_stop(const std::string &name) - decl: void region_stop_last(void) -- decl: void finalize() +- decl: void nesmik_finalize() diff --git a/src/bindings/typesnesmik.h b/src/bindings/typesnesmik.h index 579ec89b8fdc1501db76cb29b02ebf75aafacf75..faadcb7c156b91f04547d3143e1e4fb74cdf2b28 100644 --- a/src/bindings/typesnesmik.h +++ b/src/bindings/typesnesmik.h @@ -16,13 +16,13 @@ extern "C" { // splicer end types.C_declarations // helper capsule_data_helper -struct s_nesmik_SHROUD_capsule_data { +struct s_c_SHROUD_capsule_data { void *addr; /* address of C++ memory */ int idtor; /* index of destructor */ }; -typedef struct s_nesmik_SHROUD_capsule_data nesmik_SHROUD_capsule_data; +typedef struct s_c_SHROUD_capsule_data c_SHROUD_capsule_data; -void nesmik_SHROUD_memory_destructor(nesmik_SHROUD_capsule_data *cap); +void c_SHROUD_memory_destructor(c_SHROUD_capsule_data *cap); #ifdef __cplusplus } diff --git a/src/bindings/utilnesmik.cpp b/src/bindings/utilnesmik.cpp index d81afb744f503fba3eaed5a03aca4ab31575f65c..153565b1a16fa0e9c679a6d9a8cb69b30c7569db 100644 --- a/src/bindings/utilnesmik.cpp +++ b/src/bindings/utilnesmik.cpp @@ -8,7 +8,7 @@ extern "C" { #endif // Release library allocated memory. -void nesmik_SHROUD_memory_destructor(nesmik_SHROUD_capsule_data *cap) { +void c_SHROUD_memory_destructor(c_SHROUD_capsule_data *cap) { cap->addr = nullptr; cap->idtor = 0; // avoid deleting again } diff --git a/src/bindings/wrapfnesmik.f b/src/bindings/wrapfnesmik.f index 9e9b1ca6244e840a4fbc0373a1c7509f4414bda9..beb96a62cdb35ec8883f9d851581bae78a438ce5 100644 --- a/src/bindings/wrapfnesmik.f +++ b/src/bindings/wrapfnesmik.f @@ -16,34 +16,20 @@ module nesmik_mod interface - 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(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 + subroutine nesmik_init() & + bind(C, name="c_nesmik_init") 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 + end subroutine nesmik_init subroutine c_region_start(name) & - bind(C, name="nesmik_region_start") + bind(C, name="c_region_start") use iso_c_binding, only : C_CHAR implicit none character(kind=C_CHAR), intent(IN) :: name(*) end subroutine c_region_start subroutine c_region_start_bufferify(name, SHT_name_len) & - bind(C, name="nesmik_region_start_bufferify") + bind(C, name="c_region_start_bufferify") use iso_c_binding, only : C_CHAR, C_INT implicit none character(kind=C_CHAR), intent(IN) :: name(*) @@ -51,14 +37,14 @@ module nesmik_mod end subroutine c_region_start_bufferify subroutine c_region_stop(name) & - bind(C, name="nesmik_region_stop") + bind(C, name="c_region_stop") use iso_c_binding, only : C_CHAR implicit none character(kind=C_CHAR), intent(IN) :: name(*) end subroutine c_region_stop subroutine c_region_stop_bufferify(name, SHT_name_len) & - bind(C, name="nesmik_region_stop_bufferify") + bind(C, name="c_region_stop_bufferify") use iso_c_binding, only : C_CHAR, C_INT implicit none character(kind=C_CHAR), intent(IN) :: name(*) @@ -66,14 +52,14 @@ module nesmik_mod end subroutine c_region_stop_bufferify subroutine region_stop_last() & - bind(C, name="nesmik_region_stop_last") + bind(C, name="c_region_stop_last") implicit none end subroutine region_stop_last - subroutine finalize() & - bind(C, name="nesmik_finalize") + subroutine nesmik_finalize() & + bind(C, name="c_nesmik_finalize") implicit none - end subroutine finalize + end subroutine nesmik_finalize end interface ! splicer begin additional_declarations @@ -81,20 +67,6 @@ module nesmik_mod contains - 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(nesting_mode, SHT_nesting_mode_len, & - backend, SHT_backend_len) - ! splicer end function.init - end subroutine init - subroutine region_start(name) use iso_c_binding, only : C_INT character(len=*), intent(IN) :: name diff --git a/src/bindings/wrapnesmik.cpp b/src/bindings/wrapnesmik.cpp index 91d2230555ed30fe8247c438d304845499feec0b..b78a975460ff1938639896bf675dbbee520b52a9 100644 --- a/src/bindings/wrapnesmik.cpp +++ b/src/bindings/wrapnesmik.cpp @@ -30,63 +30,50 @@ static int ShroudLenTrim(const char *src, int nsrc) { // splicer begin C_definitions // splicer end C_definitions -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_nesting_mode, SHCXX_backend); - // splicer end function.init +void c_nesmik_init(void) { + // splicer begin function.nesmik_init + nesmik::nesmik_init(); + // splicer end function.nesmik_init } -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_nesting_mode, SHCXX_backend); - // splicer end function.init_bufferify -} - -void nesmik_region_start(const char *name) { +void c_region_start(const char *name) { // splicer begin function.region_start const std::string SHCXX_name(name); nesmik::region_start(SHCXX_name); // splicer end function.region_start } -void nesmik_region_start_bufferify(char *name, int SHT_name_len) { +void c_region_start_bufferify(char *name, int SHT_name_len) { // splicer begin function.region_start_bufferify const std::string SHCXX_name(name, ShroudLenTrim(name, SHT_name_len)); nesmik::region_start(SHCXX_name); // splicer end function.region_start_bufferify } -void nesmik_region_stop(const char *name) { +void c_region_stop(const char *name) { // splicer begin function.region_stop const std::string SHCXX_name(name); nesmik::region_stop(SHCXX_name); // splicer end function.region_stop } -void nesmik_region_stop_bufferify(char *name, int SHT_name_len) { +void c_region_stop_bufferify(char *name, int SHT_name_len) { // splicer begin function.region_stop_bufferify const std::string SHCXX_name(name, ShroudLenTrim(name, SHT_name_len)); nesmik::region_stop(SHCXX_name); // splicer end function.region_stop_bufferify } -void nesmik_region_stop_last(void) { +void c_region_stop_last(void) { // splicer begin function.region_stop_last nesmik::region_stop_last(); // splicer end function.region_stop_last } -void nesmik_finalize(void) { - // splicer begin function.finalize - nesmik::finalize(); - // splicer end function.finalize +void c_nesmik_finalize(void) { + // splicer begin function.nesmik_finalize + nesmik::nesmik_finalize(); + // splicer end function.nesmik_finalize } } // extern "C" diff --git a/src/bindings/wrapnesmik.h b/src/bindings/wrapnesmik.h index 80e85cfa474bb2fc83c155f8762fac4e2870f6f6..e049f916590ecd0500683a6335a1c2448651e167 100644 --- a/src/bindings/wrapnesmik.h +++ b/src/bindings/wrapnesmik.h @@ -21,22 +21,19 @@ extern "C" { // splicer begin C_declarations // splicer end C_declarations -void nesmik_init(const char *nesting_mode, const char *backend); +void c_nesmik_init(void); -void nesmik_init_bufferify(char *nesting_mode, int SHT_nesting_mode_len, - char *backend, int SHT_backend_len); +void c_region_start(const char *name); -void nesmik_region_start(const char *name); +void c_region_start_bufferify(char *name, int SHT_name_len); -void nesmik_region_start_bufferify(char *name, int SHT_name_len); +void c_region_stop(const char *name); -void nesmik_region_stop(const char *name); +void c_region_stop_bufferify(char *name, int SHT_name_len); -void nesmik_region_stop_bufferify(char *name, int SHT_name_len); +void c_region_stop_last(void); -void nesmik_region_stop_last(void); - -void nesmik_finalize(void); +void c_nesmik_finalize(void); #ifdef __cplusplus } diff --git a/src/delegator.cpp b/src/delegator.cpp index 51ff0839e7d4f82f712e461a5a968d383e88f925..2439203779a5c00f8744d85abdb9c64d52326bca 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "backends/default/default.hpp" @@ -20,20 +21,6 @@ #include "backends/extrae/extrae_type_stack.hpp" #endif -std::optional getNestingMode(const std::string &nesting_mode) { - // detect nesting mode specified by the user - if (stringsAreCaseInsensitiveEqual(nesting_mode, "?")) { - return NestingMode::Detection; - } else if (stringsAreCaseInsensitiveEqual(nesting_mode, "ProperlyNested")) { - return NestingMode::ProperlyNested; - } else if (stringsAreCaseInsensitiveEqual(nesting_mode, - "NotProperlyNested")) { - return NestingMode::NotProperlyNested; - } else { - return std::nullopt; - } -} - void Delegator::InitNonProperlyNestedBackends(const std::string &backend) { // check if backend is supplied @@ -45,18 +32,11 @@ void Delegator::InitNonProperlyNestedBackends(const std::string &backend) { npn_annotation_strategy_ = std::make_unique(); } #endif - else { - npn_annotation_strategy_ = std::make_unique(); - - std::cout - << "Could not find a matching NotProperlyNested backend with name " - << backend << " now selecting the Default" << std::endl; - } } void Delegator::TryInitProperlyNestedBackend(const std::string &backend) { - if (false) { - // a bit ugly, but worky + if (backend.compare(DetectionStrategy::name) == 0) { + pn_annotation_strategy_ = std::make_unique(); } #ifdef ENABLE_EXTRAE else if (backend.compare(ExtraeTypeStackStrategy::name) == 0) { @@ -70,84 +50,99 @@ void Delegator::TryInitProperlyNestedBackend(const std::string &backend) { #endif } -void Delegator::Init(std::string_view nesting_mode_in, - std::string_view backend_in) { - mpi_helper_ = std::make_unique(); +const std::vector Delegator::available_backends = { +#ifdef ENABLE_DLB + DLBTalpTreeStrategy::name, DLBTalpStrategy::name, +#endif +#ifdef ENABLE_EXTRAE + ExtraeTypeStackStrategy::name, +#endif + "Default", "Detection"}; - std::string backend = std::string(backend_in); +bool Delegator::checkIfBackendAvailable(const std::string &backend) { + bool found_backend{false}; + for (const auto &available_backend : available_backends) { + found_backend = found_backend || + stringsAreCaseInsensitiveEqual(available_backend, backend); + } + return found_backend; +} - if (mpi_helper_->IsRankNumber(0)) { - std::cout << "neSmiK init called with program nesting: " << nesting_mode_in - << " and backend: " << backend << std::endl; +void Delegator::Init() { + if (did_initialize_) { + return; } + mpi_helper_ = std::make_unique(); - // now determine nesting mode - auto nesting_mode = getNestingMode(std::string(nesting_mode_in)); - if (!nesting_mode.has_value()) { - std::cout << "Something went wrong when selecting the nesting mode, " - "please make sure to spell it correctly" - << std::endl; - exit(1); + EnvironmentVariable env_backend = + EnvironmentVariable( + "BACKEND", + "Set the backend to use, when init with \"env\" backend name.", + false); + if (env_backend.isSet()) { + // if backend is set we assume that user wants nesmik to run + nesmik_on_ = true; } - if (mpi_helper_->IsRankNumber(0)) { - // Some debug output - switch (nesting_mode.value()) { - case NestingMode::Detection: - std::cout << "nesting mode set to: " - << "Detection (?)" << std::endl; - break; - case NestingMode::NotProperlyNested: - std::cout << "nesting mode set to: " - << "NotProperlyNested" << std::endl; - break; - case NestingMode::ProperlyNested: - std::cout << "nesting mode set to: " - << "ProperlyNested" << std::endl; - break; + + if (!nesmik_on_) { + // early exit otherwise + if (mpi_helper_->IsRankNumber(0)) { + std::cout << "neSmiK Info: " << env_backend.getEnvName() + << " not set, ignoring calls to neSmiK" << std::endl; } + did_initialize_ = true; + return; } - if (stringsAreCaseInsensitiveEqual("ENV", std::string(backend))) { - // We instantiate the variable here, because its only required if the - // backend is set to "env". - EnvironmentVariable env_backend = - EnvironmentVariable( - "BACKEND", - "Set the backend to use, when init with \"env\" backend name.", - true); + // start backend selection + bool backend_available = + checkIfBackendAvailable(env_backend.getValue().value()); - // Unwraping the std::optional is safe because the variable is required. - backend = env_backend.getValue().value(); + if (!backend_available) { if (mpi_helper_->IsRankNumber(0)) { - std::cout << "Reading Backend from environment variable: " - << env_backend.getEnvName() << "=" << backend << std::endl; + std::cout << "neSmiK Fatal: Couldn't find a backend with name \"" + << env_backend.getValue().value() << "\"" << std::endl; } + Terminator::exit(); } - // next do backend selection: + const std::string backend = env_backend.getValue().value(); - switch (nesting_mode.value()) { - case NestingMode::Detection: - pn_annotation_strategy_ = std::make_unique(); - backend_selection_ = BackendSelection::ProperlyNested; - break; + EnvironmentVariable not_properly_nested_hint_env = + EnvironmentVariable( + "NOT_PROPERLY_NESTED", + "Give Hint about not properly nested nature of code", false); + + auto nesting_mode = not_properly_nested_hint_env.getValue().value_or(false) + ? NestingMode::NotProperlyNested + : NestingMode::ProperlyNested; + + if (nesting_mode == NestingMode::NotProperlyNested) { + if (mpi_helper_->IsRankNumber(0)) { + std::cout << "neSmiK assumes not properly nested behavior, so the " + "ProperlyNested Backends are not available" + << std::endl; + } + } + switch (nesting_mode) { case NestingMode::ProperlyNested: TryInitProperlyNestedBackend(backend); // we preferably use a Properly nested backend, // but if this is not possible, we will select the not properly nested // one if (pn_annotation_strategy_ != nullptr) { - backend_selection_ = BackendSelection::ProperlyNested; + backend_selection_ = BackendMode::ProperlyNested; break; // we break here if we already inited the backend } // we inform the user that ProperlyNested initialization failed, and // fallthrough if (mpi_helper_->IsRankNumber(0)) { - std::cout - << "Could not find a matching ProperlyNested backend with name " - << backend << std::endl; - std::cout << "Now looking for a NotProperlyNested backend, as they " + std::cout << "neSmik Info: Could not find a ProperlyNested " + "backend with name " + << backend + << ", now looking for a NotProperlyNested " + "backend, as they " "support ProperlyNested ones" << std::endl; } @@ -158,41 +153,61 @@ void Delegator::Init(std::string_view nesting_mode_in, // nested backend, which failed, or we are in not properly nested mode. InitNonProperlyNestedBackends(backend); if (npn_annotation_strategy_ != nullptr) { - backend_selection_ = BackendSelection::NotProperlyNested; + backend_selection_ = BackendMode::NotProperlyNested; + } else { + // We need to crash here because we couldn't find a Not properly nested + // backend with the name + if (mpi_helper_->IsRankNumber(0)) { + std::cout + << "neSmiK Fatal: Couldn't find a NotProperlyNested backend " + "with name " + << '"' << backend << '"' << std::endl; + } + Terminator::exit(); } break; } switch (backend_selection_) { - case BackendSelection::NotProperlyNested: - return npn_annotation_strategy_->Init(); + case BackendMode::NotProperlyNested: + npn_annotation_strategy_->Init(); break; - case BackendSelection::ProperlyNested: - return pn_annotation_strategy_->Init(); + case BackendMode::ProperlyNested: + pn_annotation_strategy_->Init(); break; } + + if (mpi_helper_->IsRankNumber(0)) { + std::cout << "nesMiK Info: Successfully initialized with backend: \"" + << backend << "\"" << std::endl; + } } // should be thread safe to call? void Delegator::RegionStart(std::string_view name) { + if (!nesmik_on_) { + return; + } name_stack_.push(std::string(name)); - switch (backend_selection_) { - case BackendSelection::NotProperlyNested: + case BackendMode::NotProperlyNested: npn_annotation_strategy_->RegionStart({name}); break; - case BackendSelection::ProperlyNested: + case BackendMode::ProperlyNested: pn_annotation_strategy_->RegionStart({name, name_stack_}); break; } } void Delegator::RegionStop(std::string_view name) { + if (!nesmik_on_) { + return; + } switch (backend_selection_) { - case BackendSelection::NotProperlyNested: + case BackendMode::NotProperlyNested: npn_annotation_strategy_->RegionStop({name}); break; - case BackendSelection::ProperlyNested: + case BackendMode::ProperlyNested: pn_annotation_strategy_->RegionStopLast({name, name_stack_}); break; } @@ -206,14 +221,17 @@ void Delegator::RegionStop(std::string_view name) { }; void Delegator::RegionStopLast() { + if (!nesmik_on_) { + return; + } const std::string stack_empty = "NESMIK: STACK EMPTPY"; const std::string &last_region_name = name_stack_.empty() ? stack_empty : name_stack_.top(); switch (backend_selection_) { - case BackendSelection::ProperlyNested: + case BackendMode::ProperlyNested: pn_annotation_strategy_->RegionStopLast({last_region_name, name_stack_}); break; - case BackendSelection::NotProperlyNested: + case BackendMode::NotProperlyNested: npn_annotation_strategy_->RegionStop({last_region_name}); break; } @@ -224,11 +242,14 @@ void Delegator::RegionStopLast() { } void Delegator::Finalize() { + if (!nesmik_on_) { + return; + } switch (backend_selection_) { - case BackendSelection::NotProperlyNested: + case BackendMode::NotProperlyNested: return npn_annotation_strategy_->Finalize(); break; - case BackendSelection::ProperlyNested: + case BackendMode::ProperlyNested: return pn_annotation_strategy_->Finalize(); break; } diff --git a/src/delegator.hpp b/src/delegator.hpp index deb18e65803e1ced170bcbfefc7712637decde1a..a9f0055c94fe339ca509ecb66b7887e27113f297 100644 --- a/src/delegator.hpp +++ b/src/delegator.hpp @@ -8,12 +8,11 @@ #include enum class NestingMode { - Detection, // When selecting the very special Detection backend - ProperlyNested, // Application is properly nested + ProperlyNested, // Application is properly nested (Default) NotProperlyNested // Application annotation is not properly nested }; -enum class BackendSelection { ProperlyNested, NotProperlyNested }; +enum class BackendMode { ProperlyNested, NotProperlyNested }; class Delegator { private: @@ -24,12 +23,16 @@ class Delegator { inline static thread_local std::stack name_stack_; - inline static BackendSelection backend_selection_; + static const std::vector available_backends; + + inline static BackendMode backend_selection_; + inline static bool nesmik_on_{false}; + inline static bool did_initialize_{false}; inline static std::unique_ptr mpi_helper_; public: - static void Init(std::string_view nesting_mode, std::string_view backend); + static void Init(); static void RegionStart(std::string_view name); static void RegionStop(std::string_view name); static void RegionStopLast(); @@ -38,5 +41,7 @@ class Delegator { private: static void InitNonProperlyNestedBackends(const std::string &backend); static void TryInitProperlyNestedBackend(const std::string &backend); + + static bool checkIfBackendAvailable(const std::string &backend); }; #endif // NESMIK_DELEGATOR_HPP diff --git a/src/nesmik.cpp b/src/nesmik.cpp index b818587aa750339f3d8377cf77b7b87aca789f5a..6954e5e1c17307443abf178757a769af7356561a 100644 --- a/src/nesmik.cpp +++ b/src/nesmik.cpp @@ -6,9 +6,7 @@ // provides a c-like way to call things with just a function compared to // instantiate a class. namespace nesmik { -void init(const std::string &nesting_mode, const std::string &backend) { - return Delegator::Init(nesting_mode, backend); -} +void nesmik_init() { return Delegator::Init(); } void region_start(const std::string &name) { return Delegator::RegionStart(name); } @@ -17,5 +15,5 @@ void region_stop(const std::string &name) { } void region_stop_last() { return Delegator::RegionStopLast(); } -void finalize() { return Delegator::Finalize(); } +void nesmik_finalize() { return Delegator::Finalize(); } } // namespace nesmik diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index d058970f81637d045bcf8ccbd464bd475e1cfa67..bd13654c9b028a02a10d75db1306c65897a33552 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -1 +1 @@ -target_sources(nesmik PRIVATE environment_variable.cpp parallelism_helper.cpp string_helpers.cpp) +target_sources(nesmik PRIVATE environment_variable.cpp parallelism_helper.cpp string_helpers.cpp terminator.cpp) diff --git a/src/utils/environment_variable.hpp b/src/utils/environment_variable.hpp index e370c67a5bbf47a119f79528170719234d849b30..f071d987ada09e4c5fbee02f11ab2eb5bb2cf84a 100644 --- a/src/utils/environment_variable.hpp +++ b/src/utils/environment_variable.hpp @@ -46,7 +46,7 @@ class EnvironmentVariable { private: std::string variable_name_; std::string description_; - std::optional value_; + std::optional value_{std::nullopt}; public: std::optional getValue() const { return value_; } diff --git a/src/utils/parallelism_helper.cpp b/src/utils/parallelism_helper.cpp index 61734eab58d14b70cd9558f5c71438cb70b9b118..2955cc4108acd2643eae001bdecdbf7e53140134 100644 --- a/src/utils/parallelism_helper.cpp +++ b/src/utils/parallelism_helper.cpp @@ -2,6 +2,15 @@ #include #include +struct MPIInformation { + bool mpi_is_initialized{false}; + int comm_size{1}; + int rank{0}; + bool valid{false}; // is a valid MPI information +}; + +static MPIInformation mpi_information; + #ifdef WITH_MPI #include @@ -16,17 +25,21 @@ bool MPIHelper::IsRankNumber(int asked_rank) const { int MPIHelper::getRankNumber() const { return mpi_comm_rank; } MPIHelper::MPIHelper() { - // First check if MPI is initialized - int is_initialized; - MPI_Initialized(&is_initialized); - mpi_is_initialized_ = static_cast(is_initialized); - - if (mpi_is_initialized_) { - MPI_Comm_size(MPI_COMM_WORLD, &mpi_comm_size); - MPI_Comm_rank(MPI_COMM_WORLD, &mpi_comm_rank); - - is_using_mpi_ = mpi_comm_size > 1; + if (!mpi_information.valid) { + int is_initialized; + MPI_Initialized(&is_initialized); + mpi_information.mpi_is_initialized = static_cast(is_initialized); + if (mpi_information.mpi_is_initialized) { + MPI_Comm_size(MPI_COMM_WORLD, &mpi_information.comm_size); + MPI_Comm_rank(MPI_COMM_WORLD, &mpi_information.rank); + } + mpi_information.valid = true; } + + mpi_is_initialized_ = mpi_information.mpi_is_initialized; + mpi_comm_size = mpi_information.comm_size; + mpi_comm_rank = mpi_information.rank; + is_using_mpi_ = mpi_comm_size > 1; } #else diff --git a/src/utils/parallelism_helper.hpp b/src/utils/parallelism_helper.hpp index a7ff3a0311e427c96b71923696a4d7c2d34a0474..7561d026345079f38b3035538cf2753391f296e3 100644 --- a/src/utils/parallelism_helper.hpp +++ b/src/utils/parallelism_helper.hpp @@ -4,6 +4,7 @@ Small helper class that can be used by Backends to Check MPI status in the application that is running */ + class MPIHelper { private: // Default values for non-MPI execution diff --git a/src/utils/terminator.cpp b/src/utils/terminator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b9b3ca0653db87e9e8a35874ea57823bcee8b4ee --- /dev/null +++ b/src/utils/terminator.cpp @@ -0,0 +1,22 @@ +#include "terminator.hpp" +#ifdef WITH_MPI +#include +#endif +#include +#include +#include + +void Terminator::exit(int exitcode) { + MPIHelper mpi_helper; + if (mpi_helper.IsRankNumber(0)) { + std::cout << "neSmiK Fatal: Now aborting execution" << std::endl; + } +#ifdef WITH_MPI + if (mpi_helper.IsUsingMPI()) { + MPI_Abort(MPI_COMM_WORLD, exitcode); + } else +#endif + { + std::exit(exitcode); + } +} diff --git a/src/utils/terminator.hpp b/src/utils/terminator.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e67e452db66e8d9dd12afc51751f5297df9f8fda --- /dev/null +++ b/src/utils/terminator.hpp @@ -0,0 +1,9 @@ +#ifndef NESMIK_TERMINATOR_HPP +#define NESMIK_TERMINATOR_HPP + +class Terminator { + public: + static void exit(int exitcode = 1); +}; + +#endif // NESMIK_TERMINATOR_HPP diff --git a/tests/cpp/TestCppDLB.cpp b/tests/cpp/TestCppDLB.cpp index 89fe69bbb7f5cc8a269f84c39aa1ca113863b025..7bc2d7635b7697f356fe5c83295ed59077cd6860 100644 --- a/tests/cpp/TestCppDLB.cpp +++ b/tests/cpp/TestCppDLB.cpp @@ -1,8 +1,8 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("NotProperlyNested", "TALP"); + nesmik::nesmik_init(); nesmik::region_start("Default"); nesmik::region_stop("Default"); - nesmik::finalize(); + nesmik::nesmik_finalize(); } diff --git a/tests/cpp/TestCppExtraeTypeStack.cpp b/tests/cpp/TestCppExtraeTypeStack.cpp index 64942a6188e6e1d844ab2699acf89319cd093392..6adb31a1a3f54a370fd80dc6f3f42d96834be8d0 100644 --- a/tests/cpp/TestCppExtraeTypeStack.cpp +++ b/tests/cpp/TestCppExtraeTypeStack.cpp @@ -1,7 +1,7 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("ProperlyNested", "Extrae::TypeStack"); + nesmik::nesmik_init(); nesmik::region_start("init"); nesmik::region_start("init_ts"); @@ -13,5 +13,5 @@ int main() { nesmik::region_start("init_ts"); nesmik::region_stop("init_ts"); - nesmik::finalize(); + nesmik::nesmik_finalize(); } diff --git a/tests/cpp/TestCppLink.cpp b/tests/cpp/TestCppLink.cpp index e56ddbb0b61d9d5256092cc15657f7a88630588b..7bc2d7635b7697f356fe5c83295ed59077cd6860 100644 --- a/tests/cpp/TestCppLink.cpp +++ b/tests/cpp/TestCppLink.cpp @@ -1,8 +1,8 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("ProperlyNested", "Default"); + nesmik::nesmik_init(); nesmik::region_start("Default"); nesmik::region_stop("Default"); - nesmik::finalize(); + nesmik::nesmik_finalize(); } diff --git a/tests/cpp/TestCppTalpTree.cpp b/tests/cpp/TestCppTalpTree.cpp index 1ecfbe2bea8084e8b1425b93d839378712b9f0e5..2abf26b2db514f5168cab9a8291aa025ee0d32dc 100644 --- a/tests/cpp/TestCppTalpTree.cpp +++ b/tests/cpp/TestCppTalpTree.cpp @@ -1,7 +1,7 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("ProperlyNested", "TALP-Tree"); + nesmik::nesmik_init(); nesmik::region_start("Top"); nesmik::region_start("child-1"); nesmik::region_start("child-1.1"); @@ -14,5 +14,5 @@ int main() { nesmik::region_stop("child-2.1"); nesmik::region_stop("child-2"); nesmik::region_stop("Top"); - nesmik::finalize(); + nesmik::nesmik_finalize(); } diff --git a/tests/cpp/TestCppTalpTreeMPI.cpp b/tests/cpp/TestCppTalpTreeMPI.cpp index 8576b6a9e0ee06d478dde9f79917da421dc9e6e3..525a3acd35bb01a37fff639a0cc8fbd29d65a315 100644 --- a/tests/cpp/TestCppTalpTreeMPI.cpp +++ b/tests/cpp/TestCppTalpTreeMPI.cpp @@ -3,7 +3,7 @@ #include "nesmik/nesmik.hpp" int main() { MPI_Init(NULL, NULL); - nesmik::init("ProperlyNested", "TALP-Tree"); + nesmik::nesmik_init(); nesmik::region_start("Top"); nesmik::region_start("child-1"); nesmik::region_start("child-1.1"); @@ -16,6 +16,6 @@ int main() { nesmik::region_stop("child-2.1"); nesmik::region_stop("child-2"); nesmik::region_stop("Top"); - nesmik::finalize(); + nesmik::nesmik_finalize(); MPI_Finalize(); } diff --git a/tests/cpp/TestRegionStopLast.cpp b/tests/cpp/TestRegionStopLast.cpp index 6bc07cb88f7a8c2cce97a9a7ee31a32cd25c67da..5f64f06fa1c5ed275f540a12d4d091c4b408f665 100644 --- a/tests/cpp/TestRegionStopLast.cpp +++ b/tests/cpp/TestRegionStopLast.cpp @@ -1,12 +1,12 @@ #include "nesmik/nesmik.hpp" int main() { - nesmik::init("ProperlyNested", "Default"); + nesmik::nesmik_init(); nesmik::region_start("Test0-1"); nesmik::region_start("Test1-1"); nesmik::region_stop("Test1-1"); nesmik::region_start("Test1-2"); nesmik::region_stop_last(); nesmik::region_stop_last(); - nesmik::finalize(); + nesmik::nesmik_finalize(); } diff --git a/tests/fortran/TestFortranModule.f90 b/tests/fortran/TestFortranModule.f90 index b2d288c8df14b77b196551de2a1d4d7f77d893fd..0411cf1c3bd57e1ec287daf99319ecb62addbea2 100644 --- a/tests/fortran/TestFortranModule.f90 +++ b/tests/fortran/TestFortranModule.f90 @@ -1,5 +1,7 @@ program do_sample use nesmik_mod - call init("ProperlyNested","Default") + call nesmik_init() call region_start("test") + call region_stop_last() + call nesmik_finalize() end program do_sample