Actual source code: mhyp.c
1: /*$Id: bvec2.c,v 1.202 2001/09/12 03:26:24 bsmith Exp $*/
2: /*
3: Creates hypre ijvector from PETSc vector
4: */
6: #include src/mat/matimpl.h
7: EXTERN_C_BEGIN
8: #include "HYPRE.h"
9: #include "IJ_mv.h"
10: EXTERN_C_END
12: int MatHYPRE_IJMatrixCreate(Mat v,HYPRE_IJMatrix *ij)
13: {
14: int ierr,rstart,rend,cstart,cend;
15:
17: MatGetOwnershipRange(v,&rstart,&rend);
18: PetscMapGetLocalRange(v->cmap,&cstart,&cend);
19: HYPRE_IJMatrixCreate(v->comm,rstart,rend-1,cstart,cend-1,ij);
20: HYPRE_IJMatrixSetObjectType(*ij,HYPRE_PARCSR);
21: return(0);
22: }
24: /*
25: Currently this only works with the MPIAIJ PETSc matrices to make
26: the conversion efficient
27: */
28: /* #include "src/mat/impls/aij/mpi/mpiaij.h" */
29: /* Mat_MPIAIJ *aij = (Mat_MPIAIJ *)v->data; */
31: int MatHYPRE_IJMatrixCopy(Mat v,HYPRE_IJMatrix ij)
32: {
33: int i,ierr,rstart,rend,*cols,ncols;
34: PetscScalar *values;
37: HYPRE_IJMatrixInitialize(ij);
38: MatGetOwnershipRange(v,&rstart,&rend);
40: for (i=rstart; i<rend; i++) {
41: MatGetRow(v,i,&ncols,&cols,&values);
42: HYPRE_IJMatrixSetValues(ij,1,&ncols,&i,cols,values);
43: MatRestoreRow(v,i,&ncols,&cols,&values);
44: }
46: HYPRE_IJMatrixAssemble(ij);
47: return(0);
48: }