[petsc-users] TAO setup with modules in Fortran 90

Satish Balay balay at mcs.anl.gov
Fri Oct 6 16:33:28 CDT 2017


Here is the change to petsc-3.7 for it to work without 'use petsctao'
-i.e only using include files. [this works as long as you only need
stuff from petscdef.h in your module - and not the parameters defined
in petsc.h]

Satish
-------

balay at asterix /home/balay/tmp/petsc/src/tao/unconstrained/examples/tutorials (maint-3.7 *=)
$ git diff
diff --git a/src/tao/unconstrained/examples/tutorials/rosenbrock1f.F b/src/tao/unconstrained/examples/tutorials/rosenbrock1f.F
index 59c467714d..d160d540c0 100644
--- a/src/tao/unconstrained/examples/tutorials/rosenbrock1f.F
+++ b/src/tao/unconstrained/examples/tutorials/rosenbrock1f.F
@@ -22,9 +22,16 @@
 
 ! ----------------------------------------------------------------------
 !
+#include "petsc/finclude/petscdef.h"
+      module commondat
+      PetscReal    ::    alpha
+      PetscInt     ::    n
+      end module commondat
+
+      program main
+      use commondat
       implicit none
-
-#include "rosenbrock1f.h"
+#include "petsc/finclude/petsc.h"
 
 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 !                   Variable declarations
@@ -144,10 +151,9 @@
 !  f - function value
 
       subroutine FormFunctionGradient(tao, X, f, G, dummy, ierr)
+      use commondat
       implicit none
-
-! n,alpha defined in rosenbrock1f.h
-#include "rosenbrock1f.h"
+#include "petsc/finclude/petsc.h"
 
       Tao        tao
       Vec              X,G
@@ -216,9 +222,9 @@
 !  require this matrix.
 
       subroutine FormHessian(tao,X,H,PrecH,dummy,ierr)
+      use commondat
       implicit none
-
-#include "rosenbrock1f.h"
+#include "petsc/finclude/petsc.h"
 
 !  Input/output variables:
       Tao        tao
balay at asterix /home/balay/tmp/petsc/src/tao/unconstrained/examples/tutorials (maint-3.7 *=)
$ make rosenbrock1
mpicc -o rosenbrock1.o -c -fPIC  -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -fvisibility=hidden -g3   -I/home/balay/tmp/petsc/include -I/home/balay/tmp/petsc/arch-linux2-c-debug/include    `pwd`/rosenbrock1.c
mpicc -fPIC  -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -fvisibility=hidden -g3  -o rosenbrock1 rosenbrock1.o -Wl,-rpath,/home/balay/tmp/petsc/arch-linux2-c-debug/lib -L/home/balay/tmp/petsc/arch-linux2-c-debug/lib -Wl,-rpath,/home/balay/soft/mpich-3.3a2/lib -L/home/balay/soft/mpich-3.3a2/lib -Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/7 -L/usr/lib/gcc/x86_64-redhat-linux/7 -lpetsc -llapack -lblas -lX11 -lpthread -lm -lmpifort -lgfortran -lm -lgfortran -lm -lquadmath -lmpicxx -lstdc++ -lm -Wl,-rpath,/home/balay/soft/mpich-3.3a2/lib -L/home/balay/soft/mpich-3.3a2/lib -Wl,-rpath,/usr/lib/gcc/x86_64-redhat-linux/7 -L/usr/lib/gcc/x86_64-redhat-linux/7 -ldl -Wl,-rpath,/home/balay/soft/mpich-3.3a2/lib -lmpi -lgcc_s -ldl 
/usr/bin/rm -f rosenbrock1.o
balay at asterix /home/balay/tmp/petsc/src/tao/unconstrained/examples/tutorials (maint-3.7 *=)
$ make runrosenbrock1
balay at asterix /home/balay/tmp/petsc/src/tao/unconstrained/examples/tutorials (maint-3.7 *=)
$ 



On Fri, 6 Oct 2017, Randy Michael Churchill wrote:

> So if I'm limited to petsc 3.7.6 for reasons of eventually using within an
> existing, larger codebase that depends on 3.7.6, is it possible to use TAO
> with a user-defined module in Fortran90 using 3.7.6?
> 
> I had tried the various forms of includes listed in the documentation, e.g.
> see below. I think I now realize this is an issue with the petsc
> installation on Edison, it does not seem to have the petsctao module in the
> library file (confirmed using nm -D on the library file). If I do the same
> include and use statement but with, for example, petscmat, it compiles
> fine.
> 
> I built v3.8 from source, and the petsctao module is in the library file,
> and now the make works.
> 
> commondat.F90
> module commondat
> #include <petsc/finclude/petscdef.h>
>       use petsc
>       PetscReal    ::    alpha
>       PetscInt     ::    n
> end module commondat
> 
> program rosenbrock1f
> #include <petsc/finclude/petsctaodef.h>
>       use petsctao
>       use commondat
> 
> 
> 
> 
> On Fri, Oct 6, 2017 at 7:54 AM, Matthew Knepley <knepley at gmail.com> wrote:
> 
> > On Fri, Oct 6, 2017 at 7:36 AM, Barry Smith <bsmith at mcs.anl.gov> wrote:
> >
> >>
> >>    Randy,
> >>
> >>     First you absolutely must use version 3.8 or the master development
> >> copy. We improved and simplified dramatically how Fortran (90) is utilized
> >> from PETSc.
> >>
> >>     Note that there is only one simple set of include files and modules
> >> for Fortran; see the newest documentation.
> >>
> >>
> > http://www.mcs.anl.gov/petsc/petsc-master/docs/manualpages/
> > Sys/UsingFortran.html
> >
> >    Matt
> >
> >
> >>
> >>    Barry
> >>
> >>
> >> > On Oct 5, 2017, at 11:48 PM, Randy Michael Churchill <rchurchi at pppl.gov>
> >> wrote:
> >> >
> >> > A simple setup question with TAO: if I were to convert the
> >> rosenbrock1f.F90 example to use a module instead of common structures, how
> >> would I setup the include statements? I've tried various combinations
> >> (using petscXXXdef.h, petscXXX.h, petscXXX.h90, along with use petscXXX),
> >> but seem to get errors with all.
> >> >
> >> > file:rosenbrock1f.h:
> >> > module commondat
> >> >       PetscReal    ::    alpha
> >> >       PetscInt     ::    n
> >> > end module commondat
> >> >
> >> > file:rosenbrock1f.90:
> >> > program rosenbrock1f
> >> > !!include statements??? which and where???!!!
> >> > use commondat
> >> > ...
> >> >
> >> > subroutine FormFunctionGradient(tao, X, f, G, dummy, ierr)
> >> >      use commondat
> >> >      implicit none
> >> >      ...
> >> >
> >> > (https://www.mcs.anl.gov/petsc/petsc-dev/src/tao/unconstrain
> >> ed/examples/tutorials/rosenbrock1f.F90.html)
> >>
> >>
> >
> >
> > --
> > What most experimenters take for granted before they begin their
> > experiments is infinitely more interesting than any results to which their
> > experiments lead.
> > -- Norbert Wiener
> >
> > https://www.cse.buffalo.edu/~knepley/ <http://www.caam.rice.edu/~mk51/>
> >
> 
> 
> 
> 



More information about the petsc-users mailing list