Hi, I want to use the mklfft with multithreading, but I faced the problem. I got an error - Segmentation fault (core dumped) even when I just created the simple 2D dimension dynamic array. Also, I have checked the multithread example with static array, it worked perfectly, but when I created dynamic array, it gave me an error. Could you tell me what is wrong I am doing, please?
This is my code:
#include "mkl_dfti.h"
#include <omp.h>
#include <math.h>
#include <complex.h>
#include <float.h>
#include <sys/time.h>
int main(int argc, char *argv[])
{
int k, j, N = atoi(argv[1]);
MKL_Complex8 **data = malloc(N*sizeof(MKL_Complex8*));
for(k=0; k<N; k++){
data[k] = malloc(N*sizeof(MKL_Complex8));
}
printf(
"Before FFT: N %d.\n",
N);
MKL_LONG len[2] = {N, N};
DFTI_DESCRIPTOR_HANDLE FFT;
int th;
printf("Create...\n");
DftiCreateDescriptor (&FFT, DFTI_SINGLE, DFTI_COMPLEX, 2, len);
DftiCommitDescriptor (FFT);
printf("Execute...\n");
struct timeval start, end;
gettimeofday(&start, NULL);
DftiComputeForward (FFT, data);
DftiFreeDescriptor (&FFT);
gettimeofday(&end, NULL);
double tstart = start.tv_sec + start.tv_usec/1000000.;
double tend = end.tv_sec + end.tv_usec/1000000.;
double t_sec = (tend - tstart);
int S = N*N;
double speed = (double) 5*S*log2(S)/t_sec*1e-6;
printf("Time: %0.6f, Speed: %0.6f\n", t_sec, speed);
for(j=0; j<N; j++) {
free(data[j]);
}
free(data);
return 0;
}