diff --git a/openmp/runtime/src/dllexports b/openmp/runtime/src/dllexports --- a/openmp/runtime/src/dllexports +++ b/openmp/runtime/src/dllexports @@ -556,6 +556,7 @@ omp_get_interop_int 807 omp_get_interop_ptr 808 omp_get_interop_str 809 + omp_in_explicit_task 769 omp_null_allocator DATA omp_default_mem_alloc DATA diff --git a/openmp/runtime/src/include/omp.h.var b/openmp/runtime/src/include/omp.h.var --- a/openmp/runtime/src/include/omp.h.var +++ b/openmp/runtime/src/include/omp.h.var @@ -497,6 +497,9 @@ #pragma omp end declare variant # endif + /* OpenMP 5.2 */ + extern int __KAI_KMPC_CONVENTION omp_in_explicit_task(void); + # undef __KAI_KMPC_CONVENTION # undef __KMP_IMP diff --git a/openmp/runtime/src/include/omp_lib.h.var b/openmp/runtime/src/include/omp_lib.h.var --- a/openmp/runtime/src/include/omp_lib.h.var +++ b/openmp/runtime/src/include/omp_lib.h.var @@ -796,6 +796,11 @@ integer(omp_allocator_handle_kind), value :: allocator end subroutine omp_free + function omp_in_explicit_task() bind(c) + import + logical (kind=omp_logical_kind) omp_in_explicit_task + end function omp_in_explicit_task + ! *** ! *** kmp_* entry points ! *** diff --git a/openmp/runtime/src/include/omp_lib.f90.var b/openmp/runtime/src/include/omp_lib.f90.var --- a/openmp/runtime/src/include/omp_lib.f90.var +++ b/openmp/runtime/src/include/omp_lib.f90.var @@ -699,6 +699,11 @@ integer(omp_allocator_handle_kind), value :: allocator end subroutine omp_free + function omp_in_explicit_task() bind(c) + use omp_lib_kinds + logical (kind=omp_logical_kind) omp_in_explicit_task + end function omp_in_explicit_task + ! *** ! *** kmp_* entry points ! *** diff --git a/openmp/runtime/src/kmp_ftn_entry.h b/openmp/runtime/src/kmp_ftn_entry.h --- a/openmp/runtime/src/kmp_ftn_entry.h +++ b/openmp/runtime/src/kmp_ftn_entry.h @@ -1567,6 +1567,15 @@ #endif } +int FTN_STDCALL FTN_IN_EXPLICIT_TASK(void) { +#ifdef KMP_STUB + return 0; +#else + int gtid = __kmp_entry_gtid(); + return __kmp_thread_from_gtid(gtid)->th.th_current_task->td_flags.tasktype; +#endif +} + // GCC compatibility (versioned symbols) #ifdef KMP_USE_VERSION_SYMBOLS diff --git a/openmp/runtime/src/kmp_ftn_os.h b/openmp/runtime/src/kmp_ftn_os.h --- a/openmp/runtime/src/kmp_ftn_os.h +++ b/openmp/runtime/src/kmp_ftn_os.h @@ -134,6 +134,7 @@ #define FTN_PAUSE_RESOURCE_ALL omp_pause_resource_all #define FTN_GET_SUPPORTED_ACTIVE_LEVELS omp_get_supported_active_levels #define FTN_DISPLAY_ENV omp_display_env +#define FTN_IN_EXPLICIT_TASK omp_in_explicit_task #define FTN_FULFILL_EVENT omp_fulfill_event #define FTN_SET_NUM_TEAMS omp_set_num_teams #define FTN_GET_MAX_TEAMS omp_get_max_teams @@ -270,6 +271,7 @@ #define FTN_PAUSE_RESOURCE_ALL omp_pause_resource_all_ #define FTN_GET_SUPPORTED_ACTIVE_LEVELS omp_get_supported_active_levels_ #define FTN_DISPLAY_ENV omp_display_env_ +#define FTN_IN_EXPLICIT_TASK omp_in_explicit_task_ #define FTN_FULFILL_EVENT omp_fulfill_event_ #define FTN_SET_NUM_TEAMS omp_set_num_teams_ #define FTN_GET_MAX_TEAMS omp_get_max_teams_ @@ -404,6 +406,7 @@ #define FTN_PAUSE_RESOURCE_ALL OMP_PAUSE_RESOURCE_ALL #define FTN_GET_SUPPORTED_ACTIVE_LEVELS OMP_GET_SUPPORTED_ACTIVE_LEVELS #define FTN_DISPLAY_ENV OMP_DISPLAY_ENV +#define FTN_IN_EXPLICIT_TASK OMP_IN_EXPLICIT_TASK #define FTN_FULFILL_EVENT OMP_FULFILL_EVENT #define FTN_SET_NUM_TEAMS OMP_SET_NUM_TEAMS #define FTN_GET_MAX_TEAMS OMP_GET_MAX_TEAMS @@ -540,6 +543,7 @@ #define FTN_PAUSE_RESOURCE_ALL OMP_PAUSE_RESOURCE_ALL_ #define FTN_GET_SUPPORTED_ACTIVE_LEVELS OMP_GET_SUPPORTED_ACTIVE_LEVELS_ #define FTN_DISPLAY_ENV OMP_DISPLAY_ENV_ +#define FTN_IN_EXPLICIT_TASK OMP_IN_EXPLICIT_TASK_ #define FTN_FULFILL_EVENT OMP_FULFILL_EVENT_ #define FTN_SET_NUM_TEAMS OMP_SET_NUM_TEAMS_ #define FTN_GET_MAX_TEAMS OMP_GET_MAX_TEAMS_ diff --git a/openmp/runtime/test/api/omp_in_explicit_task.c b/openmp/runtime/test/api/omp_in_explicit_task.c new file mode 100644 --- /dev/null +++ b/openmp/runtime/test/api/omp_in_explicit_task.c @@ -0,0 +1,49 @@ +// RUN: %libomp-compile-and-run + +#include +#include +#include + +int main() +{ + int res; + res = omp_in_explicit_task(); + if (res) { + printf("error: omp_in_explicit_task: serial1 returned %d\n", res); + return 1; + } + #pragma omp parallel num_threads(2) + { + int r = omp_in_explicit_task(); + if (r) { + printf("error: omp_in_explicit_task: par #%d returned %d\n", + omp_get_thread_num(), r); + exit(1); + } + #pragma omp task + { + int r = omp_in_explicit_task(); + if (!r) { + printf("error: omp_in_explicit_task: task1 #%d returned %d\n", + omp_get_thread_num(), r); + exit(1); + } + } + #pragma omp task + { + int r = omp_in_explicit_task(); + if (!r) { + printf("error: omp_in_explicit_task: task2 #%d returned %d\n", + omp_get_thread_num(), r); + exit(1); + } + } + } + res = omp_in_explicit_task(); + if (res) { + printf("error: omp_in_explicit_task: serial2 returned %d\n", res); + return 1; + } + printf("passed\n"); + return 0; +}