1#include <amp.h>2 3#include <iostream>4 5#include <winbase.h>//the underlying file of the operating system6 7 8 9 using namespaceconcurrency;Ten One using namespacestd; A - - the voidMain () { - - - + - + intA [] = {1,2,3,4,5,6,7,8,9,Ten }; A atarray_view<int>av (Ten, a);//GPU Computing Architecture, AV storage to GPU memory, initialization based on arrays - - //restrict directed to the GPU - - //direct operation of AV, (index<1>) operation of each element - in - toParallel_for_each (Av. extent, [=] (index<1>IDX) Restrict (AMP) {av [idx] + =1; }); + - the * for(inti =0; I <Ten; i++) { $ Panax NotoginsengStd::cout << Av[i] <<Endl; - the } + A the +Cin.Get (); - $ $ - } - the
for the respective advantages of GPU and CPU:
GPU Advantage is the high efficiency of multi-point computing, concurrent computing
The advantage of CPU is the high efficiency of single point calculation
1#include <amp.h>2#include <algorithm>3#include <iostream>4#include <functional>5 6 using namespaceconcurrency;7 using namespacestd;8 9Template < typename T >Ten classMy { One Public : A //overloaded () function - void operator() (ConstT & A)Const { -Std::cout << a <<end; the } - }; - - intMain () { + intstr [] = {'a','b','C','D','e','F','g','h','I','J','k','L' }; - +array_view<int> SS ( A, str); AParallel_for_each (ss. Extent, [=] (index<1>idx) Restrict (AMP) { atSS[IDX] + =1; - } - ); - for(unsignedinti =0; I < A; i++) { -Std::cout << static_cast <Char>(Ss[i]); - } inCin.Get (); - return 0 ; to } +
C + + GPU && CPU