Actual source code: ex65.c
2: static char help[] = "Saves a rectangular sparse matrix to disk.\n\n";
4: #include <petscmat.h>
6: int main(int argc,char **args)
7: {
8: Mat A;
9: PetscInt m = 100,n = 11,js[11],i,j,cnt;
10: PetscScalar values[11];
11: PetscViewer view;
13: PetscInitialize(&argc,&args,(char*)0,help);
14: MatCreateSeqAIJ(PETSC_COMM_WORLD,m,n,20,0,&A);
16: for (i=0; i<n; i++) values[i] = (PetscReal)i;
18: for (i=0; i<m; i++) {
19: cnt = 0;
20: if (i % 2) {
21: for (j=0; j<n; j += 2) {
22: js[cnt++] = j;
23: }
24: } else {
25: ;
26: }
27: MatSetValues(A,1,&i,cnt,js,values,INSERT_VALUES);
28: }
29: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
30: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
32: PetscViewerBinaryOpen(PETSC_COMM_WORLD,"rect",FILE_MODE_WRITE,&view);
33: MatView(A,view);
34: PetscViewerDestroy(&view);
36: MatDestroy(&A);
38: PetscFinalize();
39: return 0;
40: }
42: /*TEST
44: test:
46: TEST*/