PCShellSetContext fortran interface

Barry Smith bsmith at mcs.anl.gov
Fri Jun 8 12:58:08 CDT 2007



On Thu, 7 Jun 2007, Stephan Kramer wrote:

> Hi Barry,
> 
> Thanks, just wanted some clarification. Might I suggest in the documentation 
> as well? I don't understand what you mean by:
> 
>   in Fortran 90 one can pass in address of derived types, allocated arrays etc
> 
> Do you mean to rely on the fact that, without an explicit interface, fortran 
> will (in practice) pass in the derived type by reference, which granted you 
> do for the integer as well? 

  Yes

> This is quite in contradiction what it says in 
> the documentation, and has nothing to do with any Fortran 90 standard. 

   This could be true; but logically what else could it do in this situation?
It seems to me the only other logical approach would be to generate an error
at compile time.  Also you can provide a "fake" interface for the function
in your code, for example

      module somename
      Interface PCShelSetContext
        Subroutine PCShellSetContext(pc,ctx,ierr)
          PC pc
          type(myderivedtype), pointer :: ctx
          PetscErrorCode ierr
        End Subroutine
      End Interface DAVecGetArrayF90

   We have not tested all Fortran compilers so yes you are potentially 
taking a chance that the code is not portable.


   Barry


>Also 
> you would have to rely on the fact that this is gonna work for the supplied 
> apply routine as well.
> 
> As I said, I am merely being curious here. Thanks for any clarification. BTW 
> is there a fortran interface for PCShellSetDestroy coming any soon?
> 
> Thanks
> Stephan
> 
> On Thursday 07 June 2007 22:22:49 Barry Smith wrote:
> >   Stephan,
> >
> >     Even from Fortran the context is treated as a memory address, not
> > an integer value. You could use a common block (yuck) or some array that
> > is alloacated higher in the stack as the context, but as you note you
> > cannot use a local variable.
> >
> >     Barry
> >
> > You could argue that we should have implemented the way you suggest as
> > only allow an integer value, but I would respond that in Fortran 90 one
> > can pass in address of derived types, allocated arrays etc so I prefer our
> > current design.
> >
> > On Thu, 7 Jun 2007, Stephan Kramer wrote:
> > > Hi,
> > >
> > > I don't know if this is the expected behaviour but calling
> > > PCShellSetContext from fortran, the thing that is stored is not the
> > > integer value of context, but the pointer to this integer. Thus problems
> > > arise when supplying an integer variable that goes out of scope (e.g. on
> > > the stack) inbetween PCShellSetContext and the call to the 'apply shell
> > > preconditioner' routine. I know this makes sense from the C point of
> > > view, where you are merely supplying a void pointer, but this is not what
> > > you expect in Fortran were the only use of context could be as a
> > > reference/index itself to another object, and you thus expect the value
> > > of context to be stored.
> > >
> > > Cheers
> > > Stephan Kramer
> 
> 
> 




More information about the petsc-users mailing list