Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6977 Discussions

C++: how to convert from complex(double) to MKL_Complex16 and vice versa?

Paul_Margosian
Beginner
2,492 Views
Using Visual Studio 2008, C++, Windows 7, 64 bit.

Want to use LAPACKE_zgesv to solve systems of equations

Have calculated relevant matrices in C++ using (standard) complex

Need to convert these to MKL_Complex16 in order to use zgesv, then convert back afterwards.

Have tried a fewguesses that seemed reasonable, but no luck. The official example for zgesv just loads complex constants and does not do variable type conversions, so it doesn't help.

Help! I'm stuck once again. New user blues.

Paul Margosian
0 Kudos
4 Replies
barragan_villanueva_
Valued Contributor I
2,491 Views
Paul,

Please add the following define-line in your C++ source file before including mkl.h header file
#define MKL_Complex16 complex

After that no conversion will be needed because MKL_Comlex16 typeis redefined to your complex type.

Note, that such redefinitions are to be consistent in order to get correct results after MKL routines.
0 Kudos
Gennady_F_Intel
Moderator
2,491 Views
Paul,
the similar topic has been discussed here.
--Gennady
0 Kudos
Paul_Margosian
Beginner
2,491 Views
Victor,

Thanks. A very nice trick.

Unfortunately: MKL_Complex16 and complex are not enough alike for this to work (tried and had troubles).

One of many error messages revealed some details about how MKL_Complex16 is defined (a structuredefining "xxx.real" and "xxx.imag")

Just for the record, this is an example of what seems to work:

complexmyZ = (2.,3.);
MKL_Complex16 mkl_Z;

mkl_Z.real = real(myZ);
mkl_Z.imag = imag(myZ);

Did this with my input arrays (suitable loops and array formatting) for zgesv and compilation went OK.

Have not yet run this and checked outputs, so there is still a chance for additional puzzling problems.


Paul Margosian
0 Kudos
barragan_villanueva_
Valued Contributor I
2,491 Views
Paul,

Sorry, but I don't understand why you had problems if MKL_Complex16 was redefined.

Could you please send me small testcase to demonstrate this problem?
It will be helpful to make MKL-types more flexible and be freindlyin applications.
0 Kudos
Reply