brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 0ef8d9a Raw
65 lines · c
1// RUN: %libomp-compile-and-run2//3// The test checks the teams construct pseudocode executed on host4//5 6#include <stdio.h>7#include <omp.h>8 9#ifndef N_TEAMS10#define N_TEAMS 411#endif12#ifndef N_THR13#define N_THR 314#endif15 16static int err = 0;17 18// Internal library staff to emulate compiler's code generation:19#ifdef __cplusplus20extern "C" {21#endif22 23typedef struct {24  int reserved_1;25  int flags;26  int reserved_2;27  int reserved_3;28  char *psource;29} ident_t;30 31static ident_t dummy_loc = {0, 2, 0, 0, ";dummyFile;dummyFunc;0;0;;"};32 33int __kmpc_global_thread_num(void*);34void __kmpc_push_num_teams(ident_t const*, int, int, int);35void __kmpc_fork_teams(ident_t const*, int argc, void *microtask, ...);36 37#ifdef __cplusplus38}39#endif40 41// Outlined entry point:42void foo(int *gtid, int *tid, int *nt)43{ // start "serial" execution by master threads of each team44  if ( nt ) {45    printf(" team %d, param %d\n", omp_get_team_num(), *nt);46  } else {47    printf("ERROR: teams before parallel: gtid, tid: %d %d, bad pointer: %p\n", *gtid, *tid, nt);48    err++;49    return;50  }51}52 53int main()54{55  int nt = 4;56  int th = __kmpc_global_thread_num(NULL); // registers initial thread57  __kmpc_push_num_teams(&dummy_loc, th, N_TEAMS, N_THR);58  __kmpc_fork_teams(&dummy_loc, 1, &foo, &nt); // pass 1 shared parameter "nt"59  if (err)60    printf("failed with %d errors\n",err);61  else62    printf("passed\n");63  return err;64}65