1 // RUN: %libomp-compile-and-run 2 // REQUIRES: openmp-4.5 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 <pthread.h> 9 #include "omp_my_sleep.h" 10 11 /* 12 With task dependencies one can generate proxy tasks from an explicit task 13 being executed by a serial task team. The OpenMP runtime library didn't 14 expect that and tries to free the explicit task that is the parent of the 15 proxy task still working in background. It therefore has incomplete children 16 which triggers a debugging assertion. 17 */ 18 19 // Compiler-generated code (emulation) 20 typedef long kmp_intptr_t; 21 typedef int kmp_int32; 22 23 typedef char bool; 24 25 typedef struct ident { 26 kmp_int32 reserved_1; /**< might be used in Fortran; see above */ 27 kmp_int32 flags; /**< also f.flags; KMP_IDENT_xxx flags; KMP_IDENT_KMPC identifies this union member */ 28 kmp_int32 reserved_2; /**< not really used in Fortran any more; see above */ 29 #if USE_ITT_BUILD 30 /* but currently used for storing region-specific ITT */ 31 /* contextual information. */ 32 #endif /* USE_ITT_BUILD */ 33 kmp_int32 reserved_3; /**< source[4] in Fortran, do not use for C++ */ 34 char const *psource; /**< String describing the source location. 35 The string is composed of semi-colon separated fields which describe the source file, 36 the function and a pair of line numbers that delimit the construct. 37 */ 38 } ident_t; 39 40 typedef struct kmp_depend_info { 41 kmp_intptr_t base_addr; 42 size_t len; 43 struct { 44 bool in:1; 45 bool out:1; 46 } flags; 47 } kmp_depend_info_t; 48 49 struct kmp_task; 50 typedef kmp_int32 (* kmp_routine_entry_t)( kmp_int32, struct kmp_task * ); 51 52 typedef struct kmp_task { /* GEH: Shouldn't this be aligned somehow? */ 53 void * shareds; /**< pointer to block of pointers to shared vars */ 54 kmp_routine_entry_t routine; /**< pointer to routine to call for executing task */ 55 kmp_int32 part_id; /**< part id for the task */ 56 } kmp_task_t; 57 58 #ifdef __cplusplus 59 extern "C" { 60 #endif 61 kmp_int32 __kmpc_global_thread_num ( ident_t * ); 62 kmp_task_t* 63 __kmpc_omp_task_alloc( ident_t *loc_ref, kmp_int32 gtid, kmp_int32 flags, 64 size_t sizeof_kmp_task_t, size_t sizeof_shareds, 65 kmp_routine_entry_t task_entry ); 66 void __kmpc_proxy_task_completed_ooo ( kmp_task_t *ptask ); 67 kmp_int32 __kmpc_omp_task_with_deps ( ident_t *loc_ref, kmp_int32 gtid, kmp_task_t * new_task, 68 kmp_int32 ndeps, kmp_depend_info_t *dep_list, 69 kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list ); 70 kmp_int32 71 __kmpc_omp_task( ident_t *loc_ref, kmp_int32 gtid, kmp_task_t * new_task ); 72 #ifdef __cplusplus 73 } 74 #endif 75 76 void *target(void *task) 77 { 78 my_sleep( 0.1 ); 79 __kmpc_proxy_task_completed_ooo((kmp_task_t*) task); 80 return NULL; 81 } 82 83 pthread_t target_thread; 84 85 // User's code 86 int task_entry(kmp_int32 gtid, kmp_task_t *task) 87 { 88 pthread_create(&target_thread, NULL, &target, task); 89 return 0; 90 } 91 92 int main() 93 { 94 int dep; 95 96 #pragma omp taskgroup 97 { 98 /* 99 * Corresponds to: 100 #pragma omp target nowait depend(out: dep) 101 { 102 my_sleep( 0.1 ); 103 } 104 */ 105 kmp_depend_info_t dep_info; 106 dep_info.base_addr = (long) &dep; 107 dep_info.len = sizeof(int); 108 // out = inout per spec and runtime expects this 109 dep_info.flags.in = 1; 110 dep_info.flags.out = 1; 111 112 kmp_int32 gtid = __kmpc_global_thread_num(NULL); 113 kmp_task_t *proxy_task = __kmpc_omp_task_alloc(NULL,gtid,17,sizeof(kmp_task_t),0,&task_entry); 114 __kmpc_omp_task_with_deps(NULL,gtid,proxy_task,1,&dep_info,0,NULL); 115 116 #pragma omp task depend(in: dep) 117 { 118 /* 119 * Corresponds to: 120 #pragma omp target nowait 121 { 122 my_sleep( 0.1 ); 123 } 124 */ 125 kmp_task_t *nested_proxy_task = __kmpc_omp_task_alloc(NULL,gtid,17,sizeof(kmp_task_t),0,&task_entry); 126 __kmpc_omp_task(NULL,gtid,nested_proxy_task); 127 } 128 } 129 130 // only check that it didn't crash 131 return 0; 132 } 133