source: CIVL/examples/openMP/omp.cvh@ 83c054c

1.23 2.0 main test-branch
Last change on this file since 83c054c was 2c44d945, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

named barrier signatures.

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

  • Property mode set to 100644
File size: 1.4 KB
Line 
1// global variables and procedures shared by all threads.
2
3/********************* functions provided by omp.h *************/
4$input int OMP_NUM_THREADS;
5int in_barrier[OMP_NUM_THREADS];
6int num_in_barrier = 0;
7
8int omp_get_num_threads() {
9 return OMP_NUM_THREADS;
10}
11
12/********************* helper functions for translation *************/
13
14/* Common functions for translating for loops */
15// computes the start index for a given thread
16int __for_start(int tid, int total) {
17 return ((total/OMP_NUM_THREADS) * tid);
18}
19
20//computes the end index for a given thread
21int __for_end(int tid, int total) {
22 return ((total/OMP_NUM_THREADS) * (tid + 1));
23}
24
25//computes the extra index for a given thread
26int __for_extra(int tid, int total) {
27 int offset = total % OMP_NUM_THREADS;
28
29 if(tid < offset) {
30 return total - offset + tid;
31 }
32 return 0;
33}
34
35/********************* barrier implementation *************/
36
37void __barrier_init() {
38 for (int i=0; i<OMP_NUM_THREADS; i++) in_barrier[i] = 0;
39}
40
41// model the synchronization of threads in the same block
42void __barrier(int tid) {
43 $atomic {
44 in_barrier[tid] = 1; // I am in the barrier
45 num_in_barrier++; // increment number in barrier
46 if (num_in_barrier == OMP_NUM_THREADS) { // I am last to enter
47 for (int i=0; i<OMP_NUM_THREADS; i++) in_barrier[i] = 0; // release all
48 num_in_barrier = 0; // now none are in barrier
49 }
50 }
51 $when (in_barrier[tid] == 0); // wait till I am released
52 }
Note: See TracBrowser for help on using the repository browser.