#include"../common/book.h"#define N 10voidadd(int*a,int*b,int*c ){
int tid =0;// this is CPU zero, so we start at zerowhile(tid < N){
c[tid]= a[tid]+ b[tid];
tid +=1;// we have one CPU, so we increment by one}}intmain(void){
int a[N], b[N], c[N];// fill the arrays 'a' and 'b' on the CPUfor(int i=0; i<N; i++){
a[i]=-i;
b[i]= i * i;}add( a, b, c );// display the resultsfor(int i=0; i<N; i++){
printf("%d + %d = %d\n", a[i], b[i], c[i]);}return0;}
GPU并发编程
#include"../common/book.h"#define N 10intmain(void){
int a[N], b[N], c[N];int*dev_a,*dev_b,*dev_c;// allocate the memory on the GPUHANDLE_ERROR(cudaMalloc((void**)&dev_a, N *
CUDA Parallel ProgrammingCPU并发编程GPU并发编程尖括号的含义块索引CPU并发编程#include "../common/book.h"#define N 10void add( int *a, int *b, int *c ) { int tid = 0; // this is CPU zero, so we start at zero while (tid < N) { c[tid] = a[tid] + b[tid]; tid += 1; //