Actual source code: dspai.c
petsc-3.7.1 2016-05-15
Report Typos and Errors

      2: #include <petscmat.h>
      3: #include <petsc/private/petscimpl.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: PetscErrorCode  MatDumpSPAI(Mat A,FILE *file)
     13: {
     14:   const PetscScalar *vals;
     15:   PetscErrorCode    ierr;
     16:   int               i,j,n,size,nz;
     17:   const int         *cols;
     18:   MPI_Comm          comm;

     20:   PetscObjectGetComm((PetscObject)A,&comm);

     22:   MPI_Comm_size(comm,&size);
     23:   if (size > 1) SETERRQ(PetscObjectComm((PetscObject)A),PETSC_ERR_SUP,"Only single processor dumps");

     25:   MatGetSize(A,&n,&n);

     27:   /* print the matrix */
     28:   fprintf(file,"%d\n",n);
     29:   for (i=0; i<n; i++) {
     30:     MatGetRow(A,i,&nz,&cols,&vals);
     31:     for (j=0; j<nz; j++) fprintf(file,"%d %d %16.14e\n",i+1,cols[j]+1,vals[j]);
     32:     MatRestoreRow(A,i,&nz,&cols,&vals);
     33:   }
     34:   return(0);
     35: }

     37: PetscErrorCode  VecDumpSPAI(Vec b,FILE *file)
     38: {
     40:   int            n,i;
     41:   PetscScalar    *array;

     43:   VecGetSize(b,&n);
     44:   VecGetArray(b,&array);

     46:   fprintf(file,"%d\n",n);
     47:   for (i=0; i<n; i++) fprintf(file,"%d %16.14e\n",i+1,array[i]);
     48:   return(0);
     49: }