source: CIVL/examples/translation/cuda/test.cvl@ 764d472

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 764d472 was a86ac45, checked in by Andre Marianiello <andre.marianiello@…>, 12 years ago

Moved a few more files over from the civl-papers/examples repo

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1187 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 837 bytes
Line 
1#include "civlc.h"
2#include "stdio.h"
3
4int 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.