call KSPSolve(ksp,b,x,ierr)
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
! Check solution and clean up
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
! Check the error
call VecAXPY(x,neg_one,u,ierr)
^^^^^^^^^^^^^^^^^^^
x = x - 1.0* u; and hence changes x
On Jan 2, 2011, at 11:35 PM, Peter Wang wrote:
> Thanks, Barry,
> when you said,
> > x is computed in the code as the difference between the "exact" solution
> > and the "computed" solution.
> Does it mean x is not the solution?
>
> In the webpage document for KSPSolve, the x is defined as :
> Parameter
> ksp - iterative context obtained from KSPCreate()
> b - the right hand side vector
> x - the solution
>
> Why is x the difference in this example code? what is the solution,then?
>
>
> > From: bsmith at mcs.anl.gov
> > Date: Sun, 2 Jan 2011 22:55:00 -0600
> > To: petsc-users at mcs.anl.gov
> > Subject: Re: [petsc-users] result of ex2f.F in
> > petsc-3.1-p5\src\ksp\ksp\examples\tutorials
> >
> >
> > On Jan 2, 2011, at 9:32 PM, Peter Wang wrote:
> >
> > > I added VecView() in the ex2f.F to check the three vectors (u,b, and x)
> > > in the code.
> > >
> > > -----The vectors of u and b are same. BUt, the value of vector x is
> > > different with different processes. For example,
> > >
> > > with only 1 process, the vector x is:
> > >
> > > Process [0]
> > > 2.72322e-07
> > > 3.81437e-07
> > > 1.58922e-07
> > > 3.81437e-07
> > > 2.38878e-07
> > > -6.65645e-07
> > > 1.58922e-07
> > > -6.65645e-07
> > > -2.51219e-07
> > >
> > > with 2 processes, the vector is:
> > >
> > > Process [0]
> > > -1.11022e-16
> > > 0
> > > 2.22045e-16
> > > 2.22045e-16
> > > 0
> > >
> > > Process [1]
> > > 2.22045e-16
> > > 2.22045e-16
> > > 0
> > > 2.22045e-16
> > void PETSC_STDCALL kspbuildsolution_(KSP *ksp,Vec *v,Vec *V, int *ierr )
> > {
> > Vec vp = 0;
> > CHKFORTRANNULLOBJECT(v);
> > CHKFORTRANNULLOBJECT(V);
> > if (v) vp = *v;
> > *ierr = KSPBuildSolution(*ksp,vp,V);
> > }
> >
> > void PETSC_STDCALL kspbuildresidual_(KSP *ksp,Vec *t,Vec *v,Vec *V, int
> > *ierr )
> > {
> > Vec tp = 0,vp = 0;
> > CHKFORTRANNULLOBJECT(t);
> > CHKFORTRANNULLOBJECT(v);
> > CHKFORTRANNULLOBJECT(V);
> > if (t) tp = *t;
> > if (v) vp = *v;
> > *ierr = KSPBuildResidual(*ksp,tp,vp,V);
> > }
> >
> > Barry
> >
> > x is computed in the code as the difference between the "exact" solution
> > and the "computed" solution. Since this example uses iterative solvers,
> > which by default do not compute the solution to full accuracy, the "error"
> > will be different for different number of processes. It is just a fluke
> > that the error is smaller with two processes instead of one.
> >
> > >
> > > The example is supposed to get a vector x similar to u. Why the result is
> > > different with differnt number of processes used?
> > >
> > > ----Also, if the runtime option -my_ksp_monitor is used, there is a error
> > > showing:
> > >
> > > [0]PETSC ERROR:
> > > ------------------------------------------------------------------------
> > > [0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation,
> > > probably memory access out of range
> > >
> > > It seems there is something wrong with calling 'call
> > > KSPBuildSolution(ksp,PETSC_NULL_OBJECT,x,ierr)' in user defined function
> > > MyKSPMonitor().
> > >
> > > Any hints for this error? Thanks a lots.
> >
> > Bug in our Fortran Interface for KSPBuildSolution() fortran interface in
> > that case. If you replace the two functions in
> > src/ksp/ksp/interface/ftn-custom/zitclf.c with the ones below and run make
> > in that directory this monitor routine will work.
> >
> >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >