[Instrumentation] Fix a warning
[llvm-project.git] / openmp / runtime / test / tasking / omp_taskwait.c
blob584eceb58075c0880138b70f53654f2d9ac740da
1 // RUN: %libomp-compile-and-run
3 // This test is known to be fragile on NetBSD kernel at the moment,
4 // https://bugs.llvm.org/show_bug.cgi?id=42020.
5 // UNSUPPORTED: netbsd
6 #include <stdio.h>
7 #include <math.h>
8 #include "omp_testsuite.h"
9 #include "omp_my_sleep.h"
11 int test_omp_taskwait()
13 int result1 = 0; /* Stores number of not finished tasks after the taskwait */
14 int result2 = 0; /* Stores number of wrong array elements at the end */
15 int array[NUM_TASKS];
16 int i;
18 /* fill array */
19 for (i = 0; i < NUM_TASKS; i++)
20 array[i] = 0;
22 #pragma omp parallel
24 #pragma omp single
26 for (i = 0; i < NUM_TASKS; i++) {
27 /* First we have to store the value of the loop index in a new variable
28 * which will be private for each task because otherwise it will be overwritten
29 * if the execution of the task takes longer than the time which is needed to
30 * enter the next step of the loop!
32 int myi;
33 myi = i;
34 #pragma omp task
36 my_sleep (SLEEPTIME);
37 array[myi] = 1;
38 } /* end of omp task */
39 } /* end of for */
40 #pragma omp taskwait
41 /* check if all tasks were finished */
42 for (i = 0; i < NUM_TASKS; i++)
43 if (array[i] != 1)
44 result1++;
46 /* generate some more tasks which now shall overwrite
47 * the values in the tids array */
48 for (i = 0; i < NUM_TASKS; i++) {
49 int myi;
50 myi = i;
51 #pragma omp task
53 array[myi] = 2;
54 } /* end of omp task */
55 } /* end of for */
56 } /* end of single */
57 } /*end of parallel */
59 /* final check, if all array elements contain the right values: */
60 for (i = 0; i < NUM_TASKS; i++) {
61 if (array[i] != 2)
62 result2++;
64 return ((result1 == 0) && (result2 == 0));
67 int main()
69 int i;
70 int num_failed=0;
72 for(i = 0; i < REPETITIONS; i++) {
73 if(!test_omp_taskwait()) {
74 num_failed++;
77 return num_failed;