1 /* Validate static scheduling iteration dispatch. We only test with
2 even thread distributions here; there are multiple valid solutions
3 for uneven thread distributions. */
5 /* { dg-require-effective-target sync_int_long } */
10 #include "libgomp_g.h"
14 static int data
[N
][2];
15 static int INCR
, NTHR
, CHUNK
;
17 static void clean_data (void)
19 memset (data
, -1, sizeof (data
));
22 static void test_data (void)
24 int n
, i
, c
, thr
, iter
, chunk
;
28 chunk
= N
/ INCR
/ NTHR
;
30 thr
= iter
= c
= i
= 0;
32 for (n
= 0; n
< N
; ++n
)
36 assert (data
[n
][0] == thr
);
37 assert (data
[n
][1] == iter
);
41 assert (data
[n
][0] == -1);
42 assert (data
[n
][1] == -1);
61 static void set_data (long i
, int thr
, int iter
)
64 assert (i
>= 0 && i
< N
);
65 old
= __sync_lock_test_and_set (&data
[i
][0], thr
);
67 old
= __sync_lock_test_and_set (&data
[i
][1], iter
);
71 static void f_static_1 (void *dummy
)
73 int iam
= omp_get_thread_num ();
74 long s0
, e0
, i
, count
= 0;
75 if (GOMP_loop_static_start (0, N
, INCR
, CHUNK
, &s0
, &e0
))
78 for (i
= s0
; i
< e0
; i
+= INCR
)
79 set_data (i
, iam
, count
);
82 while (GOMP_loop_static_next (&s0
, &e0
));
86 static void test (void)
89 GOMP_parallel_start (f_static_1
, NULL
, NTHR
);
101 INCR
= 1, CHUNK
= 0; /* chunk = 360 / 5 = 72 */
104 INCR
= 4, CHUNK
= 0; /* chunk = 360 / 4 / 5 = 18 */
107 INCR
= 1, CHUNK
= 4; /* 1 * 4 * 5 = 20 -> 360 / 20 = 18 iterations. */
110 INCR
= 3, CHUNK
= 4; /* 3 * 4 * 5 = 60 -> 360 / 60 = 6 iterations. */