00001
00002
00003 #include <omp.h>
00004
00005 extern void abort (void);
00006
00007 #define LLONG_MAX __LONG_LONG_MAX__
00008 #define ULLONG_MAX (LLONG_MAX * 2ULL + 1)
00009 #define INT_MAX __INT_MAX__
00010
00011 int arr[6 * 5];
00012
00013 void
00014 set (int loopidx, int idx)
00015 {
00016 #pragma omp atomic
00017 arr[loopidx * 5 + idx]++;
00018 }
00019
00020 #define check(var, val, loopidx, idx) \
00021 if (var == (val)) set (loopidx, idx); else
00022 #define test(loopidx, count) \
00023 for (idx = 0; idx < 5; idx++) \
00024 if (arr[loopidx * 5 + idx] != idx < count) \
00025 abort (); \
00026 else \
00027 arr[loopidx * 5 + idx] = 0
00028
00029 int
00030 test1 (void)
00031 {
00032 int e = 0, idx;
00033
00034 #pragma omp parallel reduction(+:e)
00035 {
00036 long long i;
00037 unsigned long long j;
00038 #pragma omp for schedule(dynamic,1) nowait
00039 for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000)
00040 {
00041 check (i, LLONG_MAX - 30001, 0, 0)
00042 check (i, LLONG_MAX - 20001, 0, 1)
00043 check (i, LLONG_MAX - 10001, 0, 2)
00044 e = 1;
00045 }
00046 #pragma omp for schedule(dynamic,1) nowait
00047 for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000)
00048 {
00049 check (i, -LLONG_MAX + 30000, 1, 0)
00050 check (i, -LLONG_MAX + 20000, 1, 1)
00051 check (i, -LLONG_MAX + 10000, 1, 2)
00052 e = 1;
00053 }
00054 #pragma omp for schedule(dynamic,1) nowait
00055 for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL)
00056 {
00057 check (j, 20, 2, 0)
00058 e = 1;
00059 }
00060 #pragma omp for schedule(dynamic,1) nowait
00061 for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL)
00062 {
00063 check (j, ULLONG_MAX - 3, 3, 0)
00064 e = 1;
00065 }
00066 #pragma omp for schedule(dynamic,1) nowait
00067 for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL)
00068 {
00069 check (j, LLONG_MAX - 20000ULL, 4, 0)
00070 check (j, LLONG_MAX - 10000ULL, 4, 1)
00071 check (j, LLONG_MAX, 4, 2)
00072 check (j, LLONG_MAX + 10000ULL, 4, 3)
00073 e = 1;
00074 }
00075 #pragma omp for schedule(dynamic,1) nowait
00076 for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL)
00077 {
00078 check (i, -3LL * INT_MAX - 20000LL, 5, 0)
00079 check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
00080 check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
00081 check (i, -20000LL + 600LL, 5, 3)
00082 check (i, INT_MAX - 20000LL + 800LL, 5, 4)
00083 e = 1;
00084 }
00085 }
00086 if (e)
00087 abort ();
00088 test (0, 3);
00089 test (1, 3);
00090 test (2, 1);
00091 test (3, 1);
00092 test (4, 4);
00093 test (5, 5);
00094 return 0;
00095 }
00096
00097 int
00098 test2 (void)
00099 {
00100 int e = 0, idx;
00101
00102 #pragma omp parallel reduction(+:e)
00103 {
00104 long long i;
00105 unsigned long long j;
00106 #pragma omp for schedule(guided,1) nowait
00107 for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000)
00108 {
00109 check (i, LLONG_MAX - 30001, 0, 0)
00110 check (i, LLONG_MAX - 20001, 0, 1)
00111 check (i, LLONG_MAX - 10001, 0, 2)
00112 e = 1;
00113 }
00114 #pragma omp for schedule(guided,1) nowait
00115 for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000)
00116 {
00117 check (i, -LLONG_MAX + 30000, 1, 0)
00118 check (i, -LLONG_MAX + 20000, 1, 1)
00119 check (i, -LLONG_MAX + 10000, 1, 2)
00120 e = 1;
00121 }
00122 #pragma omp for schedule(guided,1) nowait
00123 for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL)
00124 {
00125 check (j, 20, 2, 0)
00126 e = 1;
00127 }
00128 #pragma omp for schedule(guided,1) nowait
00129 for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL)
00130 {
00131 check (j, ULLONG_MAX - 3, 3, 0)
00132 e = 1;
00133 }
00134 #pragma omp for schedule(guided,1) nowait
00135 for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL)
00136 {
00137 check (j, LLONG_MAX - 20000ULL, 4, 0)
00138 check (j, LLONG_MAX - 10000ULL, 4, 1)
00139 check (j, LLONG_MAX, 4, 2)
00140 check (j, LLONG_MAX + 10000ULL, 4, 3)
00141 e = 1;
00142 }
00143 #pragma omp for schedule(guided,1) nowait
00144 for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL)
00145 {
00146 check (i, -3LL * INT_MAX - 20000LL, 5, 0)
00147 check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
00148 check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
00149 check (i, -20000LL + 600LL, 5, 3)
00150 check (i, INT_MAX - 20000LL + 800LL, 5, 4)
00151 e = 1;
00152 }
00153 }
00154 if (e)
00155 abort ();
00156 test (0, 3);
00157 test (1, 3);
00158 test (2, 1);
00159 test (3, 1);
00160 test (4, 4);
00161 test (5, 5);
00162 return 0;
00163 }
00164
00165 int
00166 test3 (void)
00167 {
00168 int e = 0, idx;
00169
00170 #pragma omp parallel reduction(+:e)
00171 {
00172 long long i;
00173 unsigned long long j;
00174 #pragma omp for schedule(static) nowait
00175 for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000)
00176 {
00177 check (i, LLONG_MAX - 30001, 0, 0)
00178 check (i, LLONG_MAX - 20001, 0, 1)
00179 check (i, LLONG_MAX - 10001, 0, 2)
00180 e = 1;
00181 }
00182 #pragma omp for schedule(static) nowait
00183 for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000)
00184 {
00185 check (i, -LLONG_MAX + 30000, 1, 0)
00186 check (i, -LLONG_MAX + 20000, 1, 1)
00187 check (i, -LLONG_MAX + 10000, 1, 2)
00188 e = 1;
00189 }
00190 #pragma omp for schedule(static) nowait
00191 for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL)
00192 {
00193 check (j, 20, 2, 0)
00194 e = 1;
00195 }
00196 #pragma omp for schedule(static) nowait
00197 for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL)
00198 {
00199 check (j, ULLONG_MAX - 3, 3, 0)
00200 e = 1;
00201 }
00202 #pragma omp for schedule(static) nowait
00203 for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL)
00204 {
00205 check (j, LLONG_MAX - 20000ULL, 4, 0)
00206 check (j, LLONG_MAX - 10000ULL, 4, 1)
00207 check (j, LLONG_MAX, 4, 2)
00208 check (j, LLONG_MAX + 10000ULL, 4, 3)
00209 e = 1;
00210 }
00211 #pragma omp for schedule(static) nowait
00212 for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL)
00213 {
00214 check (i, -3LL * INT_MAX - 20000LL, 5, 0)
00215 check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
00216 check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
00217 check (i, -20000LL + 600LL, 5, 3)
00218 check (i, INT_MAX - 20000LL + 800LL, 5, 4)
00219 e = 1;
00220 }
00221 }
00222 if (e)
00223 abort ();
00224 test (0, 3);
00225 test (1, 3);
00226 test (2, 1);
00227 test (3, 1);
00228 test (4, 4);
00229 test (5, 5);
00230 return 0;
00231 }
00232
00233 int
00234 test4 (void)
00235 {
00236 int e = 0, idx;
00237
00238 #pragma omp parallel reduction(+:e)
00239 {
00240 long long i;
00241 unsigned long long j;
00242 #pragma omp for schedule(static,1) nowait
00243 for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000)
00244 {
00245 check (i, LLONG_MAX - 30001, 0, 0)
00246 check (i, LLONG_MAX - 20001, 0, 1)
00247 check (i, LLONG_MAX - 10001, 0, 2)
00248 e = 1;
00249 }
00250 #pragma omp for schedule(static,1) nowait
00251 for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000)
00252 {
00253 check (i, -LLONG_MAX + 30000, 1, 0)
00254 check (i, -LLONG_MAX + 20000, 1, 1)
00255 check (i, -LLONG_MAX + 10000, 1, 2)
00256 e = 1;
00257 }
00258 #pragma omp for schedule(static,1) nowait
00259 for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL)
00260 {
00261 check (j, 20, 2, 0)
00262 e = 1;
00263 }
00264 #pragma omp for schedule(static,1) nowait
00265 for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL)
00266 {
00267 check (j, ULLONG_MAX - 3, 3, 0)
00268 e = 1;
00269 }
00270 #pragma omp for schedule(static,1) nowait
00271 for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL)
00272 {
00273 check (j, LLONG_MAX - 20000ULL, 4, 0)
00274 check (j, LLONG_MAX - 10000ULL, 4, 1)
00275 check (j, LLONG_MAX, 4, 2)
00276 check (j, LLONG_MAX + 10000ULL, 4, 3)
00277 e = 1;
00278 }
00279 #pragma omp for schedule(static,1) nowait
00280 for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL)
00281 {
00282 check (i, -3LL * INT_MAX - 20000LL, 5, 0)
00283 check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
00284 check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
00285 check (i, -20000LL + 600LL, 5, 3)
00286 check (i, INT_MAX - 20000LL + 800LL, 5, 4)
00287 e = 1;
00288 }
00289 }
00290 if (e)
00291 abort ();
00292 test (0, 3);
00293 test (1, 3);
00294 test (2, 1);
00295 test (3, 1);
00296 test (4, 4);
00297 test (5, 5);
00298 return 0;
00299 }
00300
00301 int
00302 test5 (void)
00303 {
00304 int e = 0, idx;
00305
00306 #pragma omp parallel reduction(+:e)
00307 {
00308 long long i;
00309 unsigned long long j;
00310 #pragma omp for schedule(runtime) nowait
00311 for (i = LLONG_MAX - 30001; i <= LLONG_MAX - 10001; i += 10000)
00312 {
00313 check (i, LLONG_MAX - 30001, 0, 0)
00314 check (i, LLONG_MAX - 20001, 0, 1)
00315 check (i, LLONG_MAX - 10001, 0, 2)
00316 e = 1;
00317 }
00318 #pragma omp for schedule(runtime) nowait
00319 for (i = -LLONG_MAX + 30000; i >= -LLONG_MAX + 10000; i -= 10000)
00320 {
00321 check (i, -LLONG_MAX + 30000, 1, 0)
00322 check (i, -LLONG_MAX + 20000, 1, 1)
00323 check (i, -LLONG_MAX + 10000, 1, 2)
00324 e = 1;
00325 }
00326 #pragma omp for schedule(runtime) nowait
00327 for (j = 20; j <= LLONG_MAX - 70; j += LLONG_MAX + 50ULL)
00328 {
00329 check (j, 20, 2, 0)
00330 e = 1;
00331 }
00332 #pragma omp for schedule(runtime) nowait
00333 for (j = ULLONG_MAX - 3; j >= LLONG_MAX + 70ULL; j -= LLONG_MAX + 50ULL)
00334 {
00335 check (j, ULLONG_MAX - 3, 3, 0)
00336 e = 1;
00337 }
00338 #pragma omp for schedule(runtime) nowait
00339 for (j = LLONG_MAX - 20000ULL; j <= LLONG_MAX + 10000ULL; j += 10000ULL)
00340 {
00341 check (j, LLONG_MAX - 20000ULL, 4, 0)
00342 check (j, LLONG_MAX - 10000ULL, 4, 1)
00343 check (j, LLONG_MAX, 4, 2)
00344 check (j, LLONG_MAX + 10000ULL, 4, 3)
00345 e = 1;
00346 }
00347 #pragma omp for schedule(runtime) nowait
00348 for (i = -3LL * INT_MAX - 20000LL; i <= INT_MAX + 10000LL; i += INT_MAX + 200LL)
00349 {
00350 check (i, -3LL * INT_MAX - 20000LL, 5, 0)
00351 check (i, -2LL * INT_MAX - 20000LL + 200LL, 5, 1)
00352 check (i, -INT_MAX - 20000LL + 400LL, 5, 2)
00353 check (i, -20000LL + 600LL, 5, 3)
00354 check (i, INT_MAX - 20000LL + 800LL, 5, 4)
00355 e = 1;
00356 }
00357 }
00358 if (e)
00359 abort ();
00360 test (0, 3);
00361 test (1, 3);
00362 test (2, 1);
00363 test (3, 1);
00364 test (4, 4);
00365 test (5, 5);
00366 return 0;
00367 }
00368
00369 int
00370 main (void)
00371 {
00372 if (2 * sizeof (int) != sizeof (long long))
00373 return 0;
00374 test1 ();
00375 test2 ();
00376 test3 ();
00377 test4 ();
00378 omp_set_schedule (omp_sched_static, 0);
00379 test5 ();
00380 omp_set_schedule (omp_sched_static, 3);
00381 test5 ();
00382 omp_set_schedule (omp_sched_dynamic, 5);
00383 test5 ();
00384 omp_set_schedule (omp_sched_guided, 2);
00385 test5 ();
00386 return 0;
00387 }