source: CIVL/examples/openacc/acc_c1/acc_c1.c

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: 1.5 KB
Line 
1/*
2 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 *
10 */
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <assert.h>
15
16int main( int argc, char* argv[] )
17{
18 int n; /* size of the vector */
19 float *a; /* the vector */
20 float *restrict r; /* the results */
21 float *e; /* expected results */
22 int i, nerrors;
23 nerrors = 0;
24 if( argc > 1 )
25 n = atoi( argv[1] );
26 else
27 n = 100000;
28 if( n <= 0 ) n = 100000;
29
30 a = (float*)malloc(n*sizeof(float));
31 r = (float*)malloc(n*sizeof(float));
32 e = (float*)malloc(n*sizeof(float));
33 /* initialize */
34 for( i = 0; i < n; ++i ) a[i] = (float)(i+1);
35
36 #pragma acc kernels loop
37 for( i = 0; i < n; ++i ) r[i] = a[i]*2.0f;
38 /* compute on the host to compare */
39 for( i = 0; i < n; ++i ) e[i] = a[i]*2.0f;
40 /* check the results */
41 for( i = 0; i < n; ++i ) {
42 if ( r[i] != e[i] ) {
43 nerrors++;
44 }
45 }
46 printf( "%d iterations completed\n", n );
47 if ( nerrors != 0 ) {
48 printf( "Test FAILED\n");
49 } else {
50 printf( "Test PASSED\n");
51 }
52
53 return 0;
54}
Note: See TracBrowser for help on using the repository browser.