parallel_for_each(av.extent, [=](concurrency::index<1>idx)restrict(amp) {av[idx] += 1; });

//[=](concurrency::index<1>idx操作每一个元素
//restrict(amp)定位GPU执行

 

 1 #include <iostream>
 2 #include <amp.h>
 3 
 4 void main()
 5 {
 6     int a[10] = { 1,2,3,4,5,6,7,8,9,10 };
 7 
 8     concurrency::array_view<int>av(10, a);//GPU计算结构,av存储到GPU显存
 9 
10     parallel_for_each(av.extent, [=](concurrency::index<1>idx)restrict(amp) {av[idx] += 1; });
11     //[=](concurrency::index<1>idx操作每一个元素
12     //restrict(amp)定位GPU执行
13 
14     for (int i = 0; i < 10; i++)
15     {
16         std::cout << av[i] << std::endl;
17     }
18 }