brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 0353d62 Raw
87 lines · c
1// RUN: %libomp-compile-and-run2 3// test checks IN dep kind in depend clause on taskwait nowait4// uses codegen emulation5// Note: no outlined task routine used6#include <stdio.h>7#include <omp.h>8// ---------------------------------------------------------------------------9// internal data to emulate compiler codegen10#define TIED 111typedef struct DEP {12  size_t addr;13  size_t len;14  unsigned char flags;15} _dep;16typedef struct ID {17  int reserved_1;18  int flags;19  int reserved_2;20  int reserved_3;21  char *psource;22} _id;23typedef struct task {24  void** shareds;25  void* entry;26  int part_id;27  void* destr_thunk;28  int priority;29  long long device_id;30  int f_priv;31} task_t;32typedef int(*entry_t)(int, task_t*);33 34#ifdef __cplusplus35extern "C" {36#endif37extern int __kmpc_global_thread_num(_id*);38task_t *__kmpc_omp_task_alloc(_id *loc, int gtid, int flags,39                              size_t sz, size_t shar, entry_t rtn);40int __kmpc_omp_task_with_deps(_id *loc, int gtid, task_t *task, int ndeps,41                              _dep *dep_lst, int nd_noalias, _dep *noalias_l);42#ifdef __cplusplus43} // extern "C"44#endif45 46int main()47{48  int i1,i2,i3;49  omp_set_num_threads(2);50  printf("addresses: %p %p %p\n", &i1, &i2, &i3);51  #pragma omp parallel52  {53    int t = omp_get_thread_num();54    printf("thread %d enters parallel\n", t);55    #pragma omp single56    {57      #pragma omp task depend(in: i3)58      {59        int th = omp_get_thread_num();60        printf("task 0 created by th %d, executed by th %d\n", t, th);61      }62      #pragma omp task depend(in: i2)63      {64        int th = omp_get_thread_num();65        printf("task 1 created by th %d, executed by th %d\n", t, th);66      }67//      #pragma omp taskwait depend(in: i1, i2) nowait68      {69        _dep sdep[2];70        static _id loc = {0, 2, 0, 0, ";test.c;func;67;0;;"};71        int gtid = __kmpc_global_thread_num(&loc);72// instead of creating an empty task function we can now send NULL to runtime73        task_t *ptr = __kmpc_omp_task_alloc(&loc, gtid, TIED,74                                            sizeof(task_t), 0, NULL);75        sdep[0].addr = (size_t)&i2;76        sdep[0].flags = 1; // 1-in, 2-out, 3-inout, 4-mtx, 8-inoutset77        sdep[1].addr = (size_t)&i1;78        sdep[1].flags = 1; // in79        __kmpc_omp_task_with_deps(&loc, gtid, ptr, 2, sdep, 0, NULL);80      }81      printf("single done\n");82    }83  }84  printf("passed\n");85  return 0;86}87