brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · bc00934 Raw
58 lines · c
1// RUN: %libomp-compile-and-run2// UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7, gcc-83// UNSUPPORTED: icc, clang4 5#include <stdio.h>6#include <stdlib.h>7#include <omp.h>8 9#define NUM_TEAMS 210#define NUM_THREADS_PER_TEAM 311 12int main(int argc, char** argv) {13  #pragma omp teams num_teams(NUM_TEAMS)14  {15    int i;16    int members[NUM_THREADS_PER_TEAM];17    // Only an upper bound is guaranteed for number of teams18    int nteams = omp_get_num_teams();19    if (nteams > NUM_TEAMS) {20      fprintf(stderr, "error: too many teams: %d\n", nteams);21      exit(1);22    }23    for (i = 0; i < NUM_THREADS_PER_TEAM; ++i)24      members[i] = -1;25    #pragma omp parallel num_threads(NUM_THREADS_PER_TEAM) private(i)26    {27      int tid = omp_get_thread_num();28      int team_id = omp_get_team_num();29      int nthreads = omp_get_num_threads();30      if (nthreads != NUM_THREADS_PER_TEAM) {31        fprintf(stderr, "error: detected number of threads (%d) is not %d\n",32                nthreads, NUM_THREADS_PER_TEAM);33        exit(1);34      }35      if (tid < 0 || tid >= nthreads) {36        fprintf(stderr, "error: thread id is out of range: %d\n", tid);37        exit(1);38      }39      if (team_id < 0 || team_id > omp_get_num_teams()) {40        fprintf(stderr, "error: team id is out of range: %d\n", team_id);41        exit(1);42      }43      members[omp_get_thread_num()] = 1;44      #pragma omp barrier45      #pragma omp single46      {47        for (i = 0; i < NUM_THREADS_PER_TEAM; ++i) {48          if (members[i] != 1) {49            fprintf(stderr, "error: worker %d not flagged\n", i);50            exit(1);51          }52        }53      }54    }55  }56  return 0;57}58