[petsc-users] variable declaration in Fortran90
Dharmendar Reddy
dharmareddy84 at gmail.com
Wed Aug 29 11:50:56 CDT 2012
Hello Ron,
I do not know how your are actually including the files and
compiling. Have a look at the attached example illustrating petsc usage in
Fortran, i tried to make the structure similar to the code you posted. You
should be able to test it by (1) make test and (2) ./test
Thanks
Reddy
On Wed, Aug 29, 2012 at 10:28 AM, Roc Wang <pengxwang at hotmail.com> wrote:
> Thanks for the kindly reply.
>
> By saying petscdef files, do you mean petscXXXdef, where XXX is the
> corresponding component of PETSc, such as vec, mat, et. al.?
>
> I tried the following approach, but it still doesn't work. The errors
> come out since there are some PETSc variables defined in Module
> MyParameter. The compiler cannot find PETSc datatype. The conflict is that
> some PESTs variables have to defined in Module MyParameter, and other PETSc
> variables and PETSc subroutines are defined and called in another Module
> MySub. Any hints and suggestions would be appreciated very much. Thanks.
>
> !--------------the way I declared the PETSc files
>
> Module MyParameter
> Implicit none
> #include "finclude/petscsysdef.h" ! Put all petscXXXdef,h in the
> module
> #include "finclude/petscvecdef.h"
> #include "finclude/petscmatdef.h"
> #include "finclude/petscpcdef.h"
> #include "finclude/petsckspdef.h"
>
>
> Integer:: ... ...
> Real:: ... ... ! There are some PETSc variables defined in this
> Module
>
>
>
> End Module MyParameter
>
> Module MySub
> Use Myparameter
> Contains
> ... ...
> Subroutine MyPETSc_APP()
>
> #include "finclude/petscsys.h"
> #include "finclude/petscvec.h"
> #include "finclude/petscmat.h"
> #include "finclude/petscpc.h"
> #include "finclude/petscksp.h"
>
> #include "finclude/petscsys.h90"
> #include "finclude/petscmat.h90"
> #include "finclude/petscvec.h90"
> Implicit none
>
> ... ...
> Call MatSetType(A_Mat, MATAIJ, ierr)
> ... ...
> End Subroutine MyPETSc_APP
>
> ... ...
> EndModule MySub
>
> Main Program
> Use MyParameter
> Use MySub
> ... ...
> ... ...
> End
>
> ------------------------------
> Date: Tue, 28 Aug 2012 16:00:58 -0500
> From: dharmareddy84 at gmail.com
> To: petsc-users at mcs.anl.gov
> Subject: Re: [petsc-users] variable declaration in Fortran90
>
>
> From what i understand, you should #include the corresponding petscdef
> files in the module and the petsc headers in the subroutine.
>
> petsc version installed on machine is petsc-3.2-p5
> I use a single include file: #include "finclude/petscdef.h" in the module
> and in the subroutines (including the ones that are defined after contains
> in the module) and program.
> #include "finclude/petsc.h"
> you can use #include "finclude/petsc.h90" if you are using the things
> such as vecgetArrayF90
>
> On Tue, Aug 28, 2012 at 3:45 PM, Roc Wang <pengxwang at hotmail.com> wrote:
>
> Hello,
>
>
> I am developing Fortran90 code with PETSc. Several Modules are defined
> in the code. Such as
>
> Module MyParameter
> Implicit none
> #include "finclude/petscsys.h"
> #include "finclude/petscvec.h"
> #include "finclude/petscmat.h"
> #include "finclude/petscpc.h"
> #include "finclude/petscksp.h"
> #include "finclude/petscvec.h90"
> #include "finclude/petscmat.h90"
>
> Integer:: ... ...
> Real:: ... ...
>
>
> End Module MyParameter
>
> Module MySub
> Use Myparameter
> Contains
> ... ...
> Call MatSetType(A_Mat, MATAIJ, ierr)
> ... ...
> EndModule MySub
>
>
> Main Program
> Use MyParameter
> Use MySub
> ... ...
> ... ...
> End
>
> If I put all the modules in a single .F90 file, the compilation can be
> done successfully. However, If I put the modules in separated files, the
> following error information comes out:
>
> Error: Symbol 'mataij' at (1) has no IMPLICIT type.
>
> In addition, if I use PetscInt, PetscErrorCode to declare variables in
> Module MySub, the similar errors come out. How declare the variable with
> PETSc type in separate files? Thanks.
>
>
>
>
>
>
>
>
>
>
>
> --
> -----------------------------------------------------
> Dharmendar Reddy Palle
> Graduate Student
> Microelectronics Research center,
> University of Texas at Austin,
> 10100 Burnet Road, Bldg. 160
> MER 2.608F, TX 78758-4445
> e-mail: dharmareddy84 at gmail.com
> Phone: +1-512-350-9082
> United States of America.
>
>
--
-----------------------------------------------------
Dharmendar Reddy Palle
Graduate Student
Microelectronics Research center,
University of Texas at Austin,
10100 Burnet Road, Bldg. 160
MER 2.608F, TX 78758-4445
e-mail: dharmareddy84 at gmail.com
Phone: +1-512-350-9082
United States of America.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120829/40083d2a/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PETScFortranExample.zip
Type: application/zip
Size: 1603 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120829/40083d2a/attachment-0001.zip>
More information about the petsc-users
mailing list