[petsc-users] MatShellGetContext in Fortran

Barry Smith bsmith at mcs.anl.gov
Wed Oct 7 13:50:45 CDT 2015


  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



More information about the petsc-users mailing list