Commits

Hong Zhang committed 95a72cc

rename options for RARt algorithm using EList {"matmatmatmult","matmattransposemult","coloring_rart"};

  • Participants
  • Parent commits 3b1b962

Comments (0)

Files changed (1)

File src/mat/impls/aij/seq/matrart.c

 PetscErrorCode MatRARt_SeqAIJ_SeqAIJ(Mat A,Mat R,MatReuse scall,PetscReal fill,Mat *C)
 {
   PetscErrorCode ierr;
-  PetscBool      usecoloring = PETSC_FALSE,color_art;
+  const char     *algTypes[3] = {"matmatmatmult","matmattransposemult","coloring_rart"};
+  PetscInt       alg=0; /* set default algorithm */
+  Mat_SeqAIJ     *c;
+  Mat_RARt       *rart;
 
   PetscFunctionBegin;
-  ierr = PetscOptionsGetBool(NULL,"-matrart_color",&usecoloring,NULL);CHKERRQ(ierr);
-
-  if (!usecoloring) { /* Rt=R^T, C=R*A*Rt - avoid inefficient sparse inner products */
-    Mat           Rt;
-    Mat_SeqAIJ    *c;
-    Mat_RARt      *rart;
-    
-    if (scall == MAT_INITIAL_MATRIX) {
-      ierr = MatTranspose(R,MAT_INITIAL_MATRIX,&Rt);CHKERRQ(ierr); 
-      ierr = MatMatMatMult(R,A,Rt,scall,fill,C);CHKERRQ(ierr);
-
-      ierr = PetscNew(Mat_RARt,&rart);CHKERRQ(ierr);
-      rart->Rt = Rt;
-      c        = (Mat_SeqAIJ*)(*C)->data;
-      c->rart  = rart;
-      rart->destroy      = (*C)->ops->destroy;
-      (*C)->ops->destroy = MatDestroy_SeqAIJ_RARt;
-    } else {
-      c  = (Mat_SeqAIJ*)(*C)->data;
-      rart = c->rart;
-      Rt   = rart->Rt;
-      ierr = MatTranspose(R,MAT_REUSE_MATRIX,&Rt);CHKERRQ(ierr); 
-      ierr = MatMatMatMult(R,A,Rt,scall,fill,C);CHKERRQ(ierr);
-    }
-    PetscFunctionReturn(0);
-  }
-
-  /* use coloring */
-  /*--------------*/
-  ierr = PetscOptionsGetBool(NULL,"-matrart_color_art",&color_art,NULL);CHKERRQ(ierr); 
-  if (color_art) { /* apply coloring to A*R^T, not C = R*A*R^T */
+  ierr = PetscOptionsEList("-matrart_via","Algorithm of MatRARt","",algTypes,3,algTypes[0],&alg,PETSC_NULL);CHKERRQ(ierr);
+  switch (alg) {
+  case 1:
+    /* via matmattransposemult: ARt=A*R^T, C=R*ARt - matrix coloring can be applied to A*R^T */
+    /*---------------------------------------------------------------------------------------*/
     Mat ARt,RARt;
 #if defined(RART_PROFILE)
     PetscLogDouble t0,t1,t2;
 #endif
-    Mat_SeqAIJ           *c;
-    Mat_RARt             *rart;
-    
     if (scall == MAT_INITIAL_MATRIX) {
       ierr = PetscLogEventBegin(MAT_RARtSymbolic,A,R,0,0);CHKERRQ(ierr);
        /* must use '-mat_no_inode' with '-matmattransmult_color 1' - do not knwo why? */
     printf(" matrart_color_art_num = %g + %g = %g\n",t1-t0,t2-t1,t2-t0);
 #endif
     ierr = PetscLogEventEnd(MAT_RARtNumeric,A,R,0,0);CHKERRQ(ierr);
-    PetscFunctionReturn(0);
-  }
+#if defined(PETSC_USE_INFO)
+    ierr = PetscInfo(*C,"Use ARt=A*R^T, C=R*ARt via MatMatTransposeMult(). Coloring can be applied to A*R^T.\n");CHKERRQ(ierr); 
+#endif
+    break;
+  case 2:
+    /* via coloring_rart: apply coloring C = R*A*R^T                          */
+    /*-----------------------------------------------------*/
+    if (scall == MAT_INITIAL_MATRIX) { 
+      ierr = PetscLogEventBegin(MAT_RARtSymbolic,A,R,0,0);CHKERRQ(ierr);
+      ierr = MatRARtSymbolic_SeqAIJ_SeqAIJ(A,R,fill,C);CHKERRQ(ierr);
+      ierr = PetscLogEventEnd(MAT_RARtSymbolic,A,R,0,0);CHKERRQ(ierr);
+    }
+    ierr = PetscLogEventBegin(MAT_RARtNumeric,A,R,0,0);CHKERRQ(ierr);
+    ierr = MatRARtNumeric_SeqAIJ_SeqAIJ(A,R,*C);CHKERRQ(ierr);
+    ierr = PetscLogEventEnd(MAT_RARtNumeric,A,R,0,0);CHKERRQ(ierr);
+#if defined(PETSC_USE_INFO)
+    ierr = PetscInfo(*C,"Coloring C=R*A*R^T.\n");CHKERRQ(ierr); 
+#endif
+    break;
+  default:
+    /* via matmatmatmult: Rt=R^T, C=R*A*Rt - avoid inefficient sparse inner products */
+    /*-------------------------------------------------------------------------------*/
+    Mat           Rt;
+    if (scall == MAT_INITIAL_MATRIX) {
+      ierr = MatTranspose(R,MAT_INITIAL_MATRIX,&Rt);CHKERRQ(ierr); 
+      ierr = MatMatMatMult(R,A,Rt,scall,fill,C);CHKERRQ(ierr);
 
-  if (scall == MAT_INITIAL_MATRIX) { /* apply coloring to C=R*A*R^T */
-    ierr = PetscLogEventBegin(MAT_RARtSymbolic,A,R,0,0);CHKERRQ(ierr);
-    ierr = MatRARtSymbolic_SeqAIJ_SeqAIJ(A,R,fill,C);CHKERRQ(ierr);
-    ierr = PetscLogEventEnd(MAT_RARtSymbolic,A,R,0,0);CHKERRQ(ierr);
+      ierr = PetscNew(Mat_RARt,&rart);CHKERRQ(ierr);
+      rart->Rt = Rt;
+      c        = (Mat_SeqAIJ*)(*C)->data;
+      c->rart  = rart;
+      rart->destroy      = (*C)->ops->destroy;
+      (*C)->ops->destroy = MatDestroy_SeqAIJ_RARt;
+    } else {
+      c  = (Mat_SeqAIJ*)(*C)->data;
+      rart = c->rart;
+      Rt   = rart->Rt;
+      ierr = MatTranspose(R,MAT_REUSE_MATRIX,&Rt);CHKERRQ(ierr); 
+      ierr = MatMatMatMult(R,A,Rt,scall,fill,C);CHKERRQ(ierr);
+    }
+#if defined(PETSC_USE_INFO)
+    ierr = PetscInfo(*C,"Use Rt=R^T and C=R*A*Rt via MatMatMatMult() to avoid sparse inner products\n");CHKERRQ(ierr); 
+#endif
+    break;
   }
-  ierr = PetscLogEventBegin(MAT_RARtNumeric,A,R,0,0);CHKERRQ(ierr);
-  ierr = MatRARtNumeric_SeqAIJ_SeqAIJ(A,R,*C);CHKERRQ(ierr);
-  ierr = PetscLogEventEnd(MAT_RARtNumeric,A,R,0,0);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }