brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1005 B · 95a406d Raw
51 lines · c
1// RUN: %libomp-compile-and-run2#include <stdio.h>3#include "omp_testsuite.h"4#include "omp_my_sleep.h"5 6int test_omp_flush()7{8  int result1;9  int result2;10  int dummy;11 12  result1 = 0;13  result2 = 0;14 15  #pragma omp parallel16  {17    int rank;18    rank = omp_get_thread_num ();19    #pragma omp barrier20    if (rank == 1) {21      result2 = 3;22      #pragma omp flush (result2)23      dummy = result2;24    }25    if (rank == 0) {26      my_sleep(SLEEPTIME);27      #pragma omp flush (result2)28      result1 = result2;29    }30  }  /* end of parallel */31  return ((result1 == result2) && (result2 == dummy) && (result2 == 3));32}33 34int main()35{36  int i;37  int num_failed=0;38 39  // the test requires more than 1 thread to pass40  omp_set_dynamic(0); // disable dynamic adjustment of threads41  if (omp_get_max_threads() == 1)42    omp_set_num_threads(2); // set 2 threads if no HW resources available43 44  for (i = 0; i < REPETITIONS; i++) {45    if(!test_omp_flush()) {46      num_failed++;47    }48  }49  return num_failed;50}51