using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
const int threadsPerBlock = 256;
const int blocksPerGrid = 1024;
const int N = 64;
__global__ void reverse(int *data, int count){
__shared__ int cache[threadsPerBlock];
int tid = threadIdx.x + blockIdx.x * blockDim.x;
int cacheIndex = threadIdx.x;
int tr = count-cacheIndex-1;
if(tid< count/2)
cache[cacheIndex] = data[cacheIndex];
__syncthreads();
data[cacheIndex] = cache[tr];
}
int main(void){
int a[N];
int *devA;
generate(a,N);
cudaMalloc((void**)&devA, N * sizeof(int));
cudaMemcpy(devA, a, N * sizeof(int), cudaMemcpyHostToDevice);
reverse<<<blocksPerGrid,threadsPerBlock>>>(devA,N);
cudaMemcpy(a,devA, N * sizeof(int), cudaMemcpyDeviceToHost);
cout << a[63];
cudaFree(devA);
}
Above code does not reverse my reverse. What is wrong with this program? What am i going wrong? I think everything is okay. What do i need to edit to work it properly? What is wrong?