[petsc-users] Problems about fd_coloring
Smith, Barry F.
bsmith at mcs.anl.gov
Fri Apr 26 10:02:18 CDT 2019
> On Apr 26, 2019, at 7:24 AM, Yingjie Wu via petsc-users <petsc-users at mcs.anl.gov> wrote:
> Dear PETSc developers:
> I want to try some of the operations of matrix coloring. I have written a model of a system of non-linear equations and solved it using - snes_fd, so there is no Compute_Jacobian routine. Previous developers suggested that I use:
> -snes_fd_color -snes_fd_color_use_mat -mat_coloring_type greendy
> to improve computational efficiency. I know little about coloring. It seems to be a way to store the matrix structure, so that when the finite difference routine is used, the difference can be calculated only at the position of non-zero elements of Jacobian matrix, avoiding the difference calculation of "0" elements. I don't know if I understand this correctly.
This is close enough understanding.
> My program is a two-dimensional problem, but it does not use the DM object to allocate the solution vector X. Is there any problem with fd_coloring?
In order to use coloring you MUST provide the Jacobian matrix with its correct nonzero structure (you don't need to provide the numerical values). The fd coloring code then uses the nonzero structure and the SNES function you provide to compute the Jacobian efficiently.
Depending on your discretization it is either trivial or somewhat straight forward to provide the Jacobian nonzero structure. For example for finite differences on a 2d grid you can figure out which entires in the matrix are nonzero based on the finite difference stencil. For finite elements it is slightly more involved but essentially for each row of the matrix there are nonzero entries for all columns that that are connected by the finite element discretization (that is if you were to compute the Jacobian explicitly and get a nonzero value then you get one a nonzero location in the matrix).
Now in parallel one must be careful and insure you handle the nonzero structure correctly for vertices that are not on the same processor.
> For users like me who don't know coloring, how should I get some usage methods? It seems that the instructions on manual are somewhat brief.
> In addition, because Matrix Free needs an efficient Preconditioner and because some complex parameter variables make it impossible for me to analytically construct Jacobian matrices, the finite difference approximation of Jacobian matrices may be the most appropriate method at present.The reason I want to know about fd_coloring is to improve computational efficiency.
> I hope to get your advice.
More information about the petsc-users