Skip to content

Commit

Permalink
Add HYPRE_IJMatrixGetGlobalInfo (#1147)
Browse files Browse the repository at this point in the history
Add function to get the global number of rows, columns, and nonzeros of an IJMatrix.
  • Loading branch information
victorapm authored Oct 3, 2024
1 parent 9c2d726 commit 773824c
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 21 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ src/TAGS
hypre/
cmbuild/
install/
test/
AUTOTEST/*.dir
.vscode

Expand Down
49 changes: 45 additions & 4 deletions src/IJ_mv/HYPRE_IJMatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,48 @@ HYPRE_IJMatrixGetLocalRange( HYPRE_IJMatrix matrix,
return hypre_error_flag;
}

/*--------------------------------------------------------------------------
*--------------------------------------------------------------------------*/

HYPRE_Int
HYPRE_IJMatrixGetGlobalInfo( HYPRE_IJMatrix matrix,
HYPRE_BigInt *global_num_rows,
HYPRE_BigInt *global_num_cols,
HYPRE_BigInt *global_num_nonzeros )
{
hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;

if (!ijmatrix)
{
hypre_error_in_arg(1);
return hypre_error_flag;
}

*global_num_rows = hypre_IJMatrixGlobalNumRows(ijmatrix);
*global_num_cols = hypre_IJMatrixGlobalNumCols(ijmatrix);

if (hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR)
{
hypre_ParCSRMatrix *par_matrix = (hypre_ParCSRMatrix *) hypre_IJMatrixObject(ijmatrix);

if (!par_matrix)
{
hypre_error_in_arg(1);
return hypre_error_flag;
}

hypre_ParCSRMatrixSetNumNonzeros(par_matrix);
*global_num_nonzeros = hypre_ParCSRMatrixNumNonzeros(par_matrix);
}
else
{
hypre_error_in_arg(1);
return hypre_error_flag;
}

return hypre_error_flag;
}

/*--------------------------------------------------------------------------
*--------------------------------------------------------------------------*/

Expand Down Expand Up @@ -1276,6 +1318,8 @@ HYPRE_Int
HYPRE_IJMatrixPrint( HYPRE_IJMatrix matrix,
const char *filename )
{
void *object;

if (!matrix)
{
hypre_error_in_arg(1);
Expand All @@ -1288,11 +1332,8 @@ HYPRE_IJMatrixPrint( HYPRE_IJMatrix matrix,
return hypre_error_flag;
}

void *object;
HYPRE_IJMatrixGetObject(matrix, &object);
hypre_ParCSRMatrix *par_csr = (hypre_ParCSRMatrix*) object;

hypre_ParCSRMatrixPrintIJ(par_csr, 0, 0, filename);
hypre_ParCSRMatrixPrintIJ((hypre_ParCSRMatrix*) object, 0, 0, filename);

return hypre_error_flag;
}
Expand Down
18 changes: 18 additions & 0 deletions src/IJ_mv/HYPRE_IJ_mv.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,24 @@ HYPRE_Int HYPRE_IJMatrixGetLocalRange(HYPRE_IJMatrix matrix,
HYPRE_BigInt *jlower,
HYPRE_BigInt *jupper);

/**
* Gets global information about the matrix, including the total number of rows,
* columns, and nonzero elements across all processes.
*
* @param matrix The IJMatrix object to query.
* @param global_num_rows Pointer to store the total number of rows in the matrix.
* @param global_num_cols Pointer to store the total number of columns in the matrix.
* @param global_num_nonzeros Pointer to store the total number of nonzero elements in the matrix.
*
* @return HYPRE_Int Error code.
*
* Collective (must be called by all processes).
**/
HYPRE_Int HYPRE_IJMatrixGetGlobalInfo(HYPRE_IJMatrix matrix,
HYPRE_BigInt *global_num_rows,
HYPRE_BigInt *global_num_cols,
HYPRE_BigInt *global_num_nonzeros);

/**
* Get a reference to the constructed matrix object.
*
Expand Down
8 changes: 8 additions & 0 deletions src/parcsr_ls/par_nongalerkin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,8 @@ hypre_NonGalerkinSparsityPattern(hypre_ParCSRMatrix *R_IAP,
HYPRE_Int i, j, Cpt, row_start, row_end;
HYPRE_BigInt global_row, global_col;

HYPRE_ANNOTATE_FUNC_BEGIN;

/* Other Setup */
if (num_cols_RAP_offd)
{
Expand Down Expand Up @@ -1233,6 +1235,8 @@ hypre_NonGalerkinSparsityPattern(hypre_ParCSRMatrix *R_IAP,
hypre_TFree(ijbuf_sym_numcols, memory_location_RAP);
}

HYPRE_ANNOTATE_FUNC_END;

return Pattern_CSR;
}

Expand Down Expand Up @@ -1368,6 +1372,8 @@ hypre_BoomerAMGBuildNonGalerkinCoarseOperator( hypre_ParCSRMatrix **RAP_ptr,
HYPRE_BigInt *ijbuf_sym_cols, *ijbuf_sym_rownums;
HYPRE_Int *ijbuf_sym_numcols;

HYPRE_ANNOTATE_FUNC_BEGIN;

/* Further Initializations */
if (num_cols_RAP_offd)
{ RAP_offd_data = hypre_CSRMatrixData(RAP_offd); }
Expand Down Expand Up @@ -2352,5 +2358,7 @@ hypre_BoomerAMGBuildNonGalerkinCoarseOperator( hypre_ParCSRMatrix **RAP_ptr,
HYPRE_IJMatrixSetObjectType(ijmatrix, -1);
HYPRE_IJMatrixDestroy(ijmatrix);

HYPRE_ANNOTATE_FUNC_END;

return hypre_error_flag;
}
4 changes: 4 additions & 0 deletions src/parcsr_mv/par_csr_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ hypre_ParCSRMatrixBlkFilter( hypre_ParCSRMatrix *A,
HYPRE_Int block_size,
hypre_ParCSRMatrix **B_ptr )
{
HYPRE_ANNOTATE_FUNC_BEGIN;

#if defined(HYPRE_USING_GPU)
if (hypre_GetExecPolicy1(hypre_ParCSRMatrixMemoryLocation(A)) == HYPRE_EXEC_DEVICE)
{
Expand All @@ -210,5 +212,7 @@ hypre_ParCSRMatrixBlkFilter( hypre_ParCSRMatrix *A,
hypre_ParCSRMatrixBlkFilterHost(A, block_size, B_ptr);
}

HYPRE_ANNOTATE_FUNC_END;

return hypre_error_flag;
}
Loading

0 comments on commit 773824c

Please sign in to comment.