#include <iostream>
#include <cuda.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
using namespace std;

__global__ void kernel_gpu(float *B0,int N){
int i = blockIdx.x * blockDim.x + threadIdx.x;
if (i < N){
B0[i] = B0[i]+B0[i]*B0[i];
}
}

void kernel_cpu(float *B0,int N){
for(int i=0;i<N;i++){
B0[i] = B0[i]+B0[i]*B0[i];
}
}

int main(int argc,char **argv) {
fprintf(stderr, "414 ");
int size=664252;
int intBytes = size*sizeof(int);
int floatBytes = size*sizeof(float);
float *B0;
B0 = (float *)malloc(floatBytes);
for(int i=0;i<664252;i++){
B0[i] = 87.3329811454*i+1;
}
float *d_B0;
cudaMalloc((void **)&d_B0,664252*sizeof(float));
cudaMemcpy(d_B0,B0,664252*sizeof(float),cudaMemcpyHostToDevice);
int n = 2595*256;
int block_size = 256;
int block_no = n/block_size;
struct timeval time0,time1;
gettimeofday(&time0,NULL);
kernel_gpu<<<block_no,block_size>>>(d_B0,664252);
cudaThreadSynchronize();
gettimeofday(&time1,NULL);
double totaltime10 = (time1.tv_sec*1000000.0 + time1.tv_usec) - (time0.tv_sec*1000000.0 + time0.tv_usec);
fprintf(stderr, "GPU time: %lf msecs ",  (totaltime10)/1000.0F);
gettimeofday(&time0,NULL);
kernel_cpu(B0,664252);
gettimeofday(&time1,NULL);
totaltime10 = (time1.tv_sec*1000000.0 + time1.tv_usec) - (time0.tv_sec*1000000.0 + time0.tv_usec);
fprintf(stderr, "CPU time: %lf msecs ",  (totaltime10)/1000.0F);
float *testB0;
testB0 = (float *)malloc(floatBytes);
cudaMemcpy(testB0,d_B0,664252*sizeof(int),cudaMemcpyDeviceToHost);
for(int i=0;i<664252;i++){
}
free(B0);
free(testB0);
cudaFree(d_B0);
printf("\n");return 0; }