Re: [petsc-users] understand the restart number and total iteration number in GMRES

2018-06-03 Thread Jed Brown
GMRES provides a cheap estimate of the residual norm at each iteration.
In some cases ("happy breakdown") the iteration can't even proceed.  So
there is no point building a subspace of size m, then looking for a
solution.  Instead, just run until the estimated residual norm satisfies
the criteria, restarting with the current estimate of the solution as
initial guess any time the subspace would exceed dimension m.  This is
how everyone does restarted GMRES.

Mike Wick  writes:

> Hi:
>
> I am trying to understand the KSPGMRES a little more. In most books (or,
> Algorithm 4 in Saad's 1986 paper), I found that the GMRES(m) algorithm
> tries to construct a Krylov subspace with size m first, then seek for a
> solution that minimize over this space. Therefore, the total iteration
> number should be a multiple of the restart number.
>
> Apparently this is not the case in KSPGRMES. I wander if there is any
> stopping condition inside the restart algorithm, or if I misunderstand some
> part.
>
> Thanks!
>
> Mike


[petsc-users] understand the restart number and total iteration number in GMRES

2018-06-03 Thread Mike Wick
Hi:

I am trying to understand the KSPGMRES a little more. In most books (or,
Algorithm 4 in Saad's 1986 paper), I found that the GMRES(m) algorithm
tries to construct a Krylov subspace with size m first, then seek for a
solution that minimize over this space. Therefore, the total iteration
number should be a multiple of the restart number.

Apparently this is not the case in KSPGRMES. I wander if there is any
stopping condition inside the restart algorithm, or if I misunderstand some
part.

Thanks!

Mike


Re: [petsc-users] Makefile for mixed C++ and Fortran code

2018-06-03 Thread Satish Balay
Glad it works. Thanks for the update.

Satish

On Sun, 3 Jun 2018, Danyang Su wrote:

> Hi Satish,
> 
> Your makefile works.
> 
> Please ignore the CGAL dependency. I just modified from CGAL example and it
> needs to be further optimized with the dependency that is required for the
> algorithm I use.
> 
> Thanks,
> 
> Danyang
> 
> 
> On 18-06-02 02:51 PM, Satish Balay wrote:
> > Try the attached makefile. [with correct PETSC_DIR and PETSC_ARCH values]
> >
> > If you have issues - send the complete makefiles - and complete error log..
> >
> >
> > On Sat, 2 Jun 2018, Danyang Su wrote:
> >
> >> Hi Barry,
> >>
> >> For the code without PETSc, the rules used to compile the code with CGAL is
> > note: DLIB  can probably be simlified - and a fewof the options eliminated.
> >
> >
> >> DLIB = -lstdc++ -lmetis -lm -L/usr/local/lib -rdynamic
> > -lstdc++ is setup by petsc
> >
> > -lmetis can be a dependency of petsc - so care should be taken to have only
> > one copy of metis
> >
> >> /usr/local/lib/libmpfr.so /usr/local/lib/libgmp.so
> > Why are these here? Normally these are dependencies of gcc/gfortran [and
> > PETSc configure picks up the correct ones]
> >
> >> /usr/local/lib/libCGAL_ImageIO.so.11.0.1 /usr/local/lib/libCGAL.so.11.0.1
> > I have no idea what these are..
> >
> > Satish
> >
> >> /usr/local/lib/libboost_thread.so /usr/local/lib/libboost_system.so
> >> -lpthread
> >> -lGLU -lGL -lX11 -lXext -lz /usr/local/lib/libCGAL_ImageIO.so.11.0.1
> >> /usr/local/lib/libCGAL.so.11.0.1 /usr/local/lib/libboost_thread.so
> >> /usr/local/lib/libboost_system.so -lpthread -lGLU -lGL -lX11 -lXext -lz
> >> /usr/local/lib/libmpfr.so /usr/local/lib/libgmp.so
> >> /usr/local/lib/libboost_thread.so /usr/local/lib/libboost_system.so
> >> -lpthread
> >> -Wl,-rpath,/usr/local/lib
> >>
> >> FFLAGS = -O3 -I$(LIS_INC)
> >> CXXFLAGS = -std=c++11 -O3 -I$(LIS_INC)
> >>
> >> However, after adding these to the makefile using PETSc, I got error
> >> telling
> >> me that all the petsc include files cannot be found.
> >>
> >> ../../solver/solver_snes_common.F90:27:0: fatal error: petscversion.h: No
> >> such
> >> \
> >> file or directory
> >>   #include 
> >>
> >> ../../solver/solver_snes_common.F90:27:0: fatal error: petscversion.h: No
> >> such
> >> \
> >> file or directory
> >>   #include 
> >>
> >> Similar for other head files. However, If I change the file path to the the
> >> full path, the code cannot compiled. Does the rule I use destroy the PETSc
> >> relative path/
> >>
> >> The make commands I use is
> >>
> >> executable: $(SOURCES) chkopts
> >>  -${FLINKER} $(FFLAGS) $(FPPFLAGS) $(CPPFLAGS)  -o executable.out
> >> $(SOURCES) ${PETSC_LIB} ${LIS_LIB} ${DLIB}
> >> %.o:%.F90
> >>  $(FLINKER) $(FFLAGS) $(FPPFLAGS) -c -frounding-math $< -o $@
> >> %.o:%.cpp
> >>  $(CLINKER) $(CXXFLAGS) $(CPPFLAGS) -c -frounding-math $< -o $@
> >>
> >> Thanks,
> >>
> >> Danyang
> >>
> >> On 18-06-01 10:41 AM, Smith, Barry F. wrote:
> >>>  You need to determine exactly what flags are passed to the C++
> >>>  compiler
> >>>  for your compile that works and make sure those same flags are used
> >>>  in
> >>>  "PETSc version" of the makefile. You could add the flags directly to
> >>>  the
> >>>  rule
> >>>
>  %.o:%.cpp
>   $(CLINKER) $(CXXFLAGS) $(CPPFLAGS) -c -frounding-math $< -o $@
> >>> Barry
> >>>
> >>>
>  On Jun 1, 2018, at 12:37 PM, Danyang Su  wrote:
> 
>  Follow up:
> 
>  With following command
> 
>  executable: $(SOURCES) chkopts
>   -${FLINKER} $(FFLAGS) $(FPPFLAGS) $(CPPFLAGS)  -o executable.out
>   $(SOURCES) ${PETSC_LIB}
> 
>  %.o:%.F90
>   $(FLINKER) $(FFLAGS) $(FPPFLAGS) -c -frounding-math $< -o $@
>  %.o:%.cpp
>   $(CLINKER) $(CXXFLAGS) $(CPPFLAGS) -c -frounding-math $< -o $@
> 
>  The compiler return error: no match function.
> 
>  ../../usg/cgal_triangulation_2d.cpp: In function ‘void
>  outputTriangulation2d(in\
>  t, const char*, int, const char*)’:
>  ../../usg/cgal_triangulation_2d.cpp:485:20: error: no matching function
>  for
>  cal\
>  l to ‘std::basic_ofstream::open(std::string&)’
>   out.open(strfile);
> 
>  Thanks,
> 
> 
>  Danyang
> 
>  On 18-06-01 10:07 AM, Danyang Su wrote:
> > Hi All,
> >
> > My code needs to link to an external C++ library (CGAL). The code is
> > written in Fortran and I have already written interface to let Fortran
> > call C++ function. For the sequential version without PETSc, it can be
> > compiled without problem using the following makefile. The parallel
> > version without CGAL can also be compiled successfully. However, when I
> > tried to use PETSc together with CGAL library, I cannot compile the
> > code.
> > My questions is: How can I modify the makefile? Do I need to reconfigure
> > PETSc with special flags? All the makefile samples are shown below.

Re: [petsc-users] Makefile for mixed C++ and Fortran code

2018-06-03 Thread Danyang Su

Hi Satish,

Your makefile works.

Please ignore the CGAL dependency. I just modified from CGAL example and 
it needs to be further optimized with the dependency that is required 
for the algorithm I use.


Thanks,

Danyang


On 18-06-02 02:51 PM, Satish Balay wrote:

Try the attached makefile. [with correct PETSC_DIR and PETSC_ARCH values]

If you have issues - send the complete makefiles - and complete error log..


On Sat, 2 Jun 2018, Danyang Su wrote:


Hi Barry,

For the code without PETSc, the rules used to compile the code with CGAL is

note: DLIB  can probably be simlified - and a fewof the options eliminated.



DLIB = -lstdc++ -lmetis -lm -L/usr/local/lib -rdynamic

-lstdc++ is setup by petsc

-lmetis can be a dependency of petsc - so care should be taken to have only one 
copy of metis


/usr/local/lib/libmpfr.so /usr/local/lib/libgmp.so

Why are these here? Normally these are dependencies of gcc/gfortran [and PETSc 
configure picks up the correct ones]


/usr/local/lib/libCGAL_ImageIO.so.11.0.1 /usr/local/lib/libCGAL.so.11.0.1

I have no idea what these are..

Satish


/usr/local/lib/libboost_thread.so /usr/local/lib/libboost_system.so -lpthread
-lGLU -lGL -lX11 -lXext -lz /usr/local/lib/libCGAL_ImageIO.so.11.0.1
/usr/local/lib/libCGAL.so.11.0.1 /usr/local/lib/libboost_thread.so
/usr/local/lib/libboost_system.so -lpthread -lGLU -lGL -lX11 -lXext -lz
/usr/local/lib/libmpfr.so /usr/local/lib/libgmp.so
/usr/local/lib/libboost_thread.so /usr/local/lib/libboost_system.so -lpthread
-Wl,-rpath,/usr/local/lib

FFLAGS = -O3 -I$(LIS_INC)
CXXFLAGS = -std=c++11 -O3 -I$(LIS_INC)

However, after adding these to the makefile using PETSc, I got error telling
me that all the petsc include files cannot be found.

../../solver/solver_snes_common.F90:27:0: fatal error: petscversion.h: No such
\
file or directory
  #include 

../../solver/solver_snes_common.F90:27:0: fatal error: petscversion.h: No such
\
file or directory
  #include 

Similar for other head files. However, If I change the file path to the the
full path, the code cannot compiled. Does the rule I use destroy the PETSc
relative path/

The make commands I use is

executable: $(SOURCES) chkopts
 -${FLINKER} $(FFLAGS) $(FPPFLAGS) $(CPPFLAGS)  -o executable.out
$(SOURCES) ${PETSC_LIB} ${LIS_LIB} ${DLIB}
%.o:%.F90
 $(FLINKER) $(FFLAGS) $(FPPFLAGS) -c -frounding-math $< -o $@
%.o:%.cpp
 $(CLINKER) $(CXXFLAGS) $(CPPFLAGS) -c -frounding-math $< -o $@

Thanks,

Danyang

On 18-06-01 10:41 AM, Smith, Barry F. wrote:

 You need to determine exactly what flags are passed to the C++ compiler
 for your compile that works and make sure those same flags are used in
 "PETSc version" of the makefile. You could add the flags directly to the
 rule


%.o:%.cpp
 $(CLINKER) $(CXXFLAGS) $(CPPFLAGS) -c -frounding-math $< -o $@

Barry



On Jun 1, 2018, at 12:37 PM, Danyang Su  wrote:

Follow up:

With following command

executable: $(SOURCES) chkopts
 -${FLINKER} $(FFLAGS) $(FPPFLAGS) $(CPPFLAGS)  -o executable.out
 $(SOURCES) ${PETSC_LIB}

%.o:%.F90
 $(FLINKER) $(FFLAGS) $(FPPFLAGS) -c -frounding-math $< -o $@
%.o:%.cpp
 $(CLINKER) $(CXXFLAGS) $(CPPFLAGS) -c -frounding-math $< -o $@

The compiler return error: no match function.

../../usg/cgal_triangulation_2d.cpp: In function ‘void
outputTriangulation2d(in\
t, const char*, int, const char*)’:
../../usg/cgal_triangulation_2d.cpp:485:20: error: no matching function for
cal\
l to ‘std::basic_ofstream::open(std::string&)’
 out.open(strfile);

Thanks,


Danyang

On 18-06-01 10:07 AM, Danyang Su wrote:

Hi All,

My code needs to link to an external C++ library (CGAL). The code is
written in Fortran and I have already written interface to let Fortran
call C++ function. For the sequential version without PETSc, it can be
compiled without problem using the following makefile. The parallel
version without CGAL can also be compiled successfully. However, when I
tried to use PETSc together with CGAL library, I cannot compile the code.
My questions is: How can I modify the makefile? Do I need to reconfigure
PETSc with special flags? All the makefile samples are shown below.

#makefile for sequential version

FC = gfortran
#FC = ifort
CXX = g++ -std=c++11

DLIB = -lstdc++ -lm -L/usr/local/lib -rdynamic /usr/local/lib/libmpfr.so
/usr/local/lib/libgmp.so /usr/local/lib/libCGAL_ImageIO.so.11.0.1
/usr/local/lib/libCGAL.so.11.0.1 /usr/local/lib/libboost_thread.so
/usr/local/lib/libboost_system.so -lpthread -lGLU -lGL -lX11 -lXext -lz
/usr/local/lib/libCGAL_ImageIO.so.11.0.1 /usr/local/lib/libCGAL.so.11.0.1
/usr/local/lib/libboost_thread.so /usr/local/lib/libboost_system.so
-lpthread -lGLU -lGL -lX11 -lXext -lz /usr/local/lib/libmpfr.so
/usr/local/lib/libgmp.so /usr/local/lib/libboost_thread.so
/usr/local/lib/libboost_system.so -lpthread -Wl,-rpath,/usr/local/lib

FFLAGS = -O3
CXXFLAGS = -O3

FPPFLAGS =  -DUSECGAL

SRC =./../../

SOURCES = $(SRC)usg/math_common.o\