1614c7ef8SJonathan Peyton // RUN: %libomp-compile-and-run 2614c7ef8SJonathan Peyton #include <stdio.h> 3614c7ef8SJonathan Peyton #include "omp_testsuite.h" 4614c7ef8SJonathan Peyton #include "omp_my_sleep.h" 5614c7ef8SJonathan Peyton test_omp_flush()6614c7ef8SJonathan Peytonint test_omp_flush() 7614c7ef8SJonathan Peyton { 8614c7ef8SJonathan Peyton int result1; 9614c7ef8SJonathan Peyton int result2; 10614c7ef8SJonathan Peyton int dummy; 11614c7ef8SJonathan Peyton 12614c7ef8SJonathan Peyton result1 = 0; 13614c7ef8SJonathan Peyton result2 = 0; 14614c7ef8SJonathan Peyton 15614c7ef8SJonathan Peyton #pragma omp parallel 16614c7ef8SJonathan Peyton { 17614c7ef8SJonathan Peyton int rank; 18614c7ef8SJonathan Peyton rank = omp_get_thread_num (); 19614c7ef8SJonathan Peyton #pragma omp barrier 20614c7ef8SJonathan Peyton if (rank == 1) { 21614c7ef8SJonathan Peyton result2 = 3; 22614c7ef8SJonathan Peyton #pragma omp flush (result2) 23614c7ef8SJonathan Peyton dummy = result2; 24614c7ef8SJonathan Peyton } 25614c7ef8SJonathan Peyton if (rank == 0) { 26614c7ef8SJonathan Peyton my_sleep(SLEEPTIME); 27614c7ef8SJonathan Peyton #pragma omp flush (result2) 28614c7ef8SJonathan Peyton result1 = result2; 29614c7ef8SJonathan Peyton } 30614c7ef8SJonathan Peyton } /* end of parallel */ 31614c7ef8SJonathan Peyton return ((result1 == result2) && (result2 == dummy) && (result2 == 3)); 32614c7ef8SJonathan Peyton } 33614c7ef8SJonathan Peyton main()34614c7ef8SJonathan Peytonint main() 35614c7ef8SJonathan Peyton { 36614c7ef8SJonathan Peyton int i; 37614c7ef8SJonathan Peyton int num_failed=0; 38614c7ef8SJonathan Peyton 39*74f98554SAndrey Churbanov // the test requires more than 1 thread to pass 40*74f98554SAndrey Churbanov omp_set_dynamic(0); // disable dynamic adjustment of threads 41*74f98554SAndrey Churbanov if (omp_get_max_threads() == 1) 42*74f98554SAndrey Churbanov omp_set_num_threads(2); // set 2 threads if no HW resources available 43*74f98554SAndrey Churbanov 44614c7ef8SJonathan Peyton for (i = 0; i < REPETITIONS; i++) { 45614c7ef8SJonathan Peyton if(!test_omp_flush()) { 46614c7ef8SJonathan Peyton num_failed++; 47614c7ef8SJonathan Peyton } 48614c7ef8SJonathan Peyton } 49614c7ef8SJonathan Peyton return num_failed; 50614c7ef8SJonathan Peyton } 51