I've been learning to use Intel Math Kernel Library. Everything has been fine until now when I require to efficiently:
Specifically, I require to perform a = x * exp(iy) where x and y are arrays of doubles of the same size, and a should be an array of MKL_Complex16.
Since MKL_Complex16 = struct { double real, imag } I can manually make new arrays of MKL_Complex16 and write the real values to the real member, but that seems incredibly inefficient. This calculation is required to be performed thousands of times. I can also manually compute the exponential as sine and cosine, and again use a loop, but that isn't good either. Perhaps there is a routine that can copy into only the "real" member, but because of possible padding of the structure, I don't think that would work.
Both x and y arrays are evaluated efficiently, but how can I calculate "a" efficiently? (This is to to part of the input to a reverse FFT using MKL).
Thank you!
I found that I could write my real array of doubles directly to the real and imaginary parts of the array of MKL_Complex16 using cblas_dcopy.
double *real = (double*) mkl_malloc(N*sizeof(double), 64);
double *imag = (double*) mkl_malloc(N*sizeof(double), 64);
MKL_Complex16* z = (MKL_Complex16*) mkl_malloc(N*sizeof(MKL_Complex16), 64);
// Fill real and imag arrays with your data, then write them to the complex array
cblas_dcopy(N, real, 1, &(z[0].real), 2);
cblas_dcopy(N, imag, 1, &(z[0].imag), 2);
This worked on the Intel Xeon Phi. If the technique is used then you can combine double arrays and MKL_Complex16 arrays for use with MKL. It allowed me to compute the formula a = x * exp(iy), as I wanted. I hope that this helps someone else in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With