Date: 2016-07-24T16:58:39+00:00

Actual source code: natural.c
petsc-3.7.3 2016-07-24
Report Typos and Errors

      1: #include <petsc/private/matimpl.h>      /*I "petscmat.h"  I*/
      2: #include <petsc/private/isimpl.h>

      6: static PetscErrorCode MatColoringApply_Natural(MatColoring mc,ISColoring *iscoloring)
      7: {
      8:   PetscErrorCode  ierr;
      9:   PetscInt        start,end,i,bs = 1,n;
     10:   ISColoringValue *colors;
     11:   MPI_Comm        comm;
     12:   PetscBool       flg1,flg2;
     13:   Mat             mat     = mc->mat;
     14:   Mat             mat_seq = mc->mat;
     15:   PetscMPIInt     size;
     16:   ISColoring      iscoloring_seq;
     17:   ISColoringValue *colors_loc;
     18:   PetscInt        rstart,rend,N_loc,nc;

     21:   /* this is ugly way to get blocksize but cannot call MatGetBlockSize() because AIJ can have bs > 1 */
     22:   PetscObjectTypeCompare((PetscObject)mat,MATSEQBAIJ,&flg1);
     23:   PetscObjectTypeCompare((PetscObject)mat,MATMPIBAIJ,&flg2);
     24:   if (flg1 || flg2) {
     25:     MatGetBlockSize(mat,&bs);
     26:   }

     28:   PetscObjectGetComm((PetscObject)mat,&comm);
     29:   MPI_Comm_size(comm,&size);
     30:   if (size > 1) {
     31:     /* create a sequential iscoloring on all processors */
     32:     MatGetSeqNonzeroStructure(mat,&mat_seq);
     33:   }

     35:   MatGetSize(mat_seq,&n,NULL);
     36:   MatGetOwnershipRange(mat_seq,&start,&end);
     37:   n    = n/bs;
     38:   if (n > IS_COLORING_MAX-1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Maximum color size exceeded");

     40:   start = start/bs;
     41:   end   = end/bs;
     42:   PetscMalloc1(end-start+1,&colors);
     43:   for (i=start; i<end; i++) {
     44:     colors[i-start] = (ISColoringValue)i;
     45:   }
     46:   ISColoringCreate(comm,n,end-start,colors,PETSC_OWN_POINTER,iscoloring);

     48:   if (size > 1) {
     49:     MatDestroySeqNonzeroStructure(&mat_seq);

     51:     /* convert iscoloring_seq to a parallel iscoloring */
     52:     iscoloring_seq = *iscoloring;
     53:     rstart         = mat->rmap->rstart/bs;
     54:     rend           = mat->rmap->rend/bs;
     55:     N_loc          = rend - rstart; /* number of local nodes */

     57:     /* get local colors for each local node */
     58:     PetscMalloc1(N_loc+1,&colors_loc);
     59:     for (i=rstart; i<rend; i++) {
     60:       colors_loc[i-rstart] = iscoloring_seq->colors[i];
     61:     }
     62:     /* create a parallel iscoloring */
     63:     nc   = iscoloring_seq->n;
     64:     ISColoringCreate(comm,nc,N_loc,colors_loc,PETSC_OWN_POINTER,iscoloring);
     65:     ISColoringDestroy(&iscoloring_seq);
     66:   }
     67:   return(0);
     68: }

     72: PETSC_EXTERN PetscErrorCode MatColoringCreate_Natural(MatColoring mc)
     73: {
     75:     mc->data                = NULL;
     76:     mc->ops->apply          = MatColoringApply_Natural;
     77:     mc->ops->view           = NULL;
     78:     mc->ops->destroy        = NULL;
     79:     mc->ops->setfromoptions = NULL;
     80:     return(0);
     81: }