From 4d3dd79eb4303f4c9b3928d72b67a34a09d1bf30 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Wed, 24 Jul 2024 19:40:32 +0200 Subject: [PATCH 01/14] - Remove the two initialize arguments - move to nesmik_prefix for init and fini --- include/nesmik/nesmik.hpp | 5 +- src/bindings/nesmik.json | 370 ++++----------------------- src/bindings/nesmik.log | 14 +- src/bindings/nesmik.yaml | 7 +- src/bindings/typesnesmik.h | 6 +- src/bindings/utilnesmik.cpp | 2 +- src/bindings/wrapfnesmik.f | 50 +--- src/bindings/wrapnesmik.cpp | 39 +-- src/bindings/wrapnesmik.h | 17 +- src/delegator.cpp | 36 +-- src/delegator.hpp | 2 +- src/nesmik.cpp | 6 +- tests/cpp/TestCppDLB.cpp | 4 +- tests/cpp/TestCppExtraeTypeStack.cpp | 4 +- tests/cpp/TestCppLink.cpp | 4 +- tests/cpp/TestCppTalpTree.cpp | 4 +- tests/cpp/TestCppTalpTreeMPI.cpp | 4 +- tests/cpp/TestRegionStopLast.cpp | 4 +- tests/fortran/TestFortranModule.f90 | 4 +- 19 files changed, 130 insertions(+), 452 deletions(-) diff --git a/include/nesmik/nesmik.hpp b/include/nesmik/nesmik.hpp index 80b192e..0f69bb3 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/bindings/nesmik.json b/src/bindings/nesmik.json index 96f8aba..4048e9f 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 3fbcba9..7c263be 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 57662be..173e2f4 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 579ec89..faadcb7 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 d81afb7..153565b 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 9e9b1ca..beb96a6 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 91d2230..b78a975 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 80e85cf..e049f91 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 51ff083..f3d1f76 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -70,19 +70,24 @@ void Delegator::TryInitProperlyNestedBackend(const std::string &backend) { #endif } -void Delegator::Init(std::string_view nesting_mode_in, - std::string_view backend_in) { +void Delegator::Init() { mpi_helper_ = std::make_unique(); - std::string backend = std::string(backend_in); + EnvironmentVariable env_backend = + EnvironmentVariable( + "BACKEND", + "Set the backend to use, when init with \"env\" backend name.", + false); + + std::string backend = env_backend.getValue().value_or("Default"); if (mpi_helper_->IsRankNumber(0)) { - std::cout << "neSmiK init called with program nesting: " << nesting_mode_in - << " and backend: " << backend << std::endl; + std::cout << "Reading Backend from environment variable: " + << env_backend.getEnvName() << "=" << backend << std::endl; } // now determine nesting mode - auto nesting_mode = getNestingMode(std::string(nesting_mode_in)); + auto nesting_mode = getNestingMode(std::string("ProperlyNested")); if (!nesting_mode.has_value()) { std::cout << "Something went wrong when selecting the nesting mode, " "please make sure to spell it correctly" @@ -107,25 +112,6 @@ void Delegator::Init(std::string_view nesting_mode_in, } } - 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); - - // Unwraping the std::optional is safe because the variable is required. - backend = env_backend.getValue().value(); - if (mpi_helper_->IsRankNumber(0)) { - std::cout << "Reading Backend from environment variable: " - << env_backend.getEnvName() << "=" << backend << std::endl; - } - } - - // next do backend selection: - switch (nesting_mode.value()) { case NestingMode::Detection: pn_annotation_strategy_ = std::make_unique(); diff --git a/src/delegator.hpp b/src/delegator.hpp index deb18e6..9499661 100644 --- a/src/delegator.hpp +++ b/src/delegator.hpp @@ -29,7 +29,7 @@ class Delegator { 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(); diff --git a/src/nesmik.cpp b/src/nesmik.cpp index b818587..6954e5e 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/tests/cpp/TestCppDLB.cpp b/tests/cpp/TestCppDLB.cpp index 89fe69b..7bc2d76 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 64942a6..6adb31a 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 e56ddbb..7bc2d76 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 1ecfbe2..2abf26b 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 8576b6a..525a3ac 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 6bc07cb..5f64f06 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 b2d288c..0411cf1 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 -- GitLab From dc844542fce25885f6ff30c8a13a91c5c1712ad1 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 25 Jul 2024 09:54:07 +0200 Subject: [PATCH 02/14] move to string --- src/backends/dlb/dlb_talp_tree/dlb_talp_tree.hpp | 2 +- src/backends/extrae/extrae_type_stack.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 f013186..a5073a1 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/extrae/extrae_type_stack.hpp b/src/backends/extrae/extrae_type_stack.hpp index df59582..02370f8 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; -- GitLab From cec38cf95e94536ab386e5de24b205b298a385ec Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 25 Jul 2024 09:54:28 +0200 Subject: [PATCH 03/14] Add terminator --- src/utils/terminator.cpp | 12 ++++++++++++ src/utils/terminator.hpp | 11 +++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/utils/terminator.cpp create mode 100644 src/utils/terminator.hpp diff --git a/src/utils/terminator.cpp b/src/utils/terminator.cpp new file mode 100644 index 0000000..f6f72d9 --- /dev/null +++ b/src/utils/terminator.cpp @@ -0,0 +1,12 @@ +#include "terminator.hpp" +#ifdef WITH_MPI +#include +#endif + +void Terminator::exit(int exitcode) { +#ifdef WITH_MPI + MPI_Abort(MPI_COMM_WORLD, exitcode); +#else + exit(exitcode); +#endif +} diff --git a/src/utils/terminator.hpp b/src/utils/terminator.hpp new file mode 100644 index 0000000..255efe8 --- /dev/null +++ b/src/utils/terminator.hpp @@ -0,0 +1,11 @@ +#ifndef NESMIK_TERMINATOR_HPP +#define NESMIK_TERMINATOR_HPP + +#include +#include +class Terminator { + public: + static void exit(int exitcode = 1); +}; + +#endif // NESMIK_TERMINATOR_HPP -- GitLab From 0e73343a6e60b6d35c9a39c8d91fb2e6d5829557 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 25 Jul 2024 09:54:56 +0200 Subject: [PATCH 04/14] Make it a bit more obivous how the optional is default constructed --- src/utils/environment_variable.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/environment_variable.hpp b/src/utils/environment_variable.hpp index e370c67..f071d98 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_; } -- GitLab From 7d077d51d9f7a67610c81704a3140ea0d5e53f9d Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 25 Jul 2024 09:55:15 +0200 Subject: [PATCH 05/14] Add terminator also in src --- src/utils/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index d058970..bd13654 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) -- GitLab From e8176f7fe5da5a5b69b68823f40e13cf5457bbbd Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 25 Jul 2024 09:55:45 +0200 Subject: [PATCH 06/14] global objects vs: a lot of MPI requests... pick your battles --- src/utils/parallelism_helper.cpp | 33 ++++++++++++++++++++++---------- src/utils/parallelism_helper.hpp | 1 + 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/utils/parallelism_helper.cpp b/src/utils/parallelism_helper.cpp index 61734ea..2955cc4 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 a7ff3a0..7561d02 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 -- GitLab From e0e4b452dff788a3216dfa0bd4c6ffea9ed52067 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 25 Jul 2024 09:58:08 +0200 Subject: [PATCH 07/14] Modify delegator to incorprate new changed behavior --- src/delegator.cpp | 173 +++++++++++++++++++++++++++------------------- src/delegator.hpp | 13 ++-- 2 files changed, 109 insertions(+), 77 deletions(-) diff --git a/src/delegator.cpp b/src/delegator.cpp index f3d1f76..5dc25df 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,13 +32,6 @@ 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) { @@ -70,7 +50,28 @@ void Delegator::TryInitProperlyNestedBackend(const std::string &backend) { #endif } +const std::vector Delegator::available_backends = { +#ifdef ENABLE_DLB + DLBTalpTreeStrategy::name, DLBTalpStrategy::name, +#endif +#ifdef ENABLE_EXTRAE + ExtraeTypeStackStrategy::name, +#endif + "Default", "Detection"}; + +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; +} + void Delegator::Init() { + if (did_initialize_) { + return; + } mpi_helper_ = std::make_unique(); EnvironmentVariable env_backend = @@ -78,62 +79,67 @@ void Delegator::Init() { "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 (!nesmik_on_) { + // early exit otherwise + did_initialize_ = true; + return; + } + + // start backend selection + bool backend_available = + checkIfBackendAvailable(env_backend.getValue().value()); - std::string backend = env_backend.getValue().value_or("Default"); - - if (mpi_helper_->IsRankNumber(0)) { - std::cout << "Reading Backend from environment variable: " - << env_backend.getEnvName() << "=" << backend << std::endl; - } - - // now determine nesting mode - auto nesting_mode = getNestingMode(std::string("ProperlyNested")); - 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); - } - 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 (!backend_available) { + if (mpi_helper_->IsRankNumber(0)) { + std::cout << "neSmiK Fatal: Couldn't find backend with name " + << env_backend.getValue().value() << std::endl; + std::cout << "neSmiK Fatal: Now aborting execution" << std::endl; } + Terminator::exit(); } - switch (nesting_mode.value()) { - case NestingMode::Detection: - pn_annotation_strategy_ = std::make_unique(); - backend_selection_ = BackendSelection::ProperlyNested; - break; + const std::string backend = env_backend.getValue().value(); + + 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 matching ProperlyNested " + "backend with name " + << backend << std::endl; + std::cout << "neSmik Info: Now looking for a NotProperlyNested " + "backend, as they " "support ProperlyNested ones" << std::endl; } @@ -144,16 +150,26 @@ void Delegator::Init() { // 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 NotProperlyNested backend " + "with name " + << backend << std::endl; + std::cout << "neSmiK Fatal: Now aborting execution" << std::endl; + } + Terminator::exit(); } break; } switch (backend_selection_) { - case BackendSelection::NotProperlyNested: + case BackendMode::NotProperlyNested: return npn_annotation_strategy_->Init(); break; - case BackendSelection::ProperlyNested: + case BackendMode::ProperlyNested: return pn_annotation_strategy_->Init(); break; } @@ -161,24 +177,29 @@ void Delegator::Init() { // 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; } @@ -192,14 +213,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; } @@ -210,11 +234,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 9499661..a9f0055 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,7 +23,11 @@ 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_; @@ -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 -- GitLab From a62ab09d105ac31ab894900715213eff2a00d650 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 25 Jul 2024 11:09:40 +0200 Subject: [PATCH 08/14] Make output a bit nicer --- src/delegator.cpp | 36 ++++++++++++++++++++++-------------- src/utils/terminator.cpp | 15 +++++++++++++-- src/utils/terminator.hpp | 2 -- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/delegator.cpp b/src/delegator.cpp index 5dc25df..2439203 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -35,8 +35,8 @@ void Delegator::InitNonProperlyNestedBackends(const std::string &backend) { } 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) { @@ -86,6 +86,10 @@ void Delegator::Init() { 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; } @@ -96,9 +100,8 @@ void Delegator::Init() { if (!backend_available) { if (mpi_helper_->IsRankNumber(0)) { - std::cout << "neSmiK Fatal: Couldn't find backend with name " - << env_backend.getValue().value() << std::endl; - std::cout << "neSmiK Fatal: Now aborting execution" << std::endl; + std::cout << "neSmiK Fatal: Couldn't find a backend with name \"" + << env_backend.getValue().value() << "\"" << std::endl; } Terminator::exit(); } @@ -135,10 +138,10 @@ void Delegator::Init() { // we inform the user that ProperlyNested initialization failed, and // fallthrough if (mpi_helper_->IsRankNumber(0)) { - std::cout << "neSmik Info: Could not find a matching ProperlyNested " + std::cout << "neSmik Info: Could not find a ProperlyNested " "backend with name " - << backend << std::endl; - std::cout << "neSmik Info: Now looking for a NotProperlyNested " + << backend + << ", now looking for a NotProperlyNested " "backend, as they " "support ProperlyNested ones" << std::endl; @@ -155,10 +158,10 @@ void Delegator::Init() { // 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 NotProperlyNested backend " - "with name " - << backend << std::endl; - std::cout << "neSmiK Fatal: Now aborting execution" << std::endl; + std::cout + << "neSmiK Fatal: Couldn't find a NotProperlyNested backend " + "with name " + << '"' << backend << '"' << std::endl; } Terminator::exit(); } @@ -167,12 +170,17 @@ void Delegator::Init() { switch (backend_selection_) { case BackendMode::NotProperlyNested: - return npn_annotation_strategy_->Init(); + npn_annotation_strategy_->Init(); break; case BackendMode::ProperlyNested: - return pn_annotation_strategy_->Init(); + 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? diff --git a/src/utils/terminator.cpp b/src/utils/terminator.cpp index f6f72d9..ba864ab 100644 --- a/src/utils/terminator.cpp +++ b/src/utils/terminator.cpp @@ -2,11 +2,22 @@ #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 - MPI_Abort(MPI_COMM_WORLD, exitcode); + if (mpi_helper.IsUsingMPI()) { + MPI_Abort(MPI_COMM_WORLD, exitcode); + } else { + std::exit(exitcode); + } #else - exit(exitcode); + std::exit(exitcode); #endif } diff --git a/src/utils/terminator.hpp b/src/utils/terminator.hpp index 255efe8..e67e452 100644 --- a/src/utils/terminator.hpp +++ b/src/utils/terminator.hpp @@ -1,8 +1,6 @@ #ifndef NESMIK_TERMINATOR_HPP #define NESMIK_TERMINATOR_HPP -#include -#include class Terminator { public: static void exit(int exitcode = 1); -- GitLab From edbfbe3541fbcaa5611e2281ba017352033a0463 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 25 Jul 2024 11:10:02 +0200 Subject: [PATCH 09/14] dont require env set to work with detection backend --- src/backends/detection/detection.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backends/detection/detection.hpp b/src/backends/detection/detection.hpp index e1d8758..ed7f499 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; -- GitLab From aa661827f83dd1ad01284b52eabf9f02e7e00dd8 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 25 Jul 2024 11:10:27 +0200 Subject: [PATCH 10/14] make dlb less verbose , fix SIT header --- src/backends/dlb/dlb/dlb.cpp | 10 ++-------- src/backends/dlb/dlb/dlb.hpp | 6 +++--- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/backends/dlb/dlb/dlb.cpp b/src/backends/dlb/dlb/dlb.cpp index dc35e99..a120bf5 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 876a524..d6a4abd 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 -- GitLab From c5b9765cc5889ac5490d1c7529c90c5418a8dc2e Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 25 Jul 2024 11:10:46 +0200 Subject: [PATCH 11/14] Scope output a bit more --- src/backends/default/default.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/backends/default/default.cpp b/src/backends/default/default.cpp index 0fe3a45..d3e50e3 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; } -- GitLab From a34607e202f5dd252f5ba905da5631b218e3d3ad Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 25 Jul 2024 11:20:05 +0200 Subject: [PATCH 12/14] Add missing return statement --- .../dlb/dlb_talp_tree/dlb_talp_tree_ascii_serializer.cpp | 1 + 1 file changed, 1 insertion(+) 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 dcfbecc..10267e6 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) { -- GitLab From c12cdd05d2bfddfca56ae1c01e1df5f3bf206400 Mon Sep 17 00:00:00 2001 From: VALENTIN SEITZ Date: Thu, 25 Jul 2024 17:41:20 +0200 Subject: [PATCH 13/14] Apply 1 suggestion(s) to 1 file(s) Co-authored-by: JOAN VINYALS YLLA CATALA --- src/utils/terminator.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/utils/terminator.cpp b/src/utils/terminator.cpp index ba864ab..7a35997 100644 --- a/src/utils/terminator.cpp +++ b/src/utils/terminator.cpp @@ -14,10 +14,9 @@ void Terminator::exit(int exitcode) { #ifdef WITH_MPI if (mpi_helper.IsUsingMPI()) { MPI_Abort(MPI_COMM_WORLD, exitcode); - } else { + } else +#endif + { std::exit(exitcode); } -#else - std::exit(exitcode); -#endif } -- GitLab From 2130a9abb765096447229d9046e4073a0cf92a08 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Thu, 25 Jul 2024 17:43:15 +0200 Subject: [PATCH 14/14] add some clang format stuff --- src/utils/terminator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/terminator.cpp b/src/utils/terminator.cpp index 7a35997..b9b3ca0 100644 --- a/src/utils/terminator.cpp +++ b/src/utils/terminator.cpp @@ -14,7 +14,7 @@ void Terminator::exit(int exitcode) { #ifdef WITH_MPI if (mpi_helper.IsUsingMPI()) { MPI_Abort(MPI_COMM_WORLD, exitcode); - } else + } else #endif { std::exit(exitcode); -- GitLab