123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #include <stdlib.h>
- int x;
- long long y;
- int r, s, t;
- void
- foo (const char *a)
- {
- #pragma omp sections lastprivate (conditional: x, y)
- {
- if (a[0])
- x = a[0];
- #pragma omp section
- {
- if (a[1])
- x = a[1];
- if (a[2])
- y = a[2];
- }
- #pragma omp section
- if (a[3])
- y = a[3];
- #pragma omp section
- if (a[4])
- x = a[4];
- #pragma omp section
- {
- if (a[5])
- x = a[5];
- if (a[6])
- y = a[6];
- }
- }
- }
- void
- bar (const char *a)
- {
- #pragma omp sections lastprivate (conditional: x, y) reduction (task, +: t)
- {
- if (a[0])
- x = a[0];
- #pragma omp section
- {
- if (a[1])
- x = a[1];
- if (a[2])
- y = a[2];
- #pragma omp task in_reduction (+: t)
- t++;
- }
- #pragma omp section
- if (a[3])
- y = a[3];
- #pragma omp section
- if (a[4])
- x = a[4];
- #pragma omp section
- {
- #pragma omp task in_reduction (+: t)
- ++t;
- if (a[5])
- x = a[5];
- if (a[6])
- y = a[6];
- }
- }
- }
- void
- baz (const char *a)
- {
- #pragma omp sections lastprivate (conditional: x, y) reduction (+: r, s)
- {
- if (a[0])
- x = a[0];
- #pragma omp section
- {
- if (a[1])
- x = a[1];
- ++r;
- ++s;
- if (a[2])
- y = a[2];
- }
- #pragma omp section
- if (a[3])
- y = a[3];
- #pragma omp section
- {
- ++s;
- if (a[4])
- x = a[4];
- }
- #pragma omp section
- {
- if (a[5])
- x = a[5];
- if (a[6])
- y = a[6];
- ++s;
- }
- }
- }
- int
- main ()
- {
- #pragma omp parallel
- {
- foo ("\0\1\2\3\0\5");
- if (x != 5 || y != 3)
- abort ();
- #pragma omp barrier
- foo ("\6\0\0\0\0\0\7");
- if (x != 6 || y != 7)
- abort ();
- #pragma omp barrier
- foo ("\7\6\5\4\3\2\1");
- if (x != 2 || y != 1)
- abort ();
- #pragma omp barrier
- foo ("\0\0\4\3\0\7");
- if (x != 7 || y != 3)
- abort ();
- #pragma omp barrier
- bar ("\0\1\2\4\0\5");
- if (x != 5 || y != 4 || t != 2)
- abort ();
- #pragma omp barrier
- bar ("\6\0\0\0\0\0\7");
- if (x != 6 || y != 7 || t != 4)
- abort ();
- #pragma omp barrier
- bar ("\7\6\5\4\3\2\1");
- if (x != 2 || y != 1 || t != 6)
- abort ();
- #pragma omp barrier
- bar ("\0\0\4\3\0\7");
- if (x != 7 || y != 3 || t != 8)
- abort ();
- #pragma omp barrier
- baz ("\0\1\2\4\0\5");
- if (x != 5 || y != 4 || r != 1 || s != 3)
- abort ();
- #pragma omp barrier
- baz ("\6\0\0\0\0\0\7");
- if (x != 6 || y != 7 || r != 2 || s != 6)
- abort ();
- #pragma omp barrier
- baz ("\7\6\5\4\3\2\1");
- if (x != 2 || y != 1 || r != 3 || s != 9)
- abort ();
- #pragma omp barrier
- baz ("\0\0\4\3\0\7");
- if (x != 7 || y != 3 || r != 4 || s != 12)
- abort ();
- }
- return 0;
- }
|