OSDN Git Service

15325b48bb382c4a10dfb12cfaebff15993203a7
[pf3gnuchains/gcc-fork.git] / libgomp / testsuite / libgomp.c / ordered-2.c
1 /* Trivial test of ordered.  */
2
3 #include <omp.h>
4 #include <string.h>
5 #include <assert.h>
6 #include "libgomp_g.h"
7
8
9 #define N 100
10 static int next;
11 static int CHUNK, NTHR;
12
13 static void clean_data (void)
14 {
15   next = 0;
16 }
17
18 static void set_data (long i)
19 {
20   int n = __sync_fetch_and_add (&next, 1);
21   assert (n == i);
22 }
23
24
25 #define TMPL_1(sched)                                                   \
26 static void f_##sched##_1 (void *dummy)                                 \
27 {                                                                       \
28   long s0, e0, i;                                                       \
29   if (GOMP_loop_ordered_##sched##_start (0, N, 1, CHUNK, &s0, &e0))     \
30     do                                                                  \
31       {                                                                 \
32         for (i = s0; i < e0; ++i)                                       \
33           {                                                             \
34             GOMP_ordered_start ();                                      \
35             set_data (i);                                               \
36             GOMP_ordered_end ();                                        \
37           }                                                             \
38       }                                                                 \
39     while (GOMP_loop_ordered_##sched##_next (&s0, &e0));                \
40   GOMP_loop_end ();                                                     \
41 }                                                                       \
42 static void t_##sched##_1 (void)                                        \
43 {                                                                       \
44   clean_data ();                                                        \
45   GOMP_parallel_start (f_##sched##_1, NULL, NTHR);                      \
46   f_##sched##_1 (NULL);                                                 \
47   GOMP_parallel_end ();                                                 \
48 }
49
50 TMPL_1(static)
51 TMPL_1(dynamic)
52 TMPL_1(guided)
53
54 static void test (void)
55 {
56   t_static_1 ();
57   t_dynamic_1 ();
58   t_guided_1 ();
59 }
60
61 int main()
62 {
63   omp_set_dynamic (0);
64
65   NTHR = 4;
66
67   CHUNK = 1;
68   test ();
69
70   CHUNK = 5;
71   test ();
72
73   CHUNK = 7;
74   test ();
75
76   CHUNK = 0;
77   t_static_1 ();
78
79   return 0;
80 }