I have difficulties to use complex numbers in cuda,pycuda.
I have this in C:
#include <complex>
typedef std::complex<double> cmplx;
....
cmplx j(0.,1.);
Also,in the same code:
#include <boost/python.hpp>
#include <boost/array.hpp>
...
typedef std::vector< boost::array<std::complex<double>,3 > > ComplexFieldType;
typedef std::vector< boost::array<double,3> > RealFieldType;
...
__global__ void compute(RealFieldType const & Rs,ComplexFieldType const & M,..)
...
How can i convert this to use it with pycuda? I tried sth like this (according to the book 'cuda by an example'):
struct cuComplex {
float real;
float imag;
cuComplex(float a,float b): real(a),imag(b){}
cuComplex operator *(const cuComplex& a) {
return cuComplex(real*a.real -imag*a.imag ,imag*a.real +real*a.imag);
}
cuComplex operator +(const cuComplex& a) {
return cuComplex(real+a.real ,imag+a.imag);
};
cuComplex j(0.,1.); //instead of cmplx j(0.,1.);
__global__ void compute(float *Rs,cuComplex * M,..) //instead of RealFieldType const & Rs,ComplexFieldType const & M
....
Some of the errors i take are:
data member initializer is not allowed
this declaration has no storage class or type specifier
Thank you!
---------------------EDIT----------------------------------------------
I did the following using #include <pycuda-complex.hpp>
(relative to the above) :
pycuda::complex<float> cmplx;
cmplx j(0.,1.);
and as for typedef std::vector< boost::array<std::complex<double>,3 > > ComplexFieldType;
and ComplexFieldType const & M
,inside the global function,
i tried just "float *M " or "cmplx *M".
Until now , i am getting error :
variable "cmplx" is not a type name
If i use pycuda::complex cmplx; ,then i get:
identifier "cmplx" is undefined
name followed by "::" must be a class or namespace name
Also:
expression must have pointer-to-object type (but maybe this is from another part of code)