1.23
2.0
acw/focus-triggers
main
test-branch
| Line | |
|---|
| 1 | #include "civlc.h"
|
|---|
| 2 | #include "stdio.h"
|
|---|
| 3 |
|
|---|
| 4 | int main ( void ) {
|
|---|
| 5 | int numThreads = 2;
|
|---|
| 6 | $gbarrier _g = $gbarrier_create($here, numThreads);
|
|---|
| 7 | float cache[numThreads];
|
|---|
| 8 |
|
|---|
| 9 | for (int i = 0; i < numThreads; i++)
|
|---|
| 10 | cache[i] = i + 1;
|
|---|
| 11 |
|
|---|
| 12 | void f(int tid) {
|
|---|
| 13 | $barrier _b = $barrier_create($here, _g, tid);
|
|---|
| 14 |
|
|---|
| 15 | int i = numThreads / 2;
|
|---|
| 16 | int cacheIndex = tid;
|
|---|
| 17 |
|
|---|
| 18 | while (i != 0) {
|
|---|
| 19 | if (cacheIndex < i)
|
|---|
| 20 | cache[cacheIndex] += cache[cacheIndex + i];
|
|---|
| 21 | $barrier_call(_b);
|
|---|
| 22 | i /= 2;
|
|---|
| 23 | }
|
|---|
| 24 | $barrier_destroy(_b);
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | $proc thread[numThreads];
|
|---|
| 28 | for (int i = 0; i < numThreads; i++)
|
|---|
| 29 | thread[i] = $spawn f(i);
|
|---|
| 30 | for (int i = 0; i < numThreads; i++)
|
|---|
| 31 | $wait(thread[i]);
|
|---|
| 32 |
|
|---|
| 33 | int answer = cache[0];
|
|---|
| 34 | int total = numThreads * (numThreads + 1) / 2;
|
|---|
| 35 | printf("answer = %d, total = %d\n", answer, total);
|
|---|
| 36 |
|
|---|
| 37 | $assert(answer == total);
|
|---|
| 38 |
|
|---|
| 39 | $gbarrier_destroy(_g);
|
|---|
| 40 |
|
|---|
| 41 | return 0;
|
|---|
| 42 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.