LLVM OpenMP 20.0.0git
kmp_detach_tasks_t3.c
Go to the documentation of this file.
1// RUN: %libomp-compile && env OMP_NUM_THREADS='3' %libomp-run
2// RUN: %libomp-compile && env OMP_NUM_THREADS='1' %libomp-run
3// The runtime currently does not get dependency information from GCC.
4// UNSUPPORTED: gcc
5
6#include <stdio.h>
7#include <omp.h>
8#include "omp_my_sleep.h"
9
10// detached untied
11#define PTASK_FLAG_DETACHABLE 0x40
12
13// OpenMP RTL interfaces
14typedef unsigned long long kmp_uint64;
15typedef long long kmp_int64;
16
17typedef struct ID {
18 int reserved_1;
19 int flags;
20 int reserved_2;
21 int reserved_3;
22 char *psource;
24
25// Compiler-generated code (emulation)
26typedef struct ident {
27 void* dummy; // not used in the library
29
30typedef enum kmp_event_type_t {
34
35typedef struct {
37 union {
38 void *task;
39 } ed;
41
42typedef struct shar { // shareds used in the task
44
45typedef struct task {
47 int(*routine)(int,struct task*);
48 int part_id;
49// void *destructor_thunk; // optional, needs flag setting if provided
50// int priority; // optional, needs flag setting if provided
51// ------------------------------
52// privates used in the task:
53 omp_event_handle_t evt;
55
56typedef struct DEP {
57 size_t addr;
58 size_t len;
59 unsigned char flags;
61
62typedef int(* task_entry_t)( int, ptask );
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67extern int __kmpc_global_thread_num(void *id_ref);
68extern int** __kmpc_omp_task_alloc(id *loc, int gtid, int flags,
69 size_t sz, size_t shar, task_entry_t rtn);
70extern int __kmpc_omp_task_with_deps(id *loc, int gtid, ptask task, int nd,
71 dep *dep_lst, int nd_noalias, dep *noalias_dep_lst);
72extern int __kmpc_omp_task(id *loc, int gtid, kmp_task_t *task);
73extern omp_event_handle_t __kmpc_task_allow_completion_event(
74 ident_t *loc_ref, int gtid, kmp_task_t *task);
75#ifdef __cplusplus
76}
77#endif
78
79int volatile checker;
80
81// User's code, outlined into task entry
82int task_entry(int gtid, ptask task) {
83 checker = 1;
84 return 0;
85}
86
87int main() {
88 int i, j, gtid = __kmpc_global_thread_num(NULL);
89 int nt = omp_get_max_threads();
90 ptask task;
91 pshareds psh;
92 checker = 0;
94 #pragma omp parallel //num_threads(N)
95 {
96 #pragma omp master
97 {
98 #pragma omp task depend(inout:nt)
99 {
100 my_sleep(2.0);
101 }
102 int gtid = __kmpc_global_thread_num(NULL);
103 omp_event_handle_t evt;
104/*
105 #pragma omp task detach(evt)
106 {}
107*/
109 sizeof(struct task),sizeof(struct shar),&task_entry);
110 psh = task->shareds;
111 evt = (omp_event_handle_t)__kmpc_task_allow_completion_event(NULL,gtid,task);
112 task->evt = evt;
113
114 dep sdep;
115 sdep.addr = (size_t)&nt;
116 sdep.len = 0L;
117 sdep.flags = 3;
118
119 __kmpc_omp_task_with_deps(NULL,gtid,task,1,&sdep,0,0);
120 //__kmpc_omp_task(NULL, gtid, task);
121
122 omp_fulfill_event(evt);
123
124 #pragma omp taskwait
125 ;
126// printf("after tw %d\n", omp_get_thread_num());
127 } // end master
128 } // end parallel
129
130 // check results
131 if (checker == 1) {
132 printf("passed\n");
133 return 0;
134 } else {
135 printf("failed\n");
136 return 1;
137 }
138}
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark d int
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
kmp_event_type_t
Definition: kmp.h:2596
struct shar * pshareds
int __kmpc_global_thread_num(void *id_ref)
struct task kmp_task_t
int __kmpc_omp_task_with_deps(id *loc, int gtid, ptask task, int nd, dep *dep_lst, int nd_noalias, dep *noalias_dep_lst)
struct ID id
struct task * ptask
int task_entry(int gtid, ptask task)
int volatile checker
struct DEP dep
int __kmpc_omp_task(id *loc, int gtid, kmp_task_t *task)
kmp_event_type_t
@ KMP_EVENT_UNINITIALIZED
@ KMP_EVENT_ALLOW_COMPLETION
int ** __kmpc_omp_task_alloc(id *loc, int gtid, int flags, size_t sz, size_t shar, task_entry_t rtn)
int(* task_entry_t)(int, ptask)
unsigned long long kmp_uint64
omp_event_handle_t __kmpc_task_allow_completion_event(ident_t *loc_ref, int gtid, kmp_task_t *task)
struct ident ident_t
#define PTASK_FLAG_DETACHABLE
int main()
long long kmp_int64
#define i
Definition: kmp_stub.cpp:87
#define omp_set_dynamic
Definition: kmp_stub.cpp:35
static void my_sleep(double sleeptime)
Utility function to have a sleep function with better resolution and which only stops one thread.
Definition: omp_my_sleep.h:24
static id loc
size_t len
unsigned char flags
size_t addr
int reserved_2
char * psource
int reserved_3
int reserved_1
The ident structure that describes a source location.
Definition: kmp.h:247
Definition: kmp.h:2472
int(* routine)(int, struct task *)
omp_event_handle_t evt
void ** shareds
int omp_get_max_threads()