Actual source code: mhyp.c

  1: #define PETSCMAT_DLL

  3: /*
  4:     Creates hypre ijvector from PETSc vector
  5: */

 7:  #include src/mat/matimpl.h
  9: #include "HYPRE.h"
 10: #include "IJ_mv.h"

 13: PetscErrorCode MatHYPRE_IJMatrixCreate(Mat v,HYPRE_IJMatrix *ij)
 14: {
 16:   int rstart,rend,cstart,cend;
 17: 
 19:   MatGetOwnershipRange(v,&rstart,&rend);
 20:   PetscMapGetLocalRange(v->cmap,&cstart,&cend);
 21:   HYPRE_IJMatrixCreate(v->comm,rstart,rend-1,cstart,cend-1,ij);
 22:   HYPRE_IJMatrixSetObjectType(*ij,HYPRE_PARCSR);
 23:   return(0);
 24: }

 26: /*
 27:       Currently this only works with the MPIAIJ PETSc matrices to make
 28: the conversion efficient
 29: */
 30: /* #include "src/mat/impls/aij/mpi/mpiaij.h" */
 31: /*  Mat_MPIAIJ  *aij = (Mat_MPIAIJ *)v->data; */

 33: PetscErrorCode MatHYPRE_IJMatrixCopy(Mat v,HYPRE_IJMatrix ij)
 34: {
 35:   PetscErrorCode    ierr;
 36:   int               i,rstart,rend,ncols;
 37:   const PetscScalar *values;
 38:   const int         *cols;

 41:   HYPRE_IJMatrixInitialize(ij);
 42:   MatGetOwnershipRange(v,&rstart,&rend);
 43:   for (i=rstart; i<rend; i++) {
 44:     MatGetRow(v,i,&ncols,&cols,&values);
 45:     HYPRE_IJMatrixSetValues(ij,1,&ncols,&i,cols,values);
 46:     MatRestoreRow(v,i,&ncols,&cols,&values);
 47:   }
 48:   HYPRE_IJMatrixAssemble(ij);
 49:   return(0);
 50: }