Actual source code: dspai.c
2: #include <petscmat.h>
4: /*
5: MatDumpSPAI - Dumps a PETSc matrix to a file in an ASCII format
6: suitable for the SPAI code of Stephen Barnard to solve. This routine
7: is simply here to allow testing of matrices directly with the SPAI
8: code, rather then through the PETSc interface.
10: */
11: PetscErrorCode MatDumpSPAI(Mat A,FILE *file)
12: {
13: const PetscScalar *vals;
15: int i,j,n,size,nz;
16: const int *cols;
17: MPI_Comm comm;
19: PetscObjectGetComm((PetscObject)A,&comm);
20:
21: MPI_Comm_size(comm,&size);
22: if (size > 1) SETERRQ(((PetscObject)A)->comm,PETSC_ERR_SUP,"Only single processor dumps");
24: MatGetSize(A,&n,&n);
26: /* print the matrix */
27: fprintf(file,"%d\n",n);
28: for (i=0; i<n; i++) {
29: MatGetRow(A,i,&nz,&cols,&vals);
30: for (j=0; j<nz; j++) {
31: fprintf(file,"%d %d %16.14e\n",i+1,cols[j]+1,vals[j]);
32: }
33: MatRestoreRow(A,i,&nz,&cols,&vals);
34: }
36: return(0);
37: }
39: PetscErrorCode VecDumpSPAI(Vec b,FILE *file)
40: {
42: int n,i;
43: PetscScalar *array;
45: VecGetSize(b,&n);
46: VecGetArray(b,&array);
48: fprintf(file,"%d\n",n);
49: for (i=0; i<n; i++) {
50: fprintf(file,"%d %16.14e\n",i+1,array[i]);
51: }
53: return(0);
54: }