<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div>  You need to set the type before calling the preallocation routines. Otherwise when you set to a new type all the previous information is essentially removed when the new type is created. <div class=""><br class=""></div><div class="">  Barry</div><div class=""><br class=""></div><div class="">A slightly more clever MatCreate_MPIAIJCUSPARSE() could check if the matrix was already of the type MPIAIJ and reuse that information but currently it does not do that check.</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jun 8, 2021, at 11:11 PM, Mark Adams <<a href="mailto:mfadams@lbl.gov" class="">mfadams@lbl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I have an old code that fails with -mat_type aijcusparse<div class="">This is the code that creates the matrix:<br class=""></div><div class=""><br class=""></div><div class="">      ierr = PetscPrintf(PETSC_COMM_SELF,"\nPetscSolve.H MatCreate adding csr \n");CHKERRQ(ierr);<br class="">      ierr = MatCreate(wcomm,&m_mat);CHKERRQ(ierr);<br class="">      ierr = MatSetOptionsPrefix(m_mat,"csr_");CHKERRQ(ierr);   // prefix is new but does not matter<br class="">      ierr = MatSetSizes(m_mat,NN,NN,PETSC_DECIDE,PETSC_DECIDE);CHKERRQ(ierr);<br class="">      ierr = MatSetBlockSize(m_mat,nc);CHKERRQ(ierr);<br class="">      ierr = MatSetType(m_mat,MATAIJ);CHKERRQ(ierr);<br class="">      ierr = MatSeqAIJSetPreallocation(m_mat,nnzrow, d_nnz);CHKERRQ(ierr);<br class="">      ierr = MatMPIAIJSetPreallocation(m_mat,nnzrow, d_nnz, nnzrow/2, o_nnz);CHKERRQ(ierr);<br class="">      ierr = MatSetOption(m_mat,MAT_NEW_NONZERO_ALLOCATION_ERR,PETSC_FALSE) ;CHKERRQ(ierr);<br class="">      ierr = MatSetFromOptions( m_mat ); CHKERRQ(ierr);</div><div class=""><br class=""></div><div class=""><div class="">With -csr_mat_type aijcusprase I get this output.</div><div class="">Note, this apparent recursive structure in the call stack. I have no idea where that is coming from. I can't see that from the code.</div><div class=""><br class=""></div><div class="">Any ideas?</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Mark</div><div class=""></div></div><div class=""><br class=""></div><div class="">PetscSolve.H MatCreate .H adding csr<br class="">[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br class="">[0]PETSC ERROR: Object is in wrong state<br class="">[0]PETSC ERROR: Must call MatXXXSetPreallocation(), MatSetUp() or the matrix has not yet been factored on argument 1 "mat" before MatSetValues()<br class="">[0]PETSC ERROR: See <a href="https://www.mcs.anl.gov/petsc/documentation/faq.html" class="">https://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.<br class="">[0]PETSC ERROR: Petsc Development GIT revision: v3.15.0-734-gc2c1a54  GIT Date: 2021-06-07 02:44:02 +0000<br class="">[0]PETSC ERROR: ../viscousDriver3d.Linux.64.mpiCC.mpifort.OPT.MPI.PETSC.ex on a arch-summit-dbg-gnu-cuda named a15n03 by adams Tue Jun  8 23:39:49 2021<br class="">[0]PETSC ERROR: Configure options --with-fc=mpifort --with-cc=mpicc --with-cxx=mpiCC --CFLAGS="-fPIC -g              -mcpu=native -Wno-unused-but-set-variable -Wno-long-long -Wno-sign-compare -Wno-deprecated -Wno-unused-local-typedefs -Wno-variadic-macros -Wno-unknown-pragmas" --CXXFLAGS="-fPIC -g -std=c++11 -mcpu=native -Wno-unused-but-set-variable -Wno-long-long -Wno-sign-compare -Wno-deprecated -ftemplate-depth-99 -Wno-unused-local-typedefs -Wno-literal-suffix -Wno-invalid-offsetof -Wno-variadic-macros -Wno-unknown-pragmas" --CUDAFLAGS="-g -Xcompiler -lineinfo" --FCFLAGS="-fPIC -g" --FCOPTFLAGS=-O0 --COPTFLAGS=-O0 --CXXOPTFLAGS=-O0 --with-ssl=0 --with-batch=0 --with-mpiexec="jsrun -g1" --with-cuda=1 --with-cudac=nvcc --with-cuda-gencodearch=70 --download-metis --download-parmetis --with-blaslapack-lib="-L/autofs/nccs-svm1_sw/summit/.swci/1-compute/opt/spack/20180914/linux-rhel7-ppc64le/gcc-6.4.0/netlib-lapack-3.8.0-wcabdyqhdi5rooxbkqa6x5d7hxyxwdkm/lib64 -lblas -llapack" --with-x=0 --with-64-bit-indices=0 --with-debugging=1 PETSC_ARCH=arch-summit-dbg-gnu-cuda --force<br class="">[0]PETSC ERROR: #1 MatSetValues() at /gpfs/alpine/csc314/scratch/adams/petsc/src/mat/interface/matrix.c:1366<br class="">[0]PETSC ERROR: #2 formMatrix() at ../srcLib/EBPetscLinearSolverPoisson.cpp:126<br class="">[0]PETSC ERROR: #3 setup_solver() at ../../../Chombo/lib/src/AMRElliptic/PetscSolverI.H:283<br class="">[0]PETSC ERROR: #4 solve_private() at ../../../Chombo/lib/src/AMRElliptic/PetscSolverI.H:427<br class="">[0]PETSC ERROR: #5 KSPSolve() at /gpfs/alpine/csc314/scratch/adams/petsc/src/ksp/ksp/interface/itfunc.c:1080<br class="">[0]PETSC ERROR: #6 solve_private() at ../../../Chombo/lib/src/AMRElliptic/PetscSolverI.H:508<br class="">[0]PETSC ERROR: #7 KSPSolve() at /gpfs/alpine/csc314/scratch/adams/petsc/src/ksp/ksp/interface/itfunc.c:1080<br class="">[0]PETSC ERROR: #8 solve_private() at ../../../Chombo/lib/src/AMRElliptic/PetscSolverI.H:508<br class="">[0]PETSC ERROR: #9 KSPSolve() at /gpfs/alpine/csc314/scratch/adams/petsc/src/ksp/ksp/interface/itfunc.c:1080<br class="">[0]PETSC ERROR: #10 solve_private() at ../../../Chombo/lib/src/AMRElliptic/PetscSolverI.H:508<br class="">[0]PETSC ERROR: #11 KSPSolve() at /gpfs/alpine/csc314/scratch/adams/petsc/src/ksp/ksp/interface/itfunc.c:1080<br class="">[0]PETSC ERROR: #12 solve_private() at ../../../Chombo/lib/src/AMRElliptic/PetscSolverI.H:508<br class="">      <br class=""></div><div class=""><br class=""></div></div>
</div></blockquote></div><br class=""></div></body></html>