hello,
I want to do addition of all prime no. from 1 to 10,000. But my program showing me output up to 2000 no. only. If I increase the SIZE>2000 It is not showing correct output. I don’t know why it is so?? Is it due to any configuration related with graphics card?? or anything else??
I am using GeForce 210 (Compute Capability 1.2) with CUDA toolkit 6.5.(IDE-visual studio 2013)
Here is my program:
#include<stdio.h>
#include<cuda.h>
#include<malloc.h>
#include<conio.h>
#include<windows.h>
#define SIZE 2500
__global__ void vectoreAdd(int *d_a, int *d_b)
{
int i = threadIdx.x + (blockIdx.x*blockDim.x);
if (i<SIZE)
for (i = 2; i<SIZE; i++)
{
int counter = 0;
for (int j = 2; j<d_a**; j++)
{
if (d_a** % j == 0)
{
counter = 1; break;
}
}
if (counter == 0)
{
d_b** = d_a**;
}
}
}
int main()
{
int *a, *b, sum = 0,count=-1; //Declaration of host and device
int *d_a, *d_b;
cudaEvent_t start, stop;
float elapseTime;
int blocks, block_size = 512;
a = (int *)malloc(SIZE*sizeof(int));
b = (int *)malloc(SIZE*sizeof(int));
cudaMalloc((void**)&d_a, SIZE * sizeof(int));
cudaMalloc((void**)&d_b, SIZE * sizeof(int));
for (int i = 1; i<SIZE; i++)
{
a** = i;
b** = 0;
}
cudaMemcpy(d_a, a, SIZE*sizeof(int), cudaMemcpyHostToDevice);
cudaMemcpy(d_b, b, SIZE*sizeof(int), cudaMemcpyHostToDevice);
blocks = SIZE / block_size;
if (SIZE% block_size != 0)
blocks++;
//Calculate time of execution
cudaEventCreate(&start);
cudaEventCreate(&stop);
//start recording
cudaEventRecord(start, 0);
vectoreAdd << < blocks, block_size >> >(d_a, d_b);
//stop recording
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
//Copy results from GPU to CPU
cudaEventElapsedTime(&elapseTime, start, stop);
cudaEventDestroy(start);
cudaEventDestroy(stop);
printf("
Total elapsed time on GPU=%lf", elapseTime);
cudaThreadSynchronize();
cudaMemcpy(b, d_b, SIZE*sizeof(int), cudaMemcpyDeviceToHost);
for (int m = 0; m < SIZE; m++)
{
if (b[m] != 0)
{
printf("
prime no is:%d", b[m]);
count = count + 1;
}
}
printf("
Total prime no: %d", count);
for (int j = 1; j<SIZE; j++)
{
sum = sum + b[j];
}
printf("
sum of all prime no upto %d is:%d", SIZE, sum);
free(a);
free(b);
cudaFree(d_a);
cudaFree(d_b);
getchar();
return 0;
}
Can you please help me to sort it out??