Vector arguments to external procedures 
Author Message
 Vector arguments to external procedures

Can anyone offer any suggestions as to how to persuade the external
interface to pass the address of an arbitrary element of a vector to an
external procedure?

This would often be useful, for example for performing an operation on
part of an array.

Just to be clear about what I mean: in C you might do

    int x[100];
    foo(*(x+30), 10);

to call foo for elements 30 to 39 of the array (where foo expects simply
an array and the number of elements in it). Likewise in fortran

    integer x(100)
    call foo(x(31), 10)

does the same. All numerical packages take advantage of this, and it
would be nice to be able to call foo in an equivalent way from Pop-11 -
one ought to be able to say something like

    vars x = initintvec(100);
    exacc foo(x[30], 10);

However, as far as I can tell, the code that translates arguments for
external procedures is buried deep and I can't see how I can increment
the address of a vector before it is passed out.

I realise that I can always provide an intermediate external routine
that takes an address and an offset and adds them before calling the
real routine. However, that's a pain as it has to be done for every
external routine I want to call, and it would be much handier to have
something that did it in Pop-11.

Any thoughts?

David

PS I've been writing an interface to Lapack/BLAS in case you wonder why
I want this.



Sat, 08 Oct 2005 00:20:53 GMT  
 Vector arguments to external procedures


Quote:
>Can anyone offer any suggestions as to how to persuade the external
>interface to pass the address of an arbitrary element of a vector to an
>external procedure?

(snip)

Quote:
>I realise that I can always provide an intermediate external routine
>that takes an address and an offset and adds them before calling the
>real routine. However, that's a pain as it has to be done for every
>external routine I want to call, and it would be much handier to have
>something that did it in Pop-11.

Surely only one intermediate? (Or one for each type of external
pointer).

The new routine doesn't call the real routine: it merely returns
the address for you to pass to the real routine?

I.e. instead of

    vars x = initintvec(100);
    exacc foo(x[30], 10);

which doesn't work, you do

    vars x = initintvec(100);
    exacc foo(addr(x, 30), 10);

where you have to define the addr function (once) but can use it
wherever you want to do this.

Am I missing something?

Jonathan

--
(Replace netspam by jlc when appropriate)



Sat, 08 Oct 2005 01:38:01 GMT  
 Vector arguments to external procedures

wrote

Quote:
> However, as far as I can tell, the code that translates arguments for
> external procedures is buried deep and I can't see how I can increment
> the address of a vector before it is passed out.

I wonder if sysFIELD/sysUFIELD (defined in REF VMCODE does what you
want).
It says
            For external accessing of structure or array components, the
        mode argument may also specify  that an external pointer to  the
        component should be returned rather than its value.

The mode argument presumably has the same definition as for cons_access

I have never used any of this stuff myself, but I was curious to know
whether what you wanted could be done without descending to the level
of writing syspop11 code.
        http://www.cs.bham.ac.uk/research/poplog/sysdoc/syspop11

That could be the last resort, I suppose.

Quote:
> I realise that I can always provide an intermediate external routine
> that takes an address and an offset and adds them before calling the
> real routine. However, that's a pain as it has to be done for every
> external routine I want to call, and it would be much handier to have
> something that did it in Pop-11.

The 'last resort' mentioned above would do it in syspop11, then add a
new syntax form to invoke the mechanism. That would be easier than
having go via an intermediate external routine for every call.

Quote:
> PS I've been writing an interface to Lapack/BLAS in case you wonder why
> I want this.

Just out of curiosity, does that offer facilities that are different
from GSL -- the Gnu Scientific library:
        http://sources.redhat.com/gsl/ref/gsl-ref_toc.html
which also mentions BLAS?

Aaron



Sat, 08 Oct 2005 02:07:03 GMT  
 Vector arguments to external procedures
Ah but it's one *external* routine, not one pop routine. Or at least, if it
was a pop routine, it could only be written by solving David's original
query anyway...

David: how dirty do you want to be? You can get the address of any pop
object using fast_subscrintvec on a full field. So something like this
should work:

    vars x=initintvec(100);
    vars temp = initv(x);
    vars x_addr = fast_subscrintvec(1,temp);    ;;; address of x as a (pop)
integer

    exacc foo(x_addr+30*sizeof(:int), 10);

can't recall whether I got sizeof right. Also you need to declare foo in pop
as taking an int, so that pop converts the value back from a pop int to a
machine int. And finally, if a gc happens between the last two steps you're
scuppered, unless you declare your intvec structure to be fixed (using
consfixed, but I forget the syntax).

Roger

Quote:



> >Can anyone offer any suggestions as to how to persuade the external
> >interface to pass the address of an arbitrary element of a vector to an
> >external procedure?

> (snip)

> >I realise that I can always provide an intermediate external routine
> >that takes an address and an offset and adds them before calling the
> >real routine. However, that's a pain as it has to be done for every
> >external routine I want to call, and it would be much handier to have
> >something that did it in Pop-11.

> Surely only one intermediate? (Or one for each type of external
> pointer).

> The new routine doesn't call the real routine: it merely returns
> the address for you to pass to the real routine?

> I.e. instead of

>     vars x = initintvec(100);
>     exacc foo(x[30], 10);

> which doesn't work, you do

>     vars x = initintvec(100);
>     exacc foo(addr(x, 30), 10);

> where you have to define the addr function (once) but can use it
> wherever you want to do this.

> Am I missing something?

> Jonathan

> --
> (Replace netspam by jlc when appropriate)



Sat, 08 Oct 2005 02:53:21 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Vector arguments to external procedures

2. Vector arguments to external procedures

3. Vector arguments to external procedures - correction

4. procedure as dummy argument (was: EXTERNAL and INTRINSIC statement)

5. Procedure Argument/External

6. Passing module procedures to external procedures -- type issues

7. Defining procedures whose argument list is result of procedure

8. passing functions with variable number of arguments as procedure arguments

9. Procedures as arguments - set dummy arguments

10. no vector = vector*vector in BLAS?

11. vector valued function as argument

12. passing arguments to external os/2 .CMD files

 

 
Powered by phpBB® Forum Software