Mercurial > hg > CbC > CbC_gcc
comparison libgomp/testsuite/libgomp.c/ordered-1.c @ 0:a06113de4d67
first commit
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2009 14:47:48 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a06113de4d67 |
---|---|
1 /* Test that all loop iterations are touched. This doesn't verify | |
2 scheduling order, merely coverage. */ | |
3 /* Note that we never call GOMP_ordered_start in here. AFAICS, this is | |
4 valid; the only requirement is "not more than once per iteration". */ | |
5 | |
6 /* { dg-require-effective-target sync_int_long } */ | |
7 | |
8 #include <omp.h> | |
9 #include <string.h> | |
10 #include <assert.h> | |
11 #include "libgomp_g.h" | |
12 | |
13 | |
14 #define N 1000 | |
15 static int S, E, INCR, CHUNK, NTHR; | |
16 static int data[N]; | |
17 | |
18 static void clean_data (void) | |
19 { | |
20 memset (data, -1, sizeof (data)); | |
21 } | |
22 | |
23 static void test_data (void) | |
24 { | |
25 int i, j; | |
26 | |
27 for (i = 0; i < S; ++i) | |
28 assert (data[i] == -1); | |
29 | |
30 for (j = 0; i < E; ++i, j = (j + 1) % INCR) | |
31 if (j == 0) | |
32 assert (data[i] != -1); | |
33 else | |
34 assert (data[i] == -1); | |
35 | |
36 for (; i < N; ++i) | |
37 assert (data[i] == -1); | |
38 } | |
39 | |
40 static void set_data (long i, int val) | |
41 { | |
42 int old; | |
43 assert (i >= 0 && i < N); | |
44 old = __sync_lock_test_and_set (data+i, val); | |
45 assert (old == -1); | |
46 } | |
47 | |
48 | |
49 #define TMPL_1(sched) \ | |
50 static void f_##sched##_1 (void *dummy) \ | |
51 { \ | |
52 int iam = omp_get_thread_num (); \ | |
53 long s0, e0, i; \ | |
54 if (GOMP_loop_ordered_##sched##_start (S, E, INCR, CHUNK, &s0, &e0)) \ | |
55 do \ | |
56 { \ | |
57 for (i = s0; i < e0; i += INCR) \ | |
58 set_data (i, iam); \ | |
59 } \ | |
60 while (GOMP_loop_ordered_##sched##_next (&s0, &e0)); \ | |
61 GOMP_loop_end (); \ | |
62 } \ | |
63 static void t_##sched##_1 (void) \ | |
64 { \ | |
65 clean_data (); \ | |
66 GOMP_parallel_start (f_##sched##_1, NULL, NTHR); \ | |
67 f_##sched##_1 (NULL); \ | |
68 GOMP_parallel_end (); \ | |
69 test_data (); \ | |
70 } | |
71 | |
72 TMPL_1(static) | |
73 TMPL_1(dynamic) | |
74 TMPL_1(guided) | |
75 | |
76 static void test (void) | |
77 { | |
78 t_static_1 (); | |
79 t_dynamic_1 (); | |
80 t_guided_1 (); | |
81 } | |
82 | |
83 int main() | |
84 { | |
85 omp_set_dynamic (0); | |
86 | |
87 NTHR = 4; | |
88 | |
89 S = 0, E = N, INCR = 1, CHUNK = 4; | |
90 test (); | |
91 | |
92 S = 0, E = N, INCR = 2, CHUNK = 4; | |
93 test (); | |
94 | |
95 S = 1, E = N-1, INCR = 1, CHUNK = 5; | |
96 test (); | |
97 | |
98 S = 1, E = N-1, INCR = 2, CHUNK = 5; | |
99 test (); | |
100 | |
101 S = 2, E = 4, INCR = 1, CHUNK = 1; | |
102 test (); | |
103 | |
104 S = 0, E = N, INCR = 1, CHUNK = 0; | |
105 t_static_1 (); | |
106 | |
107 S = 1, E = N-1, INCR = 1, CHUNK = 0; | |
108 t_static_1 (); | |
109 | |
110 NTHR = 10; | |
111 S = 1, E = 9, INCR = 1, CHUNK = 0; | |
112 t_static_1 (); | |
113 | |
114 return 0; | |
115 } |