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

Carl Alan Joslin carl.joslin at joslinfamily.co.uk
Mon Aug 23 13:27:07 CEST 2010


Hello Salem

Over the weekend I produce an example for you that adds to vectors,
making use of the advanced C interface.  The main advantage is that this
saves on potential copying and memory allocation.

The function takes 2 double vectors and adds them together, trying to
reuse the memory of one of the vectors if it can.

The code assumes that the two vectors are the same length.

I do not know if it will be help full.

Carl

On Sat, 2010-08-21 at 20:35 -0700, 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: add.c
Type: text/x-csrc
Size: 3634 bytes
Desc: not available
URL: <http://lists.sac-home.org/pipermail/sac-user/attachments/20100823/0274e950/attachment.c>
-------------- next part --------------
module add;

export all;

external double[.] add( double[.] x, double[.] y);
#pragma linkobj "add.o"
#pragma refcounting [0,1,2]


-------------- next part --------------
use Array: all;
use StdIO: all;
use add: all;

int main(){
  x = tod( iota( 20));
  y = x;
  z = add( x, y);
  print( z);

  return( 0);
}


More information about the sac-user mailing list