编译例子示范

 

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <assert.h>
 4 
 5 int main( int argc, char* argv[] )
 6 {
 7     int n;      /* size of the vector */
 8     float *restrict a;  /* the vector */
 9     float *restrict r;  /* the results */
10     float *restrict e;  /* expected results */
11     int i;
12     if( argc > 1 )
13         n = atoi( argv[1] );
14     else
15         n = 100000;
16     if( n <= 0 ) n = 100000;
17 
18     a = (float*)malloc(n*sizeof(float));
19     r = (float*)malloc(n*sizeof(float));
20     e = (float*)malloc(n*sizeof(float));
21     for( i = 0; i < n; ++i ) a[i] = (float)(i+1);
22 
23     #pragma acc region
24     {
25         for( i = 0; i < n; ++i ) r[i] = a[i]*2.0f;
26     }
27     /* compute on the host to compare */
28         for( i = 0; i < n; ++i ) e[i] = a[i]*2.0f;
29     /* check the results */
30     for( i = 0; i < n; ++i )
31         assert( r[i] == e[i] );
32     printf( "%d iterations completed\n", n );
33     return 0;
34 }

 

转载于:https://www.cnblogs.com/liangliangdetianxia/p/4359275.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值