1 // RUN: %libomp-compile && env OMP_NUM_THREADS='3' %libomp-run
2 // RUN: %libomp-compile && env OMP_NUM_THREADS='1' %libomp-run
6 #include "omp_my_sleep.h"
9 #define PTASK_FLAG_DETACHABLE 0x40
11 // OpenMP RTL interfaces
12 typedef unsigned long long kmp_uint64
;
13 typedef long long kmp_int64
;
23 // Compiler-generated code (emulation)
24 typedef struct ident
{
25 void* dummy
; // not used in the library
28 typedef enum kmp_event_type_t
{
29 KMP_EVENT_UNINITIALIZED
= 0,
30 KMP_EVENT_ALLOW_COMPLETION
= 1
34 kmp_event_type_t type
;
40 typedef struct shar
{ // shareds used in the task
45 int(*routine
)(int,struct task
*);
47 // void *destructor_thunk; // optional, needs flag setting if provided
48 // int priority; // optional, needs flag setting if provided
49 // ------------------------------
50 // privates used in the task:
51 omp_event_handle_t evt
;
54 typedef int(*task_entry_t
)(int, ptask
);
58 extern int __kmpc_global_thread_num(void *id_ref
);
59 extern ptask
__kmpc_omp_task_alloc(id
*loc
, int gtid
, int flags
,
60 size_t sz
, size_t shar
, task_entry_t rtn
);
61 extern int __kmpc_omp_task(id
*loc
, int gtid
, ptask task
);
62 extern omp_event_handle_t
__kmpc_task_allow_completion_event(
63 ident_t
*loc_ref
, int gtid
, ptask task
);
70 // User's code, outlined into task entry
71 int task_entry(int gtid
, ptask task
) {
77 int i
, j
, gtid
= __kmpc_global_thread_num(NULL
);
78 int nt
= omp_get_max_threads();
83 #pragma omp parallel //num_threads(N)
87 int gtid
= __kmpc_global_thread_num(NULL
);
88 omp_event_handle_t evt
;
90 #pragma omp task detach(evt)
93 task
= (ptask
)__kmpc_omp_task_alloc(NULL
,gtid
,PTASK_FLAG_DETACHABLE
,sizeof(struct task
),sizeof(struct shar
),&task_entry
);
95 evt
= (omp_event_handle_t
)__kmpc_task_allow_completion_event(NULL
,gtid
,task
);
98 __kmpc_omp_task(NULL
, gtid
, task
);
100 omp_fulfill_event(evt
);