Date: 2013-07-02T14:44:30+00:00

Actual source code: convert.c
petsc-3.4.2 2013-07-02

      2: #include <petsc-private/matimpl.h>

      6: /*
      7:   MatConvert_Basic - Converts from any input format to another format. For
      8:   parallel formats, the new matrix distribution is determined by PETSc.

     10:   Does not do preallocation so in general will be slow
     11:  */
     12: PetscErrorCode MatConvert_Basic(Mat mat, MatType newtype,MatReuse reuse,Mat *newmat)
     13: {
     14:   Mat               M;
     15:   const PetscScalar *vwork;
     16:   PetscErrorCode    ierr;
     17:   PetscInt          i,nz,m,n,rstart,rend,lm,ln;
     18:   const PetscInt    *cwork;
     19:   PetscBool         isseqsbaij,ismpisbaij;

     22:   MatGetSize(mat,&m,&n);
     23:   MatGetLocalSize(mat,&lm,&ln);

     25:   if (ln == n) ln = PETSC_DECIDE; /* try to preserve column ownership */

     27:   MatCreate(PetscObjectComm((PetscObject)mat),&M);
     28:   MatSetSizes(M,lm,ln,m,n);
     29:   MatSetBlockSize(M,mat->rmap->bs);
     30:   MatSetType(M,newtype);
     31:   PetscObjectTypeCompare((PetscObject)M,MATSEQSBAIJ,&isseqsbaij);
     32:   PetscObjectTypeCompare((PetscObject)M,MATMPISBAIJ,&ismpisbaij);
     33:   MatSetUp(M);
     34:   if (isseqsbaij || ismpisbaij) {MatSetOption(M,MAT_IGNORE_LOWER_TRIANGULAR,PETSC_TRUE);}

     36:   MatGetOwnershipRange(mat,&rstart,&rend);
     37:   for (i=rstart; i<rend; i++) {
     38:     MatGetRow(mat,i,&nz,&cwork,&vwork);
     39:     MatSetValues(M,1,&i,nz,cwork,vwork,INSERT_VALUES);
     40:     MatRestoreRow(mat,i,&nz,&cwork,&vwork);
     41:   }
     42:   MatAssemblyBegin(M,MAT_FINAL_ASSEMBLY);
     43:   MatAssemblyEnd(M,MAT_FINAL_ASSEMBLY);

     45:   if (reuse == MAT_REUSE_MATRIX) {
     46:     MatHeaderReplace(mat,M);
     47:   } else {
     48:     *newmat = M;
     49:   }
     50:   return(0);
     51: }