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.
Barry 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. > On Jun 8, 2021, at 11:11 PM, Mark Adams <mfad...@lbl.gov> wrote: > > I have an old code that fails with -mat_type aijcusparse > This is the code that creates the matrix: > > ierr = PetscPrintf(PETSC_COMM_SELF,"\nPetscSolve.H MatCreate adding csr > \n");CHKERRQ(ierr); > ierr = MatCreate(wcomm,&m_mat);CHKERRQ(ierr); > ierr = MatSetOptionsPrefix(m_mat,"csr_");CHKERRQ(ierr); // prefix is > new but does not matter > ierr = MatSetSizes(m_mat,NN,NN,PETSC_DECIDE,PETSC_DECIDE);CHKERRQ(ierr); > ierr = MatSetBlockSize(m_mat,nc);CHKERRQ(ierr); > ierr = MatSetType(m_mat,MATAIJ);CHKERRQ(ierr); > ierr = MatSeqAIJSetPreallocation(m_mat,nnzrow, d_nnz);CHKERRQ(ierr); > ierr = MatMPIAIJSetPreallocation(m_mat,nnzrow, d_nnz, nnzrow/2, > o_nnz);CHKERRQ(ierr); > ierr = MatSetOption(m_mat,MAT_NEW_NONZERO_ALLOCATION_ERR,PETSC_FALSE) > ;CHKERRQ(ierr); > ierr = MatSetFromOptions( m_mat ); CHKERRQ(ierr); > > With -csr_mat_type aijcusprase I get this output. > 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. > > Any ideas? > > Thanks, > Mark > > PetscSolve.H MatCreate .H adding csr > [0]PETSC ERROR: --------------------- Error Message > -------------------------------------------------------------- > [0]PETSC ERROR: Object is in wrong state > [0]PETSC ERROR: Must call MatXXXSetPreallocation(), MatSetUp() or the matrix > has not yet been factored on argument 1 "mat" before MatSetValues() > [0]PETSC ERROR: See https://www.mcs.anl.gov/petsc/documentation/faq.html > <https://www.mcs.anl.gov/petsc/documentation/faq.html> for trouble shooting. > [0]PETSC ERROR: Petsc Development GIT revision: v3.15.0-734-gc2c1a54 GIT > Date: 2021-06-07 02:44:02 +0000 > [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 > [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 > [0]PETSC ERROR: #1 MatSetValues() at > /gpfs/alpine/csc314/scratch/adams/petsc/src/mat/interface/matrix.c:1366 > [0]PETSC ERROR: #2 formMatrix() at > ../srcLib/EBPetscLinearSolverPoisson.cpp:126 > [0]PETSC ERROR: #3 setup_solver() at > ../../../Chombo/lib/src/AMRElliptic/PetscSolverI.H:283 > [0]PETSC ERROR: #4 solve_private() at > ../../../Chombo/lib/src/AMRElliptic/PetscSolverI.H:427 > [0]PETSC ERROR: #5 KSPSolve() at > /gpfs/alpine/csc314/scratch/adams/petsc/src/ksp/ksp/interface/itfunc.c:1080 > [0]PETSC ERROR: #6 solve_private() at > ../../../Chombo/lib/src/AMRElliptic/PetscSolverI.H:508 > [0]PETSC ERROR: #7 KSPSolve() at > /gpfs/alpine/csc314/scratch/adams/petsc/src/ksp/ksp/interface/itfunc.c:1080 > [0]PETSC ERROR: #8 solve_private() at > ../../../Chombo/lib/src/AMRElliptic/PetscSolverI.H:508 > [0]PETSC ERROR: #9 KSPSolve() at > /gpfs/alpine/csc314/scratch/adams/petsc/src/ksp/ksp/interface/itfunc.c:1080 > [0]PETSC ERROR: #10 solve_private() at > ../../../Chombo/lib/src/AMRElliptic/PetscSolverI.H:508 > [0]PETSC ERROR: #11 KSPSolve() at > /gpfs/alpine/csc314/scratch/adams/petsc/src/ksp/ksp/interface/itfunc.c:1080 > [0]PETSC ERROR: #12 solve_private() at > ../../../Chombo/lib/src/AMRElliptic/PetscSolverI.H:508 > >