From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23047 invoked by alias); 26 Mar 2010 18:34:19 -0000 Received: (qmail 23027 invoked by uid 22791); 26 Mar 2010 18:34:18 -0000 X-SWARE-Spam-Status: No, hits=0.9 required=5.0 tests=AWL,BAYES_05,SARE_RAND_2 X-Spam-Check-By: sourceware.org Received: from mail-ew0-f216.google.com (HELO mail-ew0-f216.google.com) (209.85.219.216) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 26 Mar 2010 18:34:13 +0000 Received: by ewy8 with SMTP id 8so634623ewy.8 for ; Fri, 26 Mar 2010 11:34:11 -0700 (PDT) Received: by 10.213.68.203 with SMTP id w11mr432187ebi.43.1269628450229; Fri, 26 Mar 2010 11:34:10 -0700 (PDT) Received: from [192.168.1.6] (cpe-76-168-78-146.socal.res.rr.com [76.168.78.146]) by mx.google.com with ESMTPS id 14sm794360ewy.14.2010.03.26.11.34.08 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 26 Mar 2010 11:34:09 -0700 (PDT) Message-ID: <4BAD0026.5010909@gmail.com> Date: Fri, 26 Mar 2010 22:02:00 -0000 From: burlen User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: fortran 90 passing user defined type member to a c fucntion Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2010-03/txt/msg00317.txt.bz2 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