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