source: CIVL/examples/omp/dotProduct_orphan.cvl

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[0f03d75]1#include <stdio.h>
2#include <stdlib.h>
[20ac35f]3#include <omp.h>
4#include <civl-omp.cvl>
[0f03d75]5
[20ac35f]6$input int THREAD_MAX;
7$omp_team **parallelDataArr;
8int $omp_numThreads = THREAD_MAX;
[0f03d75]9
[20ac35f]10$input int CIVL_argc;
11$input char CIVL_argv[10][];
12$scope $gen_root = $here;
[0f03d75]13
[20ac35f]14float a[100];
15float b[100];
16float sum;
17float dotprod(int _tid)
18{
19 int i;
20 int tid;
[0f03d75]21 tid = _tid;
[20ac35f]22 $omp_team team = *parallelDataArr[_tid];
23 $omp_shared *sharedArr = team->shared;
24 void* b_local = sharedArr[1]->local;
25
26
27 {
28 $range r1 = 0 .. 100 - 1 # 1;
29 $domain(1) loop_domain = ($domain){r1};
30 $domain(1) my_iters = ($domain(1))($omp_arrive_loop(team, 0, ($domain)loop_domain, 2));
31 float sum$omp_reduction = 0;
32 $for(int i: my_iters)
33 {
34 float tmpRead0;
35 $omp_read(sharedArr[1], &tmpRead0, &b_local[i]);
36 float tmpRead1;
37 $omp_read(sharedArr[0], &tmpRead1, &sharedArr[0]->local[i]);
38 sum$omp_reduction = sum$omp_reduction + (tmpRead1 * tmpRead0);
39 printf(" tid= %d i=%d\n", tid, i);
[0f03d75]40 }
[20ac35f]41 $omp_apply_assoc(sharedArr[2], 3, &sum$omp_reduction);
42 $omp_barrier_and_flush(team);
[0f03d75]43 }
44}
[20ac35f]45int main()
46{
47 int argc = CIVL_argc;
48 char* _argv[10];
49 char** argv;
50 for(int i = 0; i < 10; i++)
51 _argv[i] = &CIVL_argv[i][0];
52 argv = &_argv[0];
[0f03d75]53 int i;
[20ac35f]54 for(i = 0; i < 100; i++)
[0f03d75]55 a[i] = b[i] = 1.0 * i;
56 sum = 0.0;
[20ac35f]57 {
58 int _nthreads = 1 + $choose_int($omp_numThreads);
59 $range thread_range = 0 .. _nthreads - 1;
60 $domain(1) dom = ($domain){thread_range};
61 $omp_gteam gteam = $omp_gteam_create($here, _nthreads);
62 $omp_gshared sum_gshared = $omp_gshared_create(gteam, &sum);
63 $omp_gshared a_gshared = $omp_gshared_create(gteam, &a);
64 $omp_gshared b_gshared = $omp_gshared_create(gteam, &b);
65 parallelDataArr = ($omp_team**)($malloc($gen_root, $omp_numThreads * sizeof($omp_team*)));
66 $parfor(int _tid: dom)
67 {
68 $omp_team team = $omp_team_create($here, gteam, _tid);
69 float sum_local;
70 int sum_status;
71 float a_local[100];
72 int a_status[100];
73 float b_local[100];
74 int b_status[100];
75 $omp_shared sum_shared = $omp_shared_create(team, sum_gshared, &sum_local, &sum_status);
76 $omp_shared a_shared = $omp_shared_create(team, a_gshared, &a_local, &a_status);
77 $omp_shared b_shared = $omp_shared_create(team, b_gshared, &b_local, &b_status);
78 parallelDataArr[_tid] = &team;
79 dotprod(_tid);
80 $omp_barrier_and_flush(team);
81 $omp_shared_destroy(sum_shared);
82 $omp_shared_destroy(a_shared);
83 $omp_shared_destroy(b_shared);
84 $omp_team_destroy(team);
[0f03d75]85 }
[20ac35f]86 $omp_gshared_destroy(sum_gshared);
87 $omp_gshared_destroy(a_gshared);
88 $omp_gshared_destroy(b_gshared);
89 $omp_gteam_destroy(gteam);
90 }
91 printf("Sum = %f\n", sum);
[0f03d75]92}
Note: See TracBrowser for help on using the repository browser.