X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/book_gpu.git/blobdiff_plain/588a7d5fe41e4604140b24fbe1bdec5e4a32febd..cf0ee588a0ef05623f955938e81be1aa96c33f46:/BookGPU/Chapters/chapter2/ex1.cu diff --git a/BookGPU/Chapters/chapter2/ex1.cu b/BookGPU/Chapters/chapter2/ex1.cu index e182349..64c08dd 100644 --- a/BookGPU/Chapters/chapter2/ex1.cu +++ b/BookGPU/Chapters/chapter2/ex1.cu @@ -18,16 +18,12 @@ void addition(int size, int *d_C, int *d_A, int *d_B) { int main( int argc, char** argv) { - if(argc!=2) { printf("usage: ex1 nb_components\n"); exit(0); } - - int size=atoi(argv[1]); - int i; int *h_arrayA=(int*)malloc(size*sizeof(int)); int *h_arrayB=(int*)malloc(size*sizeof(int)); @@ -35,7 +31,6 @@ int main( int argc, char** argv) int *h_arrayCgpu=(int*)malloc(size*sizeof(int)); int *d_arrayA, *d_arrayB, *d_arrayC; - cudaMalloc((void**)&d_arrayA,size*sizeof(int)); cudaMalloc((void**)&d_arrayB,size*sizeof(int)); cudaMalloc((void**)&d_arrayC,size*sizeof(int)); @@ -45,10 +40,9 @@ int main( int argc, char** argv) h_arrayB[i]=2*i; } - unsigned int timer_cpu = 0; cutilCheckError(cutCreateTimer(&timer_cpu)); - cutilCheckError(cutStartTimer(timer_cpu)); + cutilCheckError(cutStartTimer(timer_cpu)); for(i=0;i>>(size,d_arrayC,d_arrayA,d_arrayB); - cudaMemcpy(h_arrayCgpu,d_arrayC, size * sizeof(int), cudaMemcpyDeviceToHost); cutilCheckError(cutStopTimer(timer_gpu)); printf("GPU processing time : %f (ms) \n", cutGetTimerValue(timer_gpu)); cutDeleteTimer(timer_gpu); - for(i=0;i