zoukankan      html  css  js  c++  java
  • 编译例子示范

     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 );
    33     return 0;
    34 }

     

  • 相关阅读:
    第三个Sprint冲刺第三天
    回答第1-17章
    阅读第13-17章
    阅读第10、11、12章
    阅读第8,9,10章
    作业5.2 5.3
    四则运算 测试与封装 5.1
    阅读第5-7章
    阅读1-5章
    我给队友做的汉堡包
  • 原文地址:https://www.cnblogs.com/liangliangdetianxia/p/4359275.html
Copyright © 2011-2022 走看看