brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 6d7cd11 Raw
69 lines · c
1// RUN: %libomp-compile-and-run2//3// The test checks the teams construct with reduction executed on the host.4//5 6#include <stdio.h>7#include <omp.h>8 9#include <stdint.h>10 11#ifndef N_TEAMS12#define N_TEAMS 413#endif14#ifndef N_THR15#define N_THR 316#endif17 18// Internal library stuff to emulate compiler's code generation:19#ifdef __cplusplus20extern "C" {21#endif22 23typedef struct {24  int32_t reserved_1;25  int32_t flags;26  int32_t reserved_2;27  int32_t reserved_3;28  char const *psource;29} ident_t;30 31static ident_t dummy_loc = {0, 2, 0, 0, ";dummyFile;dummyFunc;0;0;;"};32 33typedef union {34  // The global will be used as pointer, so we need to make sure that the35  // compiler correctly aligns the global...36  void *ptr;37  int32_t data[8];38} kmp_critical_name;39kmp_critical_name crit;40 41int32_t __kmpc_global_thread_num(ident_t *);42void __kmpc_push_num_teams(ident_t *, int32_t global_tid, int32_t num_teams,43                           int32_t num_threads);44void __kmpc_fork_teams(ident_t *, int32_t argc, void *microtask, ...);45int32_t __kmpc_reduce(ident_t *, int32_t global_tid, int32_t num_vars,46                      size_t reduce_size, void *reduce_data, void *reduce_func,47                      kmp_critical_name *lck);48void __kmpc_end_reduce(ident_t *, int32_t global_tid, kmp_critical_name *lck);49 50#ifdef __cplusplus51}52#endif53 54// Outlined entry point:55void outlined(int32_t *gtid, int32_t *tid) {56  int32_t ret = __kmpc_reduce(&dummy_loc, *gtid, 0, 0, NULL, NULL, &crit);57  __kmpc_end_reduce(&dummy_loc, *gtid, &crit);58}59 60int main() {61  int32_t th = __kmpc_global_thread_num(NULL); // registers initial thread62  __kmpc_push_num_teams(&dummy_loc, th, N_TEAMS, N_THR);63  __kmpc_fork_teams(&dummy_loc, 0, &outlined);64 65  // Test did not hang -> passed!66  printf("passed\n");67  return 0;68}69