diff --git a/include/nesmik/nesmik.hpp b/include/nesmik/nesmik.hpp index e7d14eaf646eb078ff4a6e4a8f33177420e58012..d350cf15a14239df713df305e7df3b5f6a22084c 100644 --- a/include/nesmik/nesmik.hpp +++ b/include/nesmik/nesmik.hpp @@ -4,5 +4,6 @@ namespace nesmik { void init(const std::string &nesting_mode, const std::string &backend); void region_start(const std::string &name); void region_stop(const std::string &name); +void region_stop_last(void); // only supported in PN backends void finalize(); } // namespace nesmik diff --git a/src/bindings/nesmik.json b/src/bindings/nesmik.json index f124649f4cb99034b597e41d11bfe558094fa40d..71ba9941a36527489ad3810c45316e5c1eb2413e 100644 --- a/src/bindings/nesmik.json +++ b/src/bindings/nesmik.json @@ -10,7 +10,7 @@ "C_generated_path": [ "arg_to_buffer" ], - "_PTR_F_C_index": "4", + "_PTR_F_C_index": "5", "ast": { "declarator": { "metaattrs": { @@ -158,7 +158,7 @@ } }, { - "": "4 ****************************************", + "": "5 ****************************************", "_generated": "arg_to_buffer", "ast": { "declarator": { @@ -320,7 +320,7 @@ "C_generated_path": [ "arg_to_buffer" ], - "_PTR_F_C_index": "5", + "_PTR_F_C_index": "6", "ast": { "declarator": { "metaattrs": { @@ -420,7 +420,7 @@ } }, { - "": "5 ****************************************", + "": "6 ****************************************", "_PTR_C_CXX_index": "1", "_generated": "arg_to_buffer", "ast": { @@ -527,7 +527,7 @@ "C_generated_path": [ "arg_to_buffer" ], - "_PTR_F_C_index": "6", + "_PTR_F_C_index": "7", "ast": { "declarator": { "metaattrs": { @@ -627,7 +627,7 @@ } }, { - "": "6 ****************************************", + "": "7 ****************************************", "_PTR_C_CXX_index": "2", "_generated": "arg_to_buffer", "ast": { @@ -731,6 +731,54 @@ }, { "": "3 ****************************************", + "ast": { + "declarator": { + "metaattrs": { + "intent": "subroutine" + }, + "name": "region_stop_last", + "params": [], + "typemap_name": "void" + }, + "specifier": [ + "void" + ], + "typemap_name": "void" + }, + "decl": "void region_stop_last(void)", + "declgen": "void region_stop_last(void)", + "linenumber": 11, + "name": "region_stop_last", + "options": {}, + "wrap": { + "c": true, + "f_c": true, + "fortran": true + }, + "zz_fmtdict": { + "C_name": "nesmik_region_stop_last", + "C_name_api": "region_stop_last", + "C_prototype": "void", + "C_return_type": "void", + "F_C_arguments": "", + "F_C_call": "c_region_stop_last", + "F_C_name": "region_stop_last", + "F_C_subprogram": "subroutine", + "F_arguments": "", + "F_name_api": "region_stop_last", + "F_name_function": "region_stop_last", + "F_name_generic": "region_stop_last", + "F_name_impl": "region_stop_last", + "F_subprogram": "subroutine", + "function_name": "region_stop_last", + "stmt0": "f_subroutine", + "stmt1": "f_subroutine", + "stmtc0": "c_subroutine", + "stmtc1": "c_subroutine" + } + }, + { + "": "4 ****************************************", "ast": { "declarator": { "metaattrs": { @@ -747,7 +795,7 @@ }, "decl": "void finalize()", "declgen": "void finalize(void)", - "linenumber": 11, + "linenumber": 12, "name": "finalize", "options": {}, "wrap": { diff --git a/src/bindings/nesmik.log b/src/bindings/nesmik.log index d90a031cc56849b692b3158349baadc778f46c32..3fbcba94a3995538c754aa0300f16915e513f183 100644 --- a/src/bindings/nesmik.log +++ b/src/bindings/nesmik.log @@ -5,12 +5,14 @@ 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) Close wrapnesmik.h Close wrapnesmik.cpp Fortran void init(const std::string & nesting_mode, const std::string & backend) +intent(subroutine) Fortran void region_start(const std::string & name) +intent(subroutine) Fortran void region_stop(const std::string & name) +intent(subroutine) +Fortran void 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) @@ -18,6 +20,7 @@ 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) Close wrapfnesmik.f Close utilnesmik.cpp diff --git a/src/bindings/nesmik.yaml b/src/bindings/nesmik.yaml index 2905d1df04c43d6604e900a47290e3936af6eeec..eb9d6b544114c44908e6bfdfaf841c1a7a5a3613 100644 --- a/src/bindings/nesmik.yaml +++ b/src/bindings/nesmik.yaml @@ -8,4 +8,5 @@ declarations: - decl: void init(const std::string &nesting_mode, const std::string &backend) - decl: void region_start(const std::string &name) - decl: void region_stop(const std::string &name) +- decl: void region_stop_last(void) - decl: void finalize() \ No newline at end of file diff --git a/src/bindings/wrapfnesmik.f b/src/bindings/wrapfnesmik.f index 74029b18382d67da8ba226397d59e05ee608d135..9e9b1ca6244e840a4fbc0373a1c7509f4414bda9 100644 --- a/src/bindings/wrapfnesmik.f +++ b/src/bindings/wrapfnesmik.f @@ -65,6 +65,11 @@ module nesmik_mod integer(C_INT), value, intent(IN) :: SHT_name_len end subroutine c_region_stop_bufferify + subroutine region_stop_last() & + bind(C, name="nesmik_region_stop_last") + implicit none + end subroutine region_stop_last + subroutine finalize() & bind(C, name="nesmik_finalize") implicit none diff --git a/src/bindings/wrapnesmik.cpp b/src/bindings/wrapnesmik.cpp index 925312841d989a69df05eca5621cd398ef35f936..7940f9cc96f3469d00e9566c7da89cf657b8b2b2 100644 --- a/src/bindings/wrapnesmik.cpp +++ b/src/bindings/wrapnesmik.cpp @@ -84,6 +84,13 @@ void nesmik_region_stop_bufferify(char *name, int SHT_name_len) // splicer end function.region_stop_bufferify } +void nesmik_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 diff --git a/src/bindings/wrapnesmik.h b/src/bindings/wrapnesmik.h index d8833afa498edbbd05bbd229be50c22fb91927f6..ec1afc648d047c30020afcacdbe189563a3db55e 100644 --- a/src/bindings/wrapnesmik.h +++ b/src/bindings/wrapnesmik.h @@ -34,6 +34,8 @@ void nesmik_region_stop(const char * name); void nesmik_region_stop_bufferify(char *name, int SHT_name_len); +void nesmik_region_stop_last(void); + void nesmik_finalize(void); #ifdef __cplusplus diff --git a/src/delegator.cpp b/src/delegator.cpp index 910ae949eb8bbb4c48b10de73140cb467d776acd..112ee248cdb9934e242237fe20eda6af67bca26c 100644 --- a/src/delegator.cpp +++ b/src/delegator.cpp @@ -152,6 +152,21 @@ void Delegator::RegionStop(std::string_view name) { } }; +void Delegator::RegionStopLast(){ + switch (nesting_mode_) { + + case NestingMode::NotProperlyNested: + std::cout << "Calling region_stop_last() is not supported in NotProperlyNested Backends" << std::endl; + break; + case NestingMode::Detection: + case NestingMode::ProperlyNested: + const std::string& last_region_name = name_stack_.top(); + pn_annotation_strategy_->RegionStopLast({last_region_name,name_stack_}); + if(!name_stack_.empty()) {name_stack_.pop();} + break; + } +} + void Delegator::Finalize() { switch (nesting_mode_) { diff --git a/src/delegator.hpp b/src/delegator.hpp index b9427831667220fe2f94e69a4a8ba8559d6d2a12..68b97ded84e78e1f8cb1fb3695dae91ebf5eb340 100644 --- a/src/delegator.hpp +++ b/src/delegator.hpp @@ -24,6 +24,7 @@ public: static void Init(std::string_view nesting_mode, std::string_view backend); static void RegionStart(std::string_view name); static void RegionStop(std::string_view name); + static void RegionStopLast(); static void Finalize(); private: diff --git a/src/nesmik.cpp b/src/nesmik.cpp index 34fa94204e77de733d70717533bd7a6b42a9ebef..1783839759e3ec6ec93d6358fce97ee8fab2ba59 100644 --- a/src/nesmik.cpp +++ b/src/nesmik.cpp @@ -15,5 +15,9 @@ void region_start(const std::string &name) { void region_stop(const std::string &name) { return Delegator::RegionStop(name); } + +void region_stop_last() { + return Delegator::RegionStopLast(); +} void finalize() { return Delegator::Finalize(); } } // namespace nesmik diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 32c9d067fcdd9c1b710b3feaccae2ffd7daf75db..dab8f22841e62526d2925a82b9c13049c345b025 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,6 +7,16 @@ add_test(NAME TestCppLink COMMAND TestCppLink) +add_executable(TestRegionStopLast cpp/TestRegionStopLast.cpp) +target_link_libraries(TestRegionStopLast nesmik::nesmik) +target_include_directories(TestRegionStopLast + PRIVATE ${NESMIK_PUBLIC_HEADERS}) + +add_test(NAME TestRegionStopLast + COMMAND TestRegionStopLast) + + + if(ENABLE_DLB) add_executable(TestCppDLB cpp/TestCppDLB.cpp) target_link_libraries(TestCppDLB nesmik::nesmik) diff --git a/tests/cpp/TestRegionStopLast.cpp b/tests/cpp/TestRegionStopLast.cpp new file mode 100644 index 0000000000000000000000000000000000000000..77a7e284b44a60bb0922a293eff4e6d7207990d1 --- /dev/null +++ b/tests/cpp/TestRegionStopLast.cpp @@ -0,0 +1,12 @@ +#include "nesmik/nesmik.hpp" + +int main() { + nesmik::init("ProperlyNested","Default"); + nesmik::region_start("Test0-1"); + nesmik::region_start("Test1-1"); + nesmik::region_stop_last(); + nesmik::region_start("Test1-2"); + nesmik::region_stop_last(); + nesmik::region_stop_last(); + nesmik::finalize(); +}