[sac-user] Need more help on pass by reference

Daniel Rolls daniel.rolls.27 at googlemail.com
Mon Aug 23 14:46:45 CEST 2010


Salem,

I'm not too sure why exactly the version with the extra argument works  
and the other seg faults. Have you tried getting a backtrace with gdb?  
Maybe the best way to handle this would be to right a short c wrapper  
around CBLAS that returns just one newly allocated result array and to  
expose this wrapper to sac?

Dan

On 23 Aug 2010, at 04:39, Salem Reyen wrote:

> Daniel,
>
>   Thanks for the help.  I guess I didn't ask the question  
> correctly.  The method  you've suggested doesn't work for complex  
> numbers.  It took me a while to figure this out.  Let me give you an  
> example.
>
> Here is a C function signature:
>
> void cblas_zdotu_sub(const int N, const void *X, const int incX,  
> const void *Y, const int incY, void *dotu);
>
> It computes the dot product of two complex vectors X and Y with  
> length N and the result (which is also a complex number) is stored  
> at dotu.
>
> So, in SaC, if I define
>
> external double[2] cblas_zdotu_sub(int N,  double[.,.] X, int incX,  
> double[.,.] Y, int incY);
> #pragma linksign[6,1,2,3,4,5]
>
> and call
>
> print(cblas_zdotu_sub(10, X, 1, Y, 1));
>
> and then it generates segmentation fault.
>
> However, if I define,
>
> external double[2] cblas_zdotu_sub(int N,  double[.,.] X, int incX,  
> double[.,.] Y, int incY, double[2] dotc);
> #pragma linksign[6,1,2,3,4,5,6]
>
> and change the call to
>
> Z = [0d, 0d];
> print(cblas_zdotu_sub(10, X, 1, Y, 1, Z));
>
> and then it works.
>
> My guess is that since CBLAS are just C wrappers of FORTRAN  
> functions, the following link may provide the explanation:
> http://bytes.com/topic/c/answers/703405-calling-fortran-function-returns-complex
>
> Anyway, thanks again for your help.
>
> Salem
>
>
> --- On Sun, 8/22/10, Daniel Rolls <daniel.rolls.27 at googlemail.com>  
> wrote:
>
> From: Daniel Rolls <daniel.rolls.27 at googlemail.com>
> Subject: Re: [sac-user] Need more help on pass by reference
> To: "sac user mailing list" <sac-user at sac-home.org>
> Date: Sunday, August 22, 2010, 7:22 AM
>
> Salem,
>
> The array being returned (Z) should only appear one once in the SaC
> function signature as a return type. I.e
>
> external double[.] /* Z */ add( double[.] X, double[.] Y);
>
> Then in SaC you can call the function C = A + B by
> C = add(A,B)
>
> You can also write A = add(A,B) and A = add(A,A) but be aware that the
> returned A's are new variables and do not denote that memory used for
> the original A will be reused. Sac2c will work that out for you.
>
> I hope that clarifies things a bit,
> Dan
>
> On 22 Aug 2010, at 04:35, Salem Reyen wrote:
>
> > I have a C function which adds two double precision vectors, ie,
> > add(double* X, double *Y, double* Z) where vectors X and Y are
> > the input vectors and Z is the output vector.  In SaC, I declare
> > A, B, C to be double precision vectors.
> >
> > Based on Bodo's example, I can declare
> >
> > external double[.] add(double[.] X, double[.] Y, double[.] Z);
> > #pragma linksign[3,1,2,3]
> >
> > And then I can call the function add for C = A + B by
> > C = add(A, B, C);
> >
> > Now my question is how can SaC compiler handle the cases such as
> > A = A + B and A = A + A?
> >
> > Salem
> >
> >
> >
> > _______________________________________________
> > sac-user mailing list
> > sac-user at sac-home.org
> > http://lists.sac-home.org/mailman/listinfo.cgi/sac-user
> _______________________________________________
> sac-user mailing list
> sac-user at sac-home.org
> http://lists.sac-home.org/mailman/listinfo.cgi/sac-user
>
> _______________________________________________
> sac-user mailing list
> sac-user at sac-home.org
> http://lists.sac-home.org/mailman/listinfo.cgi/sac-user



More information about the sac-user mailing list