Actual source code: dspai.c
1: /* $Id: dspai.c,v 1.7 2001/08/07 03:03:40 balay Exp $*/
3: #include petscmat.h
5: /*
6: MatDumpSPAI - Dumps a PETSc matrix to a file in an ASCII format
7: suitable for the SPAI code of Stephen Barnard to solve. This routine
8: is simply here to allow testing of matrices directly with the SPAI
9: code, rather then through the PETSc interface.
11: */
12: int MatDumpSPAI(Mat A,FILE *file)
13: {
14: PetscScalar *vals;
15: int i,j,ierr,*cols,n,size,nz;
16: MPI_Comm comm;
18: PetscObjectGetComm((PetscObject)A,&comm);
19:
20: MPI_Comm_size(comm,&size);
21: if (size > 1) SETERRQ(1,"Only single processor dumps");
23: MatGetSize(A,&n,&n);
25: /* print the matrix */
26: fprintf(file,"%d\n",n);
27: for (i=0; i<n; i++) {
28: MatGetRow(A,i,&nz,&cols,&vals);
29: for (j=0; j<nz; j++) {
30: fprintf(file,"%d %d %16.14e\n",i+1,cols[j]+1,vals[j]);
31: }
32: MatRestoreRow(A,i,&nz,&cols,&vals);
33: }
35: return(0);
36: }
38: int VecDumpSPAI(Vec b,FILE *file)
39: {
40: int n,i,ierr;
41: PetscScalar *array;
43: VecGetSize(b,&n);
44: VecGetArray(b,&array);
46: fprintf(file,"%d\n",n);
47: for (i=0; i<n; i++) {
48: fprintf(file,"%d %16.14e\n",i+1,array[i]);
49: }
51: return(0);
52: }