#include <stdio.h>
#include <sys/time.h>
#include <cuda_runtime.h>
float *h_A, *h_B, *h_C, *d_A, *d_B, *d_C;
float **d_Many, **h_Many;
cudaError_t err = cudaSuccess;
long numElements = 10000000;
double startHostAllocate, endHostAllocate, startDeviceAllocate,
endDeviceAllocate, startCopy, endCopy, startExecute, endExecute;
double cpuSecond() {
struct timeval tp;
gettimeofday(&tp, NULL);
return ((double) tp.tv_sec + (double) tp.tv_usec * 1.e-6);
}
void** allocateManyHostMemory(void **manyHostMemory, int length, size_t size,
int numElements) {
manyHostMemory = (void **) malloc(sizeof(void*) * length);
printf("Host array memory allocated");
for (int i = 0; i < length; i++) {
manyHostMemory[i] = malloc(size * numElements);
}
return manyHostMemory;
}
void allocateMemory(int numElements) {
bool memcpyThisArray[numElements];
startHostAllocate = cpuSecond();
{
allocateManyHostMemory((void **) h_Many, 3, sizeof(float), numElements);
}
endHostAllocate = cpuSecond();
printf("Host memory allocated");
}
int main(void) {
startDeviceAllocate = cpuSecond();
allocateMemory(numElements);
endDeviceAllocate = cpuSecond();
}
Edit gdb results
Program received signal SIGSEGV, Segmentation fault.
allocateMemory (numElements=10000000) at addOperation.cu:46
46 startHostAllocate = cpuSecond();
(gdb) bt
#0 allocateMemory (numElements=10000000) at addOperation.cu:46
#1 0x00000000004027f9 in main () at addOperation.cu:59
(gdb)
what am I missing here ?
Edit Again for MVCE I have added code so that it can be copied and compiled.