<div dir="ltr">Thanks. <div><br></div><div>When I put the type back to mpiaij, my code runs fine without segfaults with GAMG. It doesn't work very well yet, but that is a separate issue. </div><div><br></div><div>Gaetan</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 12, 2016 at 11:03 AM, Mark Adams <span dir="ltr"><<a href="mailto:mfadams@lbl.gov" target="_blank">mfadams@lbl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Yes, we should check the type.<br><br>#define MATAIJ "aij"<br>#define MATSEQAIJ "seqaij"<br>#define MATMPIAIJ "mpiaij"<br><br>I assume that MATAIJ is mapped to SEQ or MPI, and so just need to check for the latter two. I'll do that now.<br><br>Thanks,<br>Mark</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 12, 2016 at 7:02 AM, Lawrence Mitchell <span dir="ltr"><<a href="mailto:lawrence.mitchell@imperial.ac.uk" target="_blank">lawrence.mitchell@imperial.<wbr>ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">[Added petsc-maint to cc, since I think this is an actual bug]<br>
<br>
> On 12 Aug 2016, at 01:16, Gaetan Kenway <<a href="mailto:gaetank@gmail.com" target="_blank">gaetank@gmail.com</a>> wrote:<br>
><br>
> Hi<br>
><br>
> I'm attempting to try out using GAMG for a preconditioner for my compressible CFD problem. However, I'm getting segfaults when trying to run the code. The code is based on ksp ex23.c which is attached. It just reads in two precomputed matrices (the actual jacobian and an approximate jacobian used to build the PC) and solves with a RHS of ones.<br>
><br>
> My normal approach to solving the system is with ASM+ILU. With the following options, everything works fine.<br>
<br>
This appears to be a problem that GAMG doesn't work with BAIJ matrices.<br>
<br>
But there is no checking of the input matrix type anywhere.<br>
<br>
For example, with a debug PETSc:<br>
<br>
cd src/ksp/ksp/examples/tutorials<br>
make ex23<br>
./ex23 -pc_type gamg -mat_type baij<br>
<br>
[0]PETSC ERROR: --------------------- Error Message ------------------------------<wbr>------------------------------<wbr>--<br>
[0]PETSC ERROR: Object is in wrong state<br>
[0]PETSC ERROR: Must call MatXXXSetPreallocation() or MatSetUp() on argument 1 "mat" before MatSetValues()<br>
[0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html" rel="noreferrer" target="_blank">http://www.mcs.anl.gov/petsc/d<wbr>ocumentation/faq.html</a> for trouble shooting.<br>
[0]PETSC ERROR: Petsc Development GIT revision: v3.7.3-1123-g21143a8 GIT Date: 2016-08-08 17:24:17 -0700<br>
[0]PETSC ERROR: ./ex23 on a arch-darwin-c-dbg named yam-laptop.local by lmitche1 Fri Aug 12 11:51:17 2016<br>
[0]PETSC ERROR: Configure options --download-chaco=1 --download-ctetgen=1 --download-exodusii=1 --download-hdf5=1 --download-hypre=1 --download-metis=1 --download-ml=1 --download-mumps=1 --download-netcdf=1 --download-parmetis=1 --download-ptscotch=1 --download-scalapack=1 --download-triangle=1 --with-c2html=0 --with-debugging=1 --with-shared-libraries=1 PETSC_ARCH=arch-darwin-c-dbg<br>
[0]PETSC ERROR: #1 MatSetValues() line 1195 in /Users/lmitche1/Documents/work<wbr>/src/deps/petsc/src/mat/interf<wbr>ace/matrix.c<br>
[0]PETSC ERROR: #2 PCGAMGFilterGraph() line 342 in /Users/lmitche1/Documents/work<wbr>/src/deps/petsc/src/ksp/pc/<wbr>impls/gamg/util.c<br>
[0]PETSC ERROR: #3 PCGAMGGraph_AGG() line 908 in /Users/lmitche1/Documents/work<wbr>/src/deps/petsc/src/ksp/pc/<wbr>impls/gamg/agg.c<br>
[0]PETSC ERROR: #4 PCSetUp_GAMG() line 525 in /Users/lmitche1/Documents/work<wbr>/src/deps/petsc/src/ksp/pc/<wbr>impls/gamg/gamg.c<br>
[0]PETSC ERROR: #5 PCSetUp() line 968 in /Users/lmitche1/Documents/work<wbr>/src/deps/petsc/src/ksp/pc/<wbr>interface/precon.c<br>
[0]PETSC ERROR: #6 KSPSetUp() line 393 in /Users/lmitche1/Documents/work<wbr>/src/deps/petsc/src/ksp/ksp/<wbr>interface/itfunc.c<br>
[0]PETSC ERROR: #7 KSPSolve() line 602 in /Users/lmitche1/Documents/work<wbr>/src/deps/petsc/src/ksp/ksp/<wbr>interface/itfunc.c<br>
[0]PETSC ERROR: #8 main() line 158 in /Users/lmitche1/Documents/work<wbr>/src/deps/petsc/src/ksp/ksp/<wbr>examples/tutorials/ex23.c<br>
[0]PETSC ERROR: PETSc Option Table entries:<br>
[0]PETSC ERROR: -mat_type baij<br>
[0]PETSC ERROR: -pc_type gamg<br>
[0]PETSC ERROR: ----------------End of Error Message -------send entire error message to petsc-maint@mcs.anl.gov-------<wbr>---<br>
<br>
Looking in PCGAMGFilterGraph I see:<br>
<br>
ierr = MatGetType(Gmat,&mtype);CHKERR<wbr>Q(ierr);<br>
ierr = MatCreate(comm, &tGmat);CHKERRQ(ierr);<br>
ierr = MatSetSizes(tGmat,nloc,nloc,MM<wbr>,MM);CHKERRQ(ierr);<br>
ierr = MatSetBlockSizes(tGmat, 1, 1);CHKERRQ(ierr);<br>
ierr = MatSetType(tGmat, mtype);CHKERRQ(ierr);<br>
ierr = MatSeqAIJSetPreallocation(tGma<wbr>t,0,d_nnz);CHKERRQ(ierr);<br>
ierr = MatMPIAIJSetPreallocation(tGma<wbr>t,0,d_nnz,0,o_nnz);CHKERRQ(<wbr>ierr);<br>
<br>
<br>
...<br>
ierr = MatSetValues(tGmat,1,&Ii,1,&id<wbr>x[jj],&sv,ADD_VALUES);CHKERRQ(<wbr>ierr);<br>
<br>
<br>
So if Gmat is neither SEQAIJ nor MPIAIJ, then no preallocation has happened (and MatSetUp is not called).<br>
<br>
Fixing the few instances here by just changing the type of these matrices to AIJ. One runs into to the problem that creating the coarse grid operators doesn't work, since MatMatMult and friends do not exist for BAIJ matrices.<br>
<br>
I guess GAMG could MatConvert from BAIJ to AIJ (but this uses extra memory).<br>
<br>
But it should probably barf with a comprehensible error message.<br>
<br>
Thoughts?<br>
<span><font color="#888888"><br>
Lawrence<br>
<br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div>