[petsc-users] petsc does not solve this [A][x] = [b] problem in parallel.....

Matthew Knepley knepley at gmail.com
Sat Mar 23 17:34:44 CDT 2013


On Sun, Mar 24, 2013 at 9:31 AM, Ravi Kannan <rxk at cfdrc.com> wrote:

> Dear All,****
>
> ** **
>
> This is Ravi Kannan from CFD Research Corporation.****
>
> ** **
>
> I am trying to solve this Ax=b problem in parallel and serial with no
> preconditioner. The A matrix is 3x3. The matrices are identical, as shown
> by the PETSCViewerAsciiFormat. ****
>
> ** **
>
> The serial one solves to nearly machine zero in one iteration. The
> parallel residual is much higher than zero. MORE IMPORTANTLY,  the ghost
> values are not updated after the Ksp solve!
>

1) Never ask about convergence without the output of -ksp_view -ksp_monitor

2) We do not update ghost values, you do

  Matt


>
>
> Here is the code snippet:****
>
> ** **
>
> ** **
>
> ** **
>
>     int PetSc::solving(std::vector<double>& sol)****
>
>     {****
>
>         #ifdef TIMING_STUDY_ON****
>
>         bool solver_timing_study=true;****
>
>         #else****
>
>         bool solver_timing_study=false;****
>
>         #endif****
>
>         PetscLogDouble startsolvingfunc, endsolvingfunc;****
>
>         _ierr = PetscGetTime(&startsolvingfunc);****
>
> ** **
>
> ** **
>
>         VecSetValues(_x,_size,&_id[0],&sol[0],INSERT_VALUES);****
>
>          PetscLogDouble start, end;****
>
>         _ierr = PetscGetTime(&start);****
>
>         _assemblySystem();****
>
>         _ierr = PetscGetTime(&end);****
>
> ** **
>
> ** **
>
>         if(_LSType != mf_base::DIRECT) KSPSetInitialGuessNonzero(_ksp,
> PETSC_TRU****
>
> E);****
>
> ** **
>
>         _ierr = KSPSetTolerances(_ksp,_resNob2,_abstol,1.e+30,_maxits);***
> *
>
> ** **
>
>         PetscLogDouble v1,v2;****
>
> ** **
>
>         _ierr = PetscGetTime(&v1);//CHKERRQ(_ierr);****
>
>         _ierr = KSPSolve(_ksp,_b,_x);//CHKERRQ(_ierr);****
>
>         _ierr = PetscGetTime(&v2);//CHKERRQ(_ierr);****
>
>         _elapsed_time = fabs(v2 - v1);****
>
> ** **
>
> ** **
>
>
> VecGhostUpdateBegin(_x,INSERT_VALUES,SCATTER_FORWARD);****
>
>
> VecGhostUpdateEnd(_x,INSERT_VALUES,SCATTER_FORWARD);****
>
> ** **
>
>         // z = A*x****
>
>         _ierr = MatMult(_A,_x,_z);****
>
> ** **
>
>         // z = z - b (which is Ax-b)****
>
>         _ierr = VecAXPY(_z,-1.0,_b);****
>
> ** **
>
>         _ierr = VecNorm(_z,NORM_2,&_norm);CHKERRQ(_ierr);****
>
>         _ierr = KSPGetIterationNumber(_ksp,&_iters);CHKERRQ(_ierr);****
>
> ** **
>
>         double flops;****
>
>         _ierr = PetscGetFlops(&flops); CHKERRQ(_ierr);****
>
> ** **
>
>         // SVM changes 04/02/07****
>
>         Vec lx;****
>
>         _ierr = VecGhostGetLocalForm(_x,&lx);****
>
>         PetscScalar *xx;****
>
>         //VecGetArray(Vec x,PetscScalar *a[]) :Remove this later****
>
>         VecGetArray(lx,&xx); // SVM changes 04/02/07****
>
>         for(int i=0;i<sol.size();++i){sol[i]=xx[i];}****
>
>         VecRestoreArray(lx,&xx); // SVM changes 04/02/07****
>
>         _ierr = VecGhostRestoreLocalForm(_x,&lx);****
>
> ** **
>
>        _ierr = MatZeroEntries(_A);****
>
> ** **
>
> ** **
>
>        _ierr = PetscGetTime(&endsolvingfunc);****
>
>        return 0;****
>
>    }****
>
> ** **
>
> Anything wrong with this?****
>
> ** **
>
> Thanks****
>
> Ravi****
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>



-- 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130324/2df03627/attachment-0001.html>


More information about the petsc-users mailing list