[petsc-users] tmat is not C interoperable

Smith, Barry F. bsmith at mcs.anl.gov
Thu Jun 7 18:54:36 CDT 2018


   Please find attached an example that uses the bind C and passes a PETSc object through.

   Note that you cannot pass directly a Fortran derived type to C.

    Barry


> On Jun 7, 2018, at 12:37 PM, Anthony Ruth <Anthony.J.Ruth.12 at nd.edu> wrote:
>
> Hello,
>
> I am trying to call a function in a C library from fortran. The fortran code should pass a Mat object to the C code. I defined the interface within the fortran code like this:
>
> #include <petsc/finclude/petscmat.h>
>
> interface
>     subroutine MY_FUNC(A_Mat) bind ( C, name = "MY_FUNC" )
>        use petscmat
>       Mat, intent(in) :: A_Mat
>     end subroutine MY_FUNC
>   end interface
>
> When I try to compile the code it produces this error:
>
> Variable ‘a_mat’ at (1) is a dummy argument to the BIND(C) procedure ‘MY_FUNC’ but is not C interoperable because derived type ‘tmat’ is not C interoperable
>
> My interpretation of the error is that there is some mismatch between the Mat data type defined in fortran and the Mat data type defined in C, so that I cannot pass one to the other. Is this true? Is there a compatible way to pass the Mat? Are the C and fortran implementations actually properly aligned and interchangeable so that all that is needed is something to tell the compiler to try anyway? I tried changing the data type of A_Mat to Integer Pointer (void *), but ran into a syntax error when attempting that.
>
> regards,
> Anthony Ruth
> NASA Space Technology Research Fellow
> Condensed Matter Theory
> University of Notre Dame

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180607/ac797bd4/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ex43.c
Type: application/octet-stream
Size: 211 bytes
Desc: ex43.c
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180607/ac797bd4/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ex43f.F90
Type: application/octet-stream
Size: 1101 bytes
Desc: ex43f.F90
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180607/ac797bd4/attachment-0001.obj>


More information about the petsc-users mailing list