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.
8 #include "omp_my_sleep.h"
11 #define PTASK_FLAG_DETACHABLE 0x40
13 // OpenMP RTL interfaces
14 typedef unsigned long long kmp_uint64
;
15 typedef long long kmp_int64
;
25 // Compiler-generated code (emulation)
26 typedef struct ident
{
27 void* dummy
; // not used in the library
30 typedef enum kmp_event_type_t
{
31 KMP_EVENT_UNINITIALIZED
= 0,
32 KMP_EVENT_ALLOW_COMPLETION
= 1
36 kmp_event_type_t type
;
42 typedef struct shar
{ // shareds used in the task
47 int(*routine
)(int,struct task
*);
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
;
62 typedef int(* task_entry_t
)( int, ptask
);
67 extern int __kmpc_global_thread_num(void *id_ref
);
68 extern int** __kmpc_omp_task_alloc(id
*loc
, int gtid
, int flags
,
69 size_t sz
, size_t shar
, task_entry_t rtn
);
70 extern 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
);
72 extern int __kmpc_omp_task(id
*loc
, int gtid
, kmp_task_t
*task
);
73 extern omp_event_handle_t
__kmpc_task_allow_completion_event(
74 ident_t
*loc_ref
, int gtid
, kmp_task_t
*task
);
81 // User's code, outlined into task entry
82 int task_entry(int gtid
, ptask task
) {
88 int i
, j
, gtid
= __kmpc_global_thread_num(NULL
);
89 int nt
= omp_get_max_threads();
94 #pragma omp parallel //num_threads(N)
98 #pragma omp task depend(inout:nt)
102 int gtid
= __kmpc_global_thread_num(NULL
);
103 omp_event_handle_t evt
;
105 #pragma omp task detach(evt)
108 task
= (ptask
)__kmpc_omp_task_alloc(NULL
,gtid
,PTASK_FLAG_DETACHABLE
,
109 sizeof(struct task
),sizeof(struct shar
),&task_entry
);
111 evt
= (omp_event_handle_t
)__kmpc_task_allow_completion_event(NULL
,gtid
,task
);
115 sdep
.addr
= (size_t)&nt
;
119 __kmpc_omp_task_with_deps(NULL
,gtid
,task
,1,&sdep
,0,0);
120 //__kmpc_omp_task(NULL, gtid, task);
122 omp_fulfill_event(evt
);
126 // printf("after tw %d\n", omp_get_thread_num());