[Openmp-commits] [openmp] 1fbdb03 - [OpenMP] libomp: omp_in_explicit_task() implemented.

via Openmp-commits openmp-commits at lists.llvm.org
Sat Mar 5 10:46:51 PST 2022


Author: AndreyChurbanov
Date: 2022-03-05T21:46:39+03:00
New Revision: 1fbdb03b1d2cb2ec9a3c84445db57b570a6e5d9a

URL: https://github.com/llvm/llvm-project/commit/1fbdb03b1d2cb2ec9a3c84445db57b570a6e5d9a
DIFF: https://github.com/llvm/llvm-project/commit/1fbdb03b1d2cb2ec9a3c84445db57b570a6e5d9a.diff

LOG: [OpenMP] libomp: omp_in_explicit_task() implemented.

Differential Revision: https://reviews.llvm.org/D120671

Added: 
    openmp/runtime/test/api/omp_in_explicit_task.c

Modified: 
    openmp/runtime/src/dllexports
    openmp/runtime/src/include/omp.h.var
    openmp/runtime/src/include/omp_lib.f90.var
    openmp/runtime/src/include/omp_lib.h.var
    openmp/runtime/src/kmp_ftn_entry.h
    openmp/runtime/src/kmp_ftn_os.h

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/src/dllexports b/openmp/runtime/src/dllexports
index 6e446658607a2..90fb3c4e02b05 100644
--- a/openmp/runtime/src/dllexports
+++ b/openmp/runtime/src/dllexports
@@ -556,6 +556,7 @@ kmp_set_disp_num_buffers                    890
     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
index 6c1bd23960482..8abd2428971b7 100644
--- 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.f90.var b/openmp/runtime/src/include/omp_lib.f90.var
index f475d8dbe688b..5feb299236bb7 100644
--- 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/include/omp_lib.h.var b/openmp/runtime/src/include/omp_lib.h.var
index 3a49b8a36bac9..987de7b7db70b 100644
--- 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/kmp_ftn_entry.h b/openmp/runtime/src/kmp_ftn_entry.h
index 53802b7a9c3c8..048fcf9d03974 100644
--- a/openmp/runtime/src/kmp_ftn_entry.h
+++ b/openmp/runtime/src/kmp_ftn_entry.h
@@ -1567,6 +1567,15 @@ void FTN_STDCALL FTN_DISPLAY_ENV(int verbose) {
 #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
index 66e1e1ecd2e61..d37c9c86028eb 100644
--- 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
index 0000000000000..6ecdba18cf86f
--- /dev/null
+++ b/openmp/runtime/test/api/omp_in_explicit_task.c
@@ -0,0 +1,49 @@
+// RUN: %libomp-compile-and-run
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <omp.h>
+
+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;
+}


        


More information about the Openmp-commits mailing list