This may help in this situation. http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatResetPreallocation.html
Fande, On Thu, Jun 14, 2018 at 1:08 PM, Smith, Barry F. <[email protected]> wrote: > > I am guessing your matrix has an "envelope" of nonzero values but the > first time you fill the matrix you do not fill up the entire envelope? > Hence internally within the matrix we squeeze out those nonexistent > locations so next time you fill the matrix the new location you need is not > available. > > There is really only one way to deal with this. Initially build the > entire envelope of values (putting zeros in certain locations is fine they > won't get squuzed out) then for future calls the locations are already > there and so you will have no problems with new nonzero. > > On the other hand if the envelope is much much larger than any > particular set of nonzero locations then it is better to create a new > matrix each time because all the solves with the first approach treats all > the matrix entries in the envelope as nonzero (even if they happen to be > zero). > > Barry > > > > On Jun 14, 2018, at 1:17 PM, Qicang Shen <[email protected]> wrote: > > > > Hi Guys, > > > > I'm now confronting a problem. > > > > I'm using PETSC to construct a SPARSE Matrix. And I'm sure that the > matrix has been allocated correctly using MatMPIAIJSetPreallocation with > the upper limit of the size. > > > > The code works well when I just solve the system once. > > > > However, after the system been solved. And I want to use the original > non-zero structure, but change the elements inside the matrix. The petsc > will show the error message as: > > > > [14]PETSC ERROR: Argument out of range > > [14]PETSC ERROR: New nonzero at (58,56) caused a malloc > > Use MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE) to > turn off this check > > > > My current the solution is destroy the system and reallocate with the > same size. But I believe there should be more efficient way, i.e. just use > the original structure. > > > > I would like search for help to confirm that whether PETSC will > compress/delete the zero entries during the > MatAssemblyBegin/MatAssemblyEnd/KSPSolve, > or other possible places. > > > > And how to avoid deleting zero elements during the process? > > > > Thanks very much. > > > > > > > > > > Qicang SHEN > > PhD Candidate > > Nuclear Engineering and Radiological Sciences, University of Michigan, > Ann Arbor > > Email: [email protected] > >
