[petsc-users] MatShellGetContext in Fortran
Timothée Nicolas
timothee.nicolas at gmail.com
Wed Oct 7 14:28:13 CDT 2015
Thank you very much Barry. It is working smoothly. Apparently it is very
important that for the Get context routine, the context be declared as a
pointer, and consistently, also in the routine where it is called (as in
ex5f90.F indeed).
Best
Timothee
2015-10-07 20:50 GMT+02:00 Barry Smith <bsmith at mcs.anl.gov>:
>
> Timothee,
>
> That information in the manual is not really accurate.
>
> Here is how you should do it. Take a look at
> src/snes/examples/tutorials/ex5f90.F and see the definition of the userctx
> data type and then further down the interface
> definitions for SNESSetApplicationContext() and
> SNESGetApplicationContext(). You need to mimic that same structure in your
> code but with MatShellSet/GetContext() instead.
> In this way you can do things properly and not need to deal with integer
> keys into data etc. Note that each level can have its own userctx data.
>
> Barry
>
>
>
> > On Oct 7, 2015, at 1:19 PM, Timothée Nicolas <timothee.nicolas at gmail.com>
> wrote:
> >
> > Hi all,
> >
> > In the manual, it says, about MatShellSetContext and MatShellGetContext,
> that in FORTRAN we cannot set a context other than integer or PetscObject.
> >
> >
> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreateShell.html#MatCreateShell
> >
> > In my understanding, it means that I would be allowed to do, say
> >
> > PetscInt :: ione
> > ione=1
> > call MatCreateShell(PETSC_COMM_WORLD,m,m,N,N,PETSC_NULL_INTEGER,A,ierr)
> > call MatShellSetContext(A,ione,ierr)
> > call MatShellSetOperation(A,MATOP_MULT,MyMult,ierr)
> >
> > in the routine where I define the matrix A, and then recover the integer
> in the routine MyMult with
> >
> > PetscInt :: intval
> > call MatShellGetContext(A,intval,ierr)
> >
> > This would allow me to circumvent the interdiction to pass a real
> context, by e.g. using a module at the beginning of MyMult, containing
> contexts and discriminating which context to use with the value of the
> integer (I want to use Multigrid, so I cannot have a different routine for
> each level obviously). However, this approach did not work, the value in
> intval stays undefined. How could I solve this ?
> >
> > Best
> >
> > Timothee
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20151007/3248b453/attachment.html>
More information about the petsc-users
mailing list