brintos

brintos / llvm-project-archived public Read only

0
0
Text · 998 B · 0691353 Raw
41 lines · c
1// RUN: %libomp-compile2// RUN: env OMP_SCHEDULE=nonmonotonic:dynamic,10 %libomp-run3 4// The test checks iterations distribution for OMP 5.0 nonmonotonic OMP_SCHEDULE5// case #threads > #chunks (fallback to monotonic dynamic)6 7#include <stdio.h>8#include <omp.h>9 10#define ITERS 10011#define CHUNK 1012int err = 0;13 14int main(int argc, char **argv) {15  int i, ch, it[ITERS];16  omp_set_num_threads(16); // #threads is bigger than #chunks17#pragma omp parallel for schedule(runtime)18  for (i = 0; i < ITERS; ++i) {19    it[i] = omp_get_thread_num();20  }21  // check that each chunk executed by single thread22  for (ch = 0; ch < ITERS/CHUNK; ++ch) {23    int iter = ch * CHUNK;24    int nt = it[iter]; // thread number25    for (i = 1; i < CHUNK; ++i) {26#if _DEBUG27      printf("iter %d: (%d %d)\n", iter + i, nt, it[iter + i]);28#endif29      if (nt != it[iter + i]) {30        err++;31      }32    }33  }34  if (err > 0) {35    printf("Failed, err = %d\n", err);36    return 1;37  }38  printf("Passed\n");39  return 0;40}41