/** Builds an IJMatrix from a distributed matrix by pulling rows out of the distributed_matrix and putting them into the IJMatrix. This routine does not effect the distributed matrix. In essence, it makes a copy of the input matrix in another format. NOTE: because this routine makes a copy and is not just a simple conversion, it is memory-expensive and should only be used in low-memory requirement situations (such as unit-testing code). */ HYPRE_Int HYPRE_BuildIJMatrixFromDistributedMatrix( HYPRE_DistributedMatrix DistributedMatrix, HYPRE_IJMatrix *ij_matrix, HYPRE_Int local_storage_type ) { HYPRE_Int ierr; MPI_Comm comm; HYPRE_Int M, N; HYPRE_Int first_local_row, last_local_row; HYPRE_Int first_local_col, last_local_col; HYPRE_Int i; HYPRE_Int size, *col_ind; double *values; if (!DistributedMatrix) return(-1); comm = HYPRE_DistributedMatrixGetContext( DistributedMatrix ); ierr = HYPRE_DistributedMatrixGetDims( DistributedMatrix, &M, &N ); ierr = HYPRE_DistributedMatrixGetLocalRange( DistributedMatrix, &first_local_row, &last_local_row , &first_local_col, &last_local_col ); ierr = HYPRE_IJMatrixCreate( comm, first_local_row, last_local_row, first_local_col, last_local_col, ij_matrix ); ierr = HYPRE_IJMatrixSetLocalStorageType( *ij_matrix, local_storage_type ); /* if(ierr) return(ierr); */ ierr = HYPRE_IJMatrixSetLocalSize( *ij_matrix, last_local_row-first_local_row+1, last_local_col-first_local_col+1 ); ierr = HYPRE_IJMatrixInitialize( *ij_matrix ); /* if(ierr) return(ierr);*/ /* Loop through all locally stored rows and insert them into ij_matrix */ for (i=first_local_row; i<= last_local_row; i++) { ierr = HYPRE_DistributedMatrixGetRow( DistributedMatrix, i, &size, &col_ind, &values ); /* if( ierr ) return(ierr);*/ ierr = HYPRE_IJMatrixInsertRow( *ij_matrix, size, i, col_ind, values ); /* if( ierr ) return(ierr);*/ ierr = HYPRE_DistributedMatrixRestoreRow( DistributedMatrix, i, &size, &col_ind, &values ); /* if( ierr ) return(ierr); */ } ierr = HYPRE_IJMatrixAssemble( *ij_matrix ); /* if(ierr) return(ierr); */ return(ierr); }
static Matrix *convert_matrix(MPI_Comm comm, HYPRE_DistributedMatrix *distmat) { HYPRE_Int beg_row, end_row, row, dummy; HYPRE_Int len, *ind; HYPRE_Real *val; Matrix *mat; HYPRE_DistributedMatrixGetLocalRange(distmat, &beg_row, &end_row, &dummy, &dummy); mat = MatrixCreate(comm, beg_row, end_row); for (row=beg_row; row<=end_row; row++) { HYPRE_DistributedMatrixGetRow(distmat, row, &len, &ind, &val); MatrixSetRow(mat, row, len, ind, val); HYPRE_DistributedMatrixRestoreRow(distmat, row, &len, &ind, &val); } MatrixComplete(mat); #ifdef BALANCE_INFO matvec_timing(comm, mat); balance_info(comm, mat); #endif return mat; }