C + + GPU && CPU

Source: Internet
Author: User

        

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&GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.