首页 > 其他 > 详细

编译例子示范

时间:2015-03-23 13:13:31      阅读:303      评论:0      收藏:0      [点我收藏+]

 

 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 }

 技术分享

技术分享

编译例子示范

原文:http://www.cnblogs.com/liangliangdetianxia/p/4359275.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!