00001
00002
00003
00004
00005
00006
00007
00008 #include <omp.h>
00009 #include <string.h>
00010 #include <assert.h>
00011 #include "libgomp_g.h"
00012
00013
00014 #define N 1000
00015 static int S, E, INCR, CHUNK, NTHR;
00016 static int data[N];
00017
00018 static void clean_data (void)
00019 {
00020 memset (data, -1, sizeof (data));
00021 }
00022
00023 static void test_data (void)
00024 {
00025 int i, j;
00026
00027 for (i = 0; i < S; ++i)
00028 assert (data[i] == -1);
00029
00030 for (j = 0; i < E; ++i, j = (j + 1) % INCR)
00031 if (j == 0)
00032 assert (data[i] != -1);
00033 else
00034 assert (data[i] == -1);
00035
00036 for (; i < N; ++i)
00037 assert (data[i] == -1);
00038 }
00039
00040 static void set_data (long i, int val)
00041 {
00042 int old;
00043 assert (i >= 0 && i < N);
00044 old = __sync_lock_test_and_set (data+i, val);
00045 assert (old == -1);
00046 }
00047
00048
00049 #define TMPL_1(sched) \
00050 static void f_##sched##_1 (void *dummy) \
00051 { \
00052 int iam = omp_get_thread_num (); \
00053 long s0, e0, i; \
00054 if (GOMP_loop_ordered_##sched##_start (S, E, INCR, CHUNK, &s0, &e0)) \
00055 do \
00056 { \
00057 for (i = s0; i < e0; i += INCR) \
00058 set_data (i, iam); \
00059 } \
00060 while (GOMP_loop_ordered_##sched##_next (&s0, &e0)); \
00061 GOMP_loop_end (); \
00062 } \
00063 static void t_##sched##_1 (void) \
00064 { \
00065 clean_data (); \
00066 GOMP_parallel_start (f_##sched##_1, NULL, NTHR); \
00067 f_##sched##_1 (NULL); \
00068 GOMP_parallel_end (); \
00069 test_data (); \
00070 }
00071
00072 TMPL_1(static)
00073 TMPL_1(dynamic)
00074 TMPL_1(guided)
00075
00076 static void test (void)
00077 {
00078 t_static_1 ();
00079 t_dynamic_1 ();
00080 t_guided_1 ();
00081 }
00082
00083 int main()
00084 {
00085 omp_set_dynamic (0);
00086
00087 NTHR = 4;
00088
00089 S = 0, E = N, INCR = 1, CHUNK = 4;
00090 test ();
00091
00092 S = 0, E = N, INCR = 2, CHUNK = 4;
00093 test ();
00094
00095 S = 1, E = N-1, INCR = 1, CHUNK = 5;
00096 test ();
00097
00098 S = 1, E = N-1, INCR = 2, CHUNK = 5;
00099 test ();
00100
00101 S = 2, E = 4, INCR = 1, CHUNK = 1;
00102 test ();
00103
00104 S = 0, E = N, INCR = 1, CHUNK = 0;
00105 t_static_1 ();
00106
00107 S = 1, E = N-1, INCR = 1, CHUNK = 0;
00108 t_static_1 ();
00109
00110 NTHR = 10;
00111 S = 1, E = 9, INCR = 1, CHUNK = 0;
00112 t_static_1 ();
00113
00114 return 0;
00115 }