fortran 90 passing user defined type member to a c fucntion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When calling a c function from a fortran 90 program with members of a user defined types for output arguments of the called subroutine the user defined types aren't being modified as they should be (according to my understanding). But if I pass in native types (eg integer), these are modified upon return as expected. So for the user defined types it's behaving like pass by value, rather than pass by reference. The c function has no interface defined, it's just linked in, so in my understanding all arguments should be treated like intent inout, and I think that means pass by reference. Am I correct in thinking that all arguments passed to the c function should be passed by reference?

An example of passing the user defined type members to a fortran subroutine showed that modifications of the arguments inside the subroutine are visible to the caller when the subroutine returns. Which is what I expected. There must be something about calling the c function that changes the behavior.

Am I overlooking something simple here? If not, can someone explain why the user defined type members are passed by value?
Thanks
Burlen


Here is an excerpt of the code:



module CartesianDecompModule
 use BoxModule
!============================================================================
 type CartesianDecomp
   integer   WorldRank          ! my rank in comm world
   integer   WorldSize          ! number of processes in the communicator
   !----------------------------
   integer   Comm               ! optimized cartesian communicator
   logical   Periodicity(3)     ! periodic BC flags
   logical   Reorder            ! if set optimize the communicator
   integer   NDims              ! dimensionality (1,2, or 3)
   integer   NSubDomains(3)     ! number of sub-domains
   integer   SubDomainCoords(3) ! index space coordinates into decomp
   type(Box) Domain             ! simulation domain
   type(Box) SubDomain          ! local portion of the domain

 end type CartesianDecomp

contains
!----------------------------------------------------------------------------
 subroutine CreateCommunicator(c)
   use mpi

   implicit none
   type(CartesianDecomp) :: c ! object to initialize
   integer :: iErr
   integer :: comm,nsubs(3),subs(3)

! ! This doesn't work. output arguments c%NSubDomains,c%Comm,c%SubDomainCoords, aren't modified ??
   ! call MPI_Dims_create(c%WorldSize,c%NDims,c%NSubDomains,iErr)
! call MPI_Cart_create(MPI_COMM_WORLD,c%NDims,c%NSubDomains,c%Periodicity,c%Reorder,c%Comm,iErr) ! call MPI_Cart_get(c%Comm,c%NDims,c%NSubDomains,c%Periodicity,c%SubDomainCoords,iErr)

   ! This works.
   subs(:)=0
   nsubs(:)=0
   call MPI_Dims_create(c%WorldSize,c%NDims,nsubs,iErr)
call MPI_Cart_create(MPI_COMM_WORLD,c%NDims,nsubs,c%Periodicity,c%Reorder,comm,iErr)
   call MPI_Cart_get(comm,c%NDims,nsubs,c%Periodicity,subs,iErr)
   c%Comm=comm
   c%NSubDomains=nsubs
   c%SubDomainCoords=subs

 end subroutine

end module





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux