source: CIVL/examples/omp/dotProduct_orphan.cvl@ a6d04a0

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since a6d04a0 was 0f03d75, checked in by Stephen Siegel <siegel@…>, 12 years ago

Added sideEffect directory with one example failing.
Working on omp examples.

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

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/* dotProduct_orphan.cvl: model of dotProduct_orphan.c.
2 */
3#include <civlc.h>
4#include <stdio.h>
5#include <stdlib.h>
6#define VECLEN 10
7#define THREAD_MAX 4
8/* Does thread t own iteration i in loop with n iterations? */
9#define CIVL_owns(t, n, i) ((i)%(n)==(t))
10
11float a[VECLEN], b[VECLEN], sum;
12
13// note dotprod has been changed to accept
14// _tid and _nthreads, since it can be called
15// from a parallel construct.
16// also, return type has changed to void since it
17// does not return value.
18void dotprod (int _tid, int _nthreads) {
19 int i, tid, _sum=0;
20
21 tid = _tid;
22 // #pragma omp for reduction(+:sum)
23 for (i=0; i < VECLEN; i++) {
24 if (CIVL_owns(_tid, _nthreads, i)) {
25 _sum = _sum + (a[i]*b[i]);
26 printf(" tid= %d i=%d\n",tid,i);
27 }
28 }
29 sum += _sum;
30}
31
32void main () {
33 int i;
34
35 for (i=0; i < VECLEN; i++)
36 a[i] = b[i] = 1.0 * i;
37 sum = 0.0;
38 { // #pragma omp parallel
39 int nthreads = 1+$choose_int(THREAD_MAX);
40 $proc threads[nthreads];
41 void parallel_body(int _nthreads, int _tid) {
42 dotprod(_nthreads, _tid);
43 }
44
45 for (int tid=0; tid<nthreads; tid++)
46 threads[tid] = $spawn parallel_body(tid, nthreads);
47 for (int tid=0; tid<nthreads; tid++)
48 $wait(threads[tid]);
49 } // end of parallel region
50
51 printf("Sum = %f\n",sum);
52}
Note: See TracBrowser for help on using the repository browser.