Parallel graph coloring heuristics to color large-scale general jacobian matrices

Hong Zhang hzhang at mcs.anl.gov
Thu Sep 24 11:15:41 CDT 2009


Rafael,

> I've been working for some time on this piece of code for estimating
> large-scale and general jacobian matrices via finite differences whose
> sparsity patterns can be determined a priori. It basically uses a parallel
> graph coloring heuristic to find a good vertex coloring for the column
> intersection graph relative to the jacobian matrix at hand.

If you have sparsity patterns, then petsc can create coloring context
easily.
See ~petsc/src/snes/examples/tutorials/ex10d/ex10.c :
    } else { /* Use matfdcoloring */
      ISColoring    iscoloring;
      MatStructure  flag;
      /* Get the data structure of Jac */
      ierr = FormJacobian(snes,x,&Jac,&Jac,&flag,&user);CHKERRQ(ierr);
      /* Create coloring context */
      ierr = MatGetColoring(Jac,MATCOLORING_SL,&iscoloring);CHKERRQ(ierr);
      ierr = 
MatFDColoringCreate(Jac,iscoloring,&matfdcoloring);CHKERRQ(ierr);
      ierr = MatFDColoringSetFunction(matfdcoloring,(PetscErrorCode 
(*)(void))FormFunction,&user);CHKERRQ(ierr);
      ierr = MatFDColoringSetFromOptions(matfdcoloring);CHKERRQ(ierr);
      /* ierr = 
MatFDColoringView(matfdcoloring,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); 
*/
      ierr = 
SNESSetJacobian(snes,Jac,Jac,SNESDefaultComputeJacobianColor,matfdcoloring);CHKERRQ(ierr);
      ierr = ISColoringDestroy(iscoloring);CHKERRQ(ierr);
    }
in which, coloring context is created based on Jac sparse pattern.
See its makefile on how to run it.

Hong

>
> Now, I'd like to integrate that code into PETSc, but the problem is that I
> don't know exactly how. So after spending a lot of time sifting through and
> trying to grasp "the logic" of PETSc source code, especially, the source
> code to the MatFDColoring module, I came up with a "tacky" solution
> proposal: firstly, I would call my code in order to obtain the coloring in
> parallel, and then I would have a routine (which would have to be embedded
> in PETSc code base) that, on each processor, would build the "MatFDColoring"
> data structure based on two things, the coloring found and the sparsity
> pattern of the jacobian matrix in question.
>
> It seems to me that this might work out, though I'm not entirely sure. What
> do you guys think? Is there an easier and/or more "elegant" way to do this?
>
> Thanks in advance,
>
> Rafael
>


More information about the petsc-users mailing list