Anthony,

    Keeping the nonzero locations (with zero in them) will be a bit faster in 
the call to MatZeroRows() because otherwise it has to shift all the entries in 
the sparse matrix arrays data structures to "remove" the unneeded locations. 
 
    But the real question is how it affects times in later function calls

1)  If you do the MatSetValues()/MatAssemblyBegin/End() repeatedly it will be 
much faster if you keep the nonzero locations (with zero in them). 

2)  Time for MatMult() will be a bit faster if you remove the locations, but 
the depending on the preconditioner the preconditioner may be more or less 
effective and a bit slower or faster. 

  So, rule of thumb is if you only do MatZeroRows() once you might generally 
remove the locations but if it is done in a loop with the same matrix (over 
time-steps for example, or even in SNES) you want to keep the nonzero locations.

  Barry

Note: in both cases the memory usage is the same because PETSc does not 
"return" the excessive memory.


> On Aug 13, 2020, at 8:07 AM, Matthew Knepley <[email protected]> wrote:
> 
> On Thu, Aug 13, 2020 at 3:17 AM Anthony Paul Haas <[email protected] 
> <mailto:[email protected]>> wrote:
> Hello,
> 
> I am using MatZeroRows for imposing a known forcing into my equations in 
> conjunction with rhs and by setting the diagonal of the matrix to 1.
> 
> I am using Fortran. I have used:
> 
> ! only local processors set their own zeros                                   
>                                                                               
>                                     
> call MatSetOption(self%fieldLHSMat_ps, MAT_NO_OFF_PROC_ZERO_ROWS, PETSC_TRUE, 
> ierr)
> 
> call MatSetOption(self%fieldLHSMat_ps, MAT_KEEP_NONZERO_PATTERN, PETSC_TRUE, 
> ierr)
> 
> call MatZeroRows(self%fieldLHSMat_ps, numrows, glob_row_idx, diag, 
> PETSC_NULL_OBJECT, PETSC_NULL_OBJECT, ierr)
> 
> 
> Is numrows above the local (on each proc.) number of rows to remove, or is it 
> the global number of rows to remove?
> 
> Local.
>  
> Also on some processors, I have no rows to remove, hence the array 
> glob_row_idx is not allocated. How can I tell Petsc? Should I pass 
> PETSC_NULL_OBJECT instead of glob_row_idx in this case?   
> 
> If you pass numrows = 0, it should not matter what is in the next slot, as 
> long as it type checks.
>  
> Finally, does using the option MAT_KEEP_NONZERO_PATTERN have an influence on 
> the time the MatZeroRows call will take?
> 
> I don't think it makes much of a difference, but I have not measured it.
> 
>   Thanks,
> 
>      Matt
>  
> Thanks,
> 
> Best regards,
> 
> Anthony
> 
> 
> 
> 
> 
> -- 
> What most experimenters take for granted before they begin their experiments 
> is infinitely more interesting than any results to which their experiments 
> lead.
> -- Norbert Wiener
> 
> https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>

Reply via email to