source: CIVL/examples/omp/simd_simple.c@ 8190175

main test-branch
Last change on this file since 8190175 was c864f11, checked in by Wenhao Wu <wuwenhao@…>, 2 years ago

Add a simple simd for loop example

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

  • Property mode set to 100644
File size: 485 bytes
RevLine 
[c864f11]1#include <stdio.h>
2#include <assert.h>
3#define N 6
4
5void func(int n, double A[restrict]) {
6 double s = 0.0;
7#pragma omp simd simdlen(2)
8 for (int i = 0; i < 2*n; ++i) {
9#pragma civl depend source(A)
10 S1:
11 s += A[i];
12#pragma civl depend target(A)
13 S2:
14 A[i] = 10.0*i;
15 }
16 printf("s=%lf\n", s);
17 assert(s == 2*N*(2*N-1)/2);
18}
19
20int main(void) {
21 double A[2*N];
22 for (int i=0; i<2*N; i++)
23 A[i] = i;
24 func(N, A);
25 for (int i=0; i<2*N; i++)
26 assert(A[i] == 10.0*i);
27}
Note: See TracBrowser for help on using the repository browser.