[petsc-users] Is it possible to free extra memory after matassemble?
Gong Ding
gdiso at ustc.edu
Fri Feb 18 08:31:29 CST 2011
Thank Barry, but at the moment I only want to loop cells once.
The "loop" operation is very time consuming because I use AD to build the Jacobian matrix and there are millons of cells.
Anyway, I'd like to allocate enough memory and free extra memory before solving the matrix (usually by direct solver such as MUMPS).
> Hi,
> After update my FVM code to support higher order, I have to preallocate more memory when creating the matrix. However, only a few cells (determined at run time) needed to be high order, thus preallocated memory is overkill too much.
You should preallocate ONLY the space you need so that only the space you need is ever allocated. In Unix/Windows there is no good way to recover memory. Why is the preallocated memory too much?
The way to do this is each time the matrix nonzero structure will change. (1) loop over you cells determining what needs to be "high order" and determine the number of nonzeros for each row, the (2) preallocate the matrix, then (3) loop over cells again building the actual sparse matrix entries and putting them in. If the matrix nonzero structure changes each time step then just delete the old matrix and generate a new one each time, creating a new matrix with the proper preallocation is not an expensive operation.
Yes it may seem inefficient to loop over the cells twice but you will find that it actually works very well, saves tons of memory and is much much faster than not preallocating.
Barry
>
> Is it possible to add a function to reassemble the AIJ matrix to free the extra memory?
> Or it has already done when MatAssembly is called?
>
>
More information about the petsc-users
mailing list