1 Reply Latest reply on Jan 25, 2011 2:06 PM by chipf

    doublecomplex

    janaj

      Hey,

      I have a pointer of doublecomplex using it as the data for my matrix class. Now I want to do some operations just on the real part of the pointer. I know I can work on one real part like this:

      doublecomplex * D = new doublecomplex[5];

      for(int i=0;i<5;i++){

          D.real = D.imag = i;

      }

       

      But I want to do something like this:

      doublecomplex *D,*E,*C;

      C = AddCL(D.real,E.real);

      This function uses opencl and there for I can't give it the doublecomplex pointer.

       

      Any ideas?

        • doublecomplex
          chipf

          I imagine you have already solved this, but I'll try to answer.

          First OpenCL is close enough to C so that the same rules apply for pointers, at least as far as your example illustrates.   In C/C++, using A.real as you have done is not meaningful.  You would have to say A[0].real to describe a real value, and there is no method to directly describe an array that is just the real values of the DoubleComplex array.

          I'm guessing you want your AddCL function to add the reals for all the elements in the array and store each one in the real part of C.  Then you should define it as something like AddRealCL (A,B,C) passing the pointers for all three arrays, and then the routine just accesses the individual real elements, adds them, and then stores in C. 

          You could have the function return a C which is a pointer, but you would either need to give it the address of C as  parameter, or the function would have to allocate a new C.