Pointers to procedures possible in g95? 
Author Message
 Pointers to procedures possible in g95?

With CVF, IVF, and Sun fortran I use Cray Pointers to procedures in one of
my modules. But this does not appear to be supported by g95. Is it possible
to use any form of pointers to procedures with g95?

Best Regards and thank You in Advance,
Stig Kildeg?rd Andersen



Wed, 23 Jul 2008 03:51:44 GMT  
 Pointers to procedures possible in g95?


Quote:
> With CVF, IVF, and Sun Fortran I use Cray Pointers to procedures in one of
> my modules. But this does not appear to be supported by g95. Is it possible
> to use any form of pointers to procedures with g95?

Can't help with g95.  I will note that gfortran has support
for Cray pointers.

--
Steve
http://troutmask.apl.washington.edu/~kargl/



Wed, 23 Jul 2008 04:07:25 GMT  
 Pointers to procedures possible in g95?

Quote:


> > With CVF, IVF, and Sun Fortran I use Cray Pointers to procedures in one of
> > my modules. But this does not appear to be supported by g95. Is it possible
> > to use any form of pointers to procedures with g95?

> Can't help with g95.  I will note that gfortran has support
> for Cray pointers.

Does that include Cray pointers toprocedures? Cray pointers not being
standardized, there are multiple variants of them. Several
implementations do Cray pointers, but not to procedures; that is a
separate question.

--
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain



Wed, 23 Jul 2008 05:19:34 GMT  
 Pointers to procedures possible in g95?


Quote:



>> > With CVF, IVF, and Sun Fortran I use Cray Pointers to procedures in one of
>> > my modules. But this does not appear to be supported by g95. Is it possible
>> > to use any form of pointers to procedures with g95?

>> Can't help with g95.  I will note that gfortran has support
>> for Cray pointers.

> Does that include Cray pointers toprocedures? Cray pointers not being
> standardized, there are multiple variants of them. Several
> implementations do Cray pointers, but not to procedures; that is a
> separate question.

The doucmentation states "The pointee may be an array or scalar.",
In reading the rest of the description, it appears that the pointee
cannot be a procedure.

--
Steve
http://troutmask.apl.washington.edu/~kargl/



Wed, 23 Jul 2008 05:47:12 GMT  
 Pointers to procedures possible in g95?



Quote:





writes:
> >> > With CVF, IVF, and Sun Fortran I use Cray Pointers to procedures in
one of
> >> > my modules. But this does not appear to be supported by g95. Is it
possible
> >> > to use any form of pointers to procedures with g95?

> >> Can't help with g95.  I will note that gfortran has support
> >> for Cray pointers.

> > Does that include Cray pointers toprocedures? Cray pointers not being
> > standardized, there are multiple variants of them. Several
> > implementations do Cray pointers, but not to procedures; that is a
> > separate question.

> The doucmentation states "The pointee may be an array or scalar.",
> In reading the rest of the description, it appears that the pointee
> cannot be a procedure.

> --
> Steve
> http://troutmask.apl.washington.edu/~kargl/

I use Cray pointers to procedures in CVF. But In porting my code to Intel
Fortran under linux using compiler version 8 point something we were unable
to get the compiler to accept the concept of pointing to a procedure. I
scoured Intel's web site in the Fortran version 9 section but was unable to
find any reference to procedure pointers and so concluded IVF didn't support
them. We've since upgraded to version 9 but I haven't tried procedure
pointers with that version.

But then again, the CVF documentation didn't mention this vital feature
either. It took a question on the CVF forum for Steve Lionel to point us at
a code example in the 'samples' folder as distributed on the CD. The trick
is to specify the procedure in an interface block, then reference it in the
second field of the pointer declaration.

Stig: Have you *really* got procedure pointers to work in IVF? If so, what's
the trick? Are you using it on Windows or Linux?

--
Qolin

Email: my qname at domain
Domain: qomputing dot demon dot co dot uk



Thu, 24 Jul 2008 06:15:10 GMT  
 Pointers to procedures possible in g95?

Quote:

> ... porting my code to Intel
> Fortran under linux using compiler version 8 point something we were unable
> to get the compiler to accept the concept of pointing to a procedure...

Using Cray Pointers to procedures works fine with ifort.  I've done it with
versions 8.0, 8.1, and 9.0 without major problem.

Interestingly, the Cray compilers themselves did *not* directly support pointing
to procedures.  Current SGI/MIPS compilers, which are based on the Cray front end,
are the same way.  So the ability to do procedure pointing with Cray pointers is
actually an "extension to an extension".  Nonetheless, it is pretty simple to
trick the code into doing procedure pointing anyway.  :)

One other technique, somewhat more standardised, is to use the POSIX 1003.9
functions PXFGETSUBHANDLE and PXFCALLSUBHANDLE.  I've also used these without
problem with SGI and Intel Fortran environments.  One restriction is that, by
the POSIX Standard, you get only 1 integer argument.  (However since the
PXF routines are Fortran-77-style calls, TKR checking on the argument can, er,
be, ahem, 'avoided' rather easily.  For example some clever programmer might try
to pass a derived type via that argument...)

Procedure pointers are one of the things I am really looking forward to in
F2003.

Walt



Wed, 23 Jul 2008 15:30:55 GMT  
 Pointers to procedures possible in g95?


Quote:
> Using Cray Pointers to procedures works fine with ifort.  I've done it
with
> versions 8.0, 8.1, and 9.0 without major problem.

Walt,

The guys porting my CVF code to Intel 8 under Linux swore blind (and
incidentally swore at me too) that they couldn't get the Cray pointers to
work for procedures. I can't post an example of the code I use until monday.
in the meantime, any chance you could post a sample of your code that works
under IVF? Also, double check: are we talking Windows or Linux?

As for the compiler folk, notably Intel: come ON guys, if your Cray pointers
support procedures, how about advertising it in the docs, or at least in the
release notes? This is a killer feature for me.

Quote:

> Procedure pointers are one of the things I am really looking forward to in
> F2003.

Join the club!

Qolin

Email: my qname at domain
Domain: qomputing dot demon dot co dot uk



Thu, 24 Jul 2008 16:48:18 GMT  
 Pointers to procedures possible in g95?
Sun's "no charge" Studio 11 Fortran compiler supports pointer
 to procedures.  I just ran the following program:

      PROGRAM MAIN
        EXTERNAL FOO, BAR
        POINTER (P, FOO)
        P = LOC(BAR)
        CALL FOO
      END

      SUBROUTINE BAR
        PRINT *, 'HELLO'
      END

You need to be running Solaris to use the latest released version of
Sun f95,
but a Linux version of the compiler is available as a technology
preview.

Bob Corbett



Wed, 23 Jul 2008 21:53:02 GMT  
 Pointers to procedures possible in g95?

Quote:

> The guys porting my CVF code to Intel 8 under Linux swore blind (and
> incidentally swore at me too) that they couldn't get the Cray pointers to
> work for procedures.

Note: For a number of reasons I would suggest upgrading to some 9.0
release.  I think they are at around 9.0.031 right now.

Quote:
> ... any chance you could post a sample of your code that works
> under IVF?

Basically it goes something like the following:

    integer, parameter :: fptr_k = 8
    external :: my_proc1, my_proc2
    integer(fptr_k) :: ptr_array(2)
    :
    external :: f
    pointer (pf, f)
    :
    ptr_array = (/ loc (my_proc1), loc (my_proc2) /)
    :
    do, i=1, size (ptr_array)
      pf = ptr_array(i)         ! Set the pointer
      call f (args...)          ! Call it
    end do

(That is off the top of my head.  Hopefully I've not messed up a detail.)

Using the PXF routines is easy too - if you can live with one
argument.  One simply codes:

    external :: my_proc1, my_proc2
    integer :: myfp_handle(2)
    integer :: pxferr   ! Error return.  Zero if successful.
    :
    call pxfgetsubhandle (my_proc1, myfp_handle(1), pxferr)
    call pxfgetsubhandle (my_proc2, myfp_handle(2), pxferr)    
    :
    do, i=1,size (myfp_handle)
      call pxfcallsubhandle (myfp_handle(i), my_arg, pxferr)
    end do

Quote:
> Also, double check: are we talking Windows or Linux?

IA64 Linux (SGI Altix).

Quote:
> As for the compiler folk, notably Intel: come ON guys, if your Cray pointers
> support procedures, how about advertising it in the docs, or at least in the
> release notes?

It is in their Ref Manual somewhere.  They refer to Cray Pointers as
"Integer Pointers" in their docs.  And they certainly do document the PXF
routines in the library manual.

Quote:
> This is a killer feature for me.

It is hard to see how.  Worst case, it is a few lines of C code.  Here is a
simplistic implementation of PXFGETSUBHANDLE and PXFCALLSUBHANDLE that works
on many current systems.  (Notably those that follow the original AT+T f77
naming/calling rules, and also where a memory address can fit in a default-sized
integer.):

typedef void (*Ffptr)(int *);
typedef int Fint;

void
pxfgetsubhandle_ (Ffptr sub, Fint *jhandle1, Fint *ierror)
{
  (void *)*jhandle1 = sub;
  *ierror = 0;

Quote:
}

void
pxfcallsubhandle_ (Fint *jhandle2, Fint *ival, Fint *ierror)
{
  Ffptr fp = *jhandle2;
  (*fp) (ival);
  *ierror = 0;

Quote:
}

HTH,

Walt



Wed, 23 Jul 2008 22:10:18 GMT  
 Pointers to procedures possible in g95?

Quote:


>>... porting my code to Intel
>>Fortran under linux using compiler version 8 point something we were unable
>>to get the compiler to accept the concept of pointing to a procedure...

> Using Cray Pointers to procedures works fine with ifort.  I've done it with
> versions 8.0, 8.1, and 9.0 without major problem.

> Interestingly, the Cray compilers themselves did *not* directly support pointing
> to procedures.  Current SGI/MIPS compilers, which are based on the Cray front end,
> are the same way.  So the ability to do procedure pointing with Cray pointers is
> actually an "extension to an extension".  Nonetheless, it is pretty simple to
> trick the code into doing procedure pointing anyway.  :)

> One other technique, somewhat more standardised, is to use the POSIX 1003.9
> functions PXFGETSUBHANDLE and PXFCALLSUBHANDLE.  I've also used these without
> problem with SGI and Intel Fortran environments.  One restriction is that, by
> the POSIX Standard, you get only 1 integer argument.  (However since the
> PXF routines are Fortran-77-style calls, TKR checking on the argument can, er,
> be, ahem, 'avoided' rather easily.  For example some clever programmer might try
> to pass a derived type via that argument...)

> Procedure pointers are one of the things I am really looking forward to in
> F2003.

After 30 or so years of user requests for them...:-)

Quote:

> Walt

--

Gary Scott

Fortran Library:  http://www.fortranlib.com

Support the Original G95 Project:  http://www.g95.org
-OR-
Support the GNU GFortran Project:  http://gcc.gnu.org/fortran/index.html

Why are there two?  God only knows.

If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford



Thu, 24 Jul 2008 02:03:59 GMT  
 Pointers to procedures possible in g95?

Yes. I had a sort of quarter-assed version of procedure pointers
implemented, and I've upgraded it to half-assed.  You can now do
something like:

---------------------------------------
subroutine proc
  print *, 'Hello from proc'
end

program main
procedure(), pointer :: pp
external :: proc

  pp => proc
  call pp()
end
---------------------------------------

This is for the build going up later tonight, you'll get crashes with
the current version.

  I think procedure pointers are a very exciting part of F2003.  Now
you can just initialize your intergrator with the function to call once
instead of passing it through potentially multiple layers of dummy
procedures.

        Andy



Thu, 24 Jul 2008 03:14:37 GMT  
 Pointers to procedures possible in g95?


< snip >

Quote:
> > ... any chance you could post a sample of your code that works
> > under IVF?

> Basically it goes something like the following:

>     integer, parameter :: fptr_k = 8
>     external :: my_proc1, my_proc2
>     integer(fptr_k) :: ptr_array(2)
>     :
>     external :: f
>     pointer (pf, f)
>     :
>     ptr_array = (/ loc (my_proc1), loc (my_proc2) /)
>     :
>     do, i=1, size (ptr_array)
>       pf = ptr_array(i) ! Set the pointer
>       call f (args...)  ! Call it
>     end do

> (That is off the top of my head.  Hopefully I've not messed up a detail.)

Thanks Walt. I notice you don't use an INTERFACE to the external routine,
which as it turns out is forbidden by IVF (see the Intel Fortran  9.0
reference manual, page B-13). This of course is exactly what my CVF code
does, so that explains why the folk doing the Intel/Linux port had trouble.
The original example in the CVF samples uses an Interface so of course I
copied it. In addition most of the routines I want to point to (with Cray
pointers) have (standard Fortran) pointer arguments, hence an explicit
interface is pretty much mandatory I think (certainly they crash horribly
(in CVF and IVF) without it).

Quote:
> It is in their Ref Manual somewhere.  They refer to Cray Pointers as
> "Integer Pointers" in their docs.  And they certainly do document the PXF
> routines in the library manual.

I had yet another good look at the Intel 9 Ref manuel this morning; various
references to "integer pointers", notably appendix B (Additional Language
Features), but nothing about being able to point to a procedure or an
external. The only place it gets close is where it forbids the pointee from
being in a "generic interface block". OK, knowing what I now know from your
post, I suppose I should have read between the lines here: What else might
be referenced in a generic interface block but an external procedure?

Quote:
> > This is a killer feature for me.

> It is hard to see how.  Worst case, it is a few lines of C code.

The need for the explicit interface is one reason, the multiplicity of
callback routines I need (about 20 of them) is another. Perhaps I should
explain. My application started out as a console or QuickWin executable, on
Windows with CVF. Then 3 years ago the company told me to split it into
"components", by which they meant DLLs, so that other windows programs could
access the functionality in agreeable-sized chunks. This work is finally
nearing completion. But to get things to work sensibly, the rump of the
original application needs to have various of the DLLs do call-backs to it,
which are implemented with Cray pointers. CVF allows me to declare
INTERFACEs to all of them, which as I said earlier seems essential due to
pointer arguments.

This lot then needs to be ported to IVF on Linux (said the suits some months
ago), where, guess what, it has to be converted back to a console
application. In this situation the Cray pointers are solving a problem we no
longer have, nevertheless we would have preferred to leave them in as the
path of least resistance for the port. Alas and woe.

"A few lines of C code" ? ...Er, I don't think so... Then again, it would be
nice to be proved wrong.

<moan_at_Intel>
OK guys, if you REALLY want to push IVF as the replacement for CVF, how
about making it compatible? WHY, oh WHY, prevent the pointee of a Cray
pointer being defined in an INTERFACE statement, when CVF allows it, and
even gives an example of it in liew of actual documentation?
</moan_at_Intel>

Ok, I know Steve Lionel will jump on me for not posting this on the Intel
Forum, so I guess I better do just that. But it'll have to wait until
tomorrow.

--
Qolin

Email: my qname at domain
Domain: qomputing dot demon dot co dot uk



Fri, 25 Jul 2008 04:20:42 GMT  
 Pointers to procedures possible in g95?

Quote:

> .... I notice you don't use an INTERFACE to the external routine,
> which as it turns out is forbidden by IVF (see the Intel Fortran  9.0
> reference manual, page B-13). This of course is exactly what my CVF code
> does, so that explains why the folk doing the Intel/Linux port had trouble...

Well...  Now you are talking about an "extension to an extension to an
extension"...  I'd recommend sticking with simple f77-style calls here.
Note that one can still pass derived types.

Quote:
> "A few lines of C code" ? ...Er, I don't think so... Then again, it would be
> nice to be proved wrong.

The main things you can do with procedure pointers are a.) obtain the address of
a procedure (e.g., PXFGETSUBHANDLE), and b.) call the procedure through the
pointer (e.g., PXFCALLSUBHANDLE).  Those two routines, perhaps with slight
variation in the latter to accept more args of different TKR, provide
the basic capability.

Walt



Thu, 24 Jul 2008 13:03:23 GMT  
 Pointers to procedures possible in g95?

Quote:
> ---------------------------------------
> subroutine proc
>   print *, 'Hello from proc'
> end

> program main
> procedure(), pointer :: pp
> external :: proc

>   pp => proc
>   call pp()
> end
> ---------------------------------------

seems to be working now.. That certainly is an interesting feature of
F03.

Joost



Thu, 24 Jul 2008 13:20:38 GMT  
 Pointers to procedures possible in g95?

Quote:
> This is for the build going up later tonight, you'll get crashes with
> the current version.

>  I think procedure pointers are a very exciting part of F2003.  Now
> you can just initialize your intergrator with the function to call once
> instead of passing it through potentially multiple layers of dummy
> procedures.

>        Andy

That sounds great Andy. Thank You. I will try it when the Windows binary is
updated.

Best Regards,
Stig Kildeg?rd Andersen



Thu, 24 Jul 2008 19:59:25 GMT  
 
 [ 20 post ]  Go to page: [1] [2]

 Relevant Pages 

1. g95 procedure pointers as derived-type components

2. Pointers to pointers possible?

3. dummy procedure and g95

4. array-valued dummy procedure, a bug in g95?

5. g95 on Windows: g95.exe: no input files

6. storing procedure addresses in variable possible?

7. Is it possible to pass argument by pointer to a VI.

8. Remote Procedure Calls W95/NT : possible????

9. array of pointer possible?

10. Q? Possible Problem with Procedures and Namespaces

11. stored procedures possible with tclodbc?

12. Is it possible to [trace] a procedure

 

 
Powered by phpBB® Forum Software