<div dir="ltr"><div class="gmail_default" style="font-family:courier new,monospace">Thank you for that fast and complete answer.</div><br> sáb, 17 de jan de 2015 21:21, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>> escreveu:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
As Dave points out the error is not detected because of a confluence of options you happen to be using; normally a MatMult() in the Krylov methods triggers an error but in your choices there is no MatMult(). The reason PCSetUp() and PCSetUp_BJacobi() cannot detect the problem is because they may not yet have available the vector that you pass into KSPSolve() hence cannot detect the size difference.<br>
<br>
I have added an error check in PCApply() to make sure the sizes of the objects passed in are correct; it is in the branch barry/fix-bjacobi-vector-<u></u>lengt<u></u>hs and next (I learned my lesson and did not stick it immediately into next and master :-(). I've also attached the patch file.<br>
<br>
Thanks<br>
<br>
Barry<br>
<br>
[0]PETSC ERROR: --------------------- Error Message ------------------------------<u></u><u></u>------------------------------<u></u><u></u>--<br>
[0]PETSC ERROR: Nonconforming object sizes<br>
[0]PETSC ERROR: Preconditioner number of local rows 20 does not equal resulting vector number of rows 30<br>
[0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html" target="_blank">http://www.mcs.anl.gov/petsc/<u></u>d<u></u>ocumentation/faq.html</a> for trouble shooting.<br>
[0]PETSC ERROR: Petsc Release Version 3.5.2, unknown<br>
[0]PETSC ERROR: ./ex1 on a arch-maint named Barrys-MacBook-Pro-3.local by barrysmith Sat Jan 17 17:15:12 2015<br>
[0]PETSC ERROR: Configure options --download-mpich --with-fc=0 --with-cxx=0 --download-sowing=0<br>
[0]PETSC ERROR: #1 PCApply() line 439 in /Users/barrysmith/Src/petsc/<u></u>sr<u></u>c/ksp/pc/interface/precon.c<br>
[0]PETSC ERROR: #2 KSP_PCApply() line 230 in /Users/barrysmith/Src/petsc/<u></u>in<u></u>clude/petsc-private/kspimpl.<u></u>h<br>
[0]PETSC ERROR: #3 KSPSolve_PREONLY() line 26 in /Users/barrysmith/Src/petsc/<u></u>sr<u></u>c/ksp/ksp/impls/preonly/<u></u>preonl<u></u>y.c<br>
[0]PETSC ERROR: #4 KSPSolve() line 460 in /Users/barrysmith/Src/petsc/<u></u>sr<u></u>c/ksp/ksp/interface/itfunc.c<br>
[0]PETSC ERROR: #5 main() line 59 in /Users/barrysmith/Src/petsc/<u></u>te<u></u>st-dir/ex1.c<br>
[0]PETSC ERROR: ----------------End of Error Message -------send entire error message to petsc-maint@mcs.anl.gov-------<u></u><u></u>---<br>
<br>
> On Jan 17, 2015, at 4:13 PM, Dave May <<a href="mailto:dave.mayhem23@gmail.com" target="_blank">dave.mayhem23@gmail.com</a>> wrote:<br>
><br>
> Many of the Mat-Vec operations will check that the local and global sizes of the matrix and vector are compatible, for example MatMult. If you changed your outer KSP type to anything other than PREONLY, an error about the mismatched sizes would get thrown.<br>
><br>
> It seems that none of the methods being called from within PCSetUp_BJACOBI perform such a check (which is a bit of a surprise). I cannot tell you exactly what the result of calling PCApply() with BJACOBI will be in the case when the local/global sizes of x,y are larger than the those for the operator. (I would guess that the "extra" entries might be ignored by PCApply_BJACOBI, but without going through the function in detail this really is a guess).<br>
><br>
> The call to PCApply() does not check that the local/global sizes of the input and output vectors are compatible with the sizes associated with the preconditioned operator. It seems neither does PCSetUp().<br>
><br>
> Shouldn't PCSetUp() perform such a check to detect this error early on and to not have the in-built assumption that a method called within PCSetUp_XXX() will in fact catch the error??<br>
><br>
><br>
> Cheers,<br>
> Dave<br>
><br>
><br>
><br>
> On 17 January 2015 at 22:42, Michael Souza <<a href="mailto:souza.michael@gmail.com" target="_blank">souza.michael@gmail.com</a>> wrote:<br>
> I'm not sure if this is a bug, but the PCJACOBI can be applied in a vector with size different from its operators.<br>
> In the code below, I define a PCJACOBI for a matrix A with size equal to 20 and I apply it in a 30 length vector x.<br>
><br>
> Is this just an unforeseen mistake (unexpected application)? If it isn't, what exactly does PCJACOBI do in this situation?<br>
><br>
> Cheers,<br>
> Michael<br>
><br>
> ------------------------------<u></u><u></u>------------------------------<u></u><u></u>-------------------------<br>
> int main(int argc, char **args){<br>
> PetscErrorCode ierr;<br>
> PC pc;<br>
> KSP ksp;<br>
> MPI_Comm comm;<br>
> Mat A;<br>
> PetscInt i, na=20, nx=30;<br>
> Vec x, y;<br>
><br>
> ierr = PetscInitialize(&argc, &args, (char *) 0, help); CHKERRQ(ierr);<br>
><br>
> // matrix creation and setup<br>
> ierr = MatCreate(PETSC_COMM_WORLD, &A); CHKERRQ(ierr);<br>
> ierr = MatSetType(A, MATMPIAIJ); CHKERRQ(ierr);<br>
> ierr = MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, na, na); CHKERRQ(ierr);<br>
> ierr = MatSetUp(A); CHKERRQ(ierr);<br>
> for (i = 0; i < na; i++) {<br>
> if(i > 0)<br>
> ierr = MatSetValue(A, i, (i - 1), 1.0, INSERT_VALUES); CHKERRQ(ierr);<br>
> if(i < (na-1))<br>
> ierr = MatSetValue(A, i, i+1, 1.0, INSERT_VALUES); CHKERRQ(ierr);<br>
> ierr = MatSetValue(A, i, i, -2.0, INSERT_VALUES); CHKERRQ(ierr);<br>
> }<br>
> ierr = MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);<br>
> ierr = MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);<br>
><br>
> // vector creation and setup<br>
> ierr = VecCreate(PETSC_COMM_WORLD, &x); CHKERRQ(ierr);<br>
> ierr = VecSetSizes(x,PETSC_DECIDE,nx)<u></u><u></u>;CHKERRQ(ierr);<br>
> ierr = VecSetFromOptions(x);CHKERRQ(<u></u>i<u></u>err);<br>
> ierr = VecSet(x,1.0);CHKERRQ(ierr);<br>
> ierr = VecDuplicate(x,&y);CHKERRQ(<u></u>ier<u></u>r);<br>
><br>
> // set KSP<br>
> ierr = PetscObjectGetComm((<u></u>PetscObjec<u></u>t) A, &comm); CHKERRQ(ierr);<br>
> ierr = KSPCreate(comm, &ksp); CHKERRQ(ierr);<br>
> ierr = KSPSetType(ksp, KSPPREONLY); CHKERRQ(ierr);<br>
> ierr = KSPSetOperators(ksp, A, A); CHKERRQ(ierr);<br>
> ierr = KSPGetPC(ksp, &pc); CHKERRQ(ierr);<br>
> ierr = PCSetType(pc, PCBJACOBI); CHKERRQ(ierr);<br>
> ierr = PCSetUp(pc); CHKERRQ(ierr);<br>
> { // setup the SubKSP<br>
> PetscInt nlocal, dummy;<br>
> KSP *subksp;<br>
> PC subpc;<br>
> ierr = PCBJacobiGetSubKSP(pc, &nlocal, &dummy, &subksp); CHKERRQ(ierr);<br>
> ierr = KSPSetType(*subksp, KSPPREONLY); CHKERRQ(ierr);<br>
> ierr = KSPGetPC(*subksp, &subpc); CHKERRQ(ierr);<br>
> ierr = PCSetType(subpc, PCILU); CHKERRQ(ierr);<br>
> ierr = PCFactorSetLevels(subpc, 1); CHKERRQ(ierr);<br>
> ierr = PCSetFromOptions(subpc); CHKERRQ(ierr);<br>
> ierr = PCSetUp(subpc); CHKERRQ(ierr);<br>
> }<br>
><br>
> // solve<br>
> ierr = VecView(x,PETSC_VIEWER_STDOUT_<u></u><u></u>WORLD);<br>
> ierr = KSPSolve(ksp,x,y); CHKERRQ(ierr);<br>
> ierr = VecView(y,PETSC_VIEWER_STDOUT_<u></u><u></u>WORLD); CHKERRQ(ierr);<br>
><br>
> // destroy objects<br>
> ierr = MatDestroy(&A); CHKERRQ(ierr);<br>
> ierr = VecDestroy(&x); CHKERRQ(ierr);<br>
> ierr = VecDestroy(&y); CHKERRQ(ierr);<br>
> ierr = KSPDestroy(&ksp); CHKERRQ(ierr);<br>
><br>
> return EXIT_SUCCESS;<br>
> }<br>
><br>
<br>
</blockquote></div></div>