Actual source code: ex117.c
2: static char help[] = "Tests Cholesky factorization and Matview() for a SBAIJ matrix, (bs=2).\n";
3: /*
4: This code is modified from the code contributed by JUNWANG@uwm.edu on Apr 13, 2007
5: */
7: #include petscmat.h
11: int main(int argc,char **args)
12: {
14: Mat mat,fact;
15: int ind1[2],ind2[2];
16: PetscScalar temp[2*2];
17: PetscInt *nnz=new PetscInt[3];
18: IS perm,colp;
19: MatFactorInfo info;
21: PetscInitialize(&argc,&args,0,0);
22: nnz[0]=2;nnz[1]=1;nnz[1]=1;
24: MatCreateSeqSBAIJ(PETSC_COMM_SELF,2,6,6,0,nnz,&mat);
25: ind1[0]=0;ind1[1]=1;
26: temp[0]=3;temp[1]=2;temp[2]=0;temp[3]=3;
27: MatSetValues(mat,2,ind1,2,ind1,temp,INSERT_VALUES);
28: ind2[0]=4;ind2[1]=5;
29: temp[0]=1;temp[1]=1;temp[2]=2;temp[3]=1;
30: MatSetValues(mat,2,ind1,2,ind2,temp,INSERT_VALUES);
31: ind1[0]=2;ind1[1]=3;
32: temp[0]=4;temp[1]=1;temp[2]=1;temp[3]=5;
33: MatSetValues(mat,2,ind1,2,ind1,temp,INSERT_VALUES);
34: ind1[0]=4;ind1[1]=5;
35: temp[0]=5;temp[1]=1;temp[2]=1;temp[3]=6;
36: MatSetValues(mat,2,ind1,2,ind1,temp,INSERT_VALUES);
38: MatAssemblyBegin(mat,MAT_FINAL_ASSEMBLY);
39: MatAssemblyEnd(mat,MAT_FINAL_ASSEMBLY);
41: printf("mat: \n");
42: MatView(mat,PETSC_VIEWER_STDOUT_SELF);
44: // begin cholesky factorization
45: MatGetOrdering(mat,MATORDERING_NATURAL,&perm,&colp);
46: ISDestroy(colp);
47: info.fill=1.0;
48: MatGetFactor(mat,MAT_SOLVER_PETSC,MAT_FACTOR_CHOLESKY,&fact);
49: MatCholeskyFactorSymbolic(fact,mat,perm,&info);
50: MatCholeskyFactorNumeric(fact,mat,&info,&fact);
51: printf("Chol factor: \n");
52: MatView(fact, PETSC_VIEWER_STDOUT_SELF);
54: ISDestroy(perm);
55: ierr= MatDestroy(mat);
56: MatDestroy(fact);
57: PetscFinalize();
58: return 0;
59: }