Actual source code: convert.c
1: /*$Id: convert.c,v 1.76 2001/08/07 03:03:20 balay Exp $*/
3: #include src/mat/matimpl.h
7: /*
8: MatConvert_Basic - Converts from any input format to another format. For
9: parallel formats, the new matrix distribution is determined by PETSc.
11: Does not do preallocation so in general will be slow
12: */
13: int MatConvert_Basic(Mat mat,const MatType newtype,Mat *newmat) {
14: Mat M;
15: PetscScalar *vwork;
16: int ierr,i,nz,m,n,*cwork,rstart,rend,lm,ln;
19: MatGetSize(mat,&m,&n);
20: MatGetLocalSize(mat,&lm,&ln);
22: if (ln == n) ln = PETSC_DECIDE; /* try to preserve column ownership */
24: MatCreate(mat->comm,lm,ln,m,n,&M);
25: MatSetType(M,newtype);
27: MatGetOwnershipRange(mat,&rstart,&rend);
28: for (i=rstart; i<rend; i++) {
29: MatGetRow(mat,i,&nz,&cwork,&vwork);
30: MatSetValues(M,1,&i,nz,cwork,vwork,INSERT_VALUES);
31: MatRestoreRow(mat,i,&nz,&cwork,&vwork);
32: }
33: MatAssemblyBegin(M,MAT_FINAL_ASSEMBLY);
34: MatAssemblyEnd(M,MAT_FINAL_ASSEMBLY);
36: /* Fake support for "inplace" convert. */
37: if (*newmat == mat) {
38: MatDestroy(mat);
39: }
40: *newmat = M;
41: return(0);
42: }