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
5: /*
6: MatConvert_Basic - Converts from any input format to another format. For
7: parallel formats, the new matrix distribution is determined by PETSc.
9: Does not do preallocation so in general will be slow
10: */
11: int MatConvert_Basic(Mat mat,MatType newtype,Mat *M)
12: {
13: PetscScalar *vwork;
14: int ierr,i,nz,m,n,*cwork,rstart,rend,lm,ln;
17: MatGetSize(mat,&m,&n);
18: MatGetLocalSize(mat,&lm,&ln);
20: if (ln == n) ln = PETSC_DECIDE; /* try to preserve column ownership */
22: MatCreate(mat->comm,lm,ln,m,n,M);
23: MatSetType(*M,newtype);
25: MatGetOwnershipRange(mat,&rstart,&rend);
26: for (i=rstart; i<rend; i++) {
27: MatGetRow(mat,i,&nz,&cwork,&vwork);
28: MatSetValues(*M,1,&i,nz,cwork,vwork,INSERT_VALUES);
29: MatRestoreRow(mat,i,&nz,&cwork,&vwork);
30: }
31: MatAssemblyBegin(*M,MAT_FINAL_ASSEMBLY);
32: MatAssemblyEnd(*M,MAT_FINAL_ASSEMBLY);
33: return(0);
34: }