[sac-user] Need more help on pass by reference
salemreyen at yahoo.com
Mon Aug 23 05:39:38 CEST 2010
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 cblas_zdotu_sub(int N, double[.,.] X, int incX, double[.,.] Y, int incY);
print(cblas_zdotu_sub(10, X, 1, Y, 1));
and then it generates segmentation fault.
However, if I define,
external double cblas_zdotu_sub(int N, double[.,.] X, int incX, double[.,.] Y, int incY, double dotc);
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:
Anyway, thanks again for your help.
--- 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
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,
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?
> sac-user mailing list
> sac-user at sac-home.org
sac-user mailing list
sac-user at sac-home.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the sac-user