Skip to content

Commit

Permalink
Adding optimized multi GPU matrix/vector assembly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Mullowney committed May 27, 2021
1 parent b9b1501 commit 494094a
Show file tree
Hide file tree
Showing 10 changed files with 1,267 additions and 423 deletions.
84 changes: 84 additions & 0 deletions src/IJ_mv/HYPRE_IJMatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,90 @@ HYPRE_IJMatrixSetMaxOffProcElmts( HYPRE_IJMatrix matrix,
* create IJMatrix on host memory
*--------------------------------------------------------------------------*/

HYPRE_Int
HYPRE_IJMatrixSetMaxOnProcElmts( HYPRE_IJMatrix matrix,
HYPRE_Int max_on_proc_elmts)
{
hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;

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

if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
{
return( hypre_IJMatrixSetMaxOnProcElmtsParCSR(ijmatrix,
max_on_proc_elmts) );
}
else
{
hypre_error_in_arg(1);
}

return hypre_error_flag;
}

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

HYPRE_Int
HYPRE_IJMatrixSetOffProcSendElmts( HYPRE_IJMatrix matrix,
HYPRE_Int off_proc_send_elmts)
{
hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;

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

if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
{
return( hypre_IJMatrixSetOffProcSendElmtsParCSR(ijmatrix,
off_proc_send_elmts) );
}
else
{
hypre_error_in_arg(1);
}

return hypre_error_flag;
}

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

HYPRE_Int
HYPRE_IJMatrixSetOffProcRecvElmts( HYPRE_IJMatrix matrix,
HYPRE_Int off_proc_recv_elmts)
{
hypre_IJMatrix *ijmatrix = (hypre_IJMatrix *) matrix;

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

if ( hypre_IJMatrixObjectType(ijmatrix) == HYPRE_PARCSR )
{
return( hypre_IJMatrixSetOffProcRecvElmtsParCSR(ijmatrix,
off_proc_recv_elmts) );
}
else
{
hypre_error_in_arg(1);
}

return hypre_error_flag;
}

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

HYPRE_Int
HYPRE_IJMatrixRead( const char *filename,
MPI_Comm comm,
Expand Down
84 changes: 84 additions & 0 deletions src/IJ_mv/HYPRE_IJVector.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,90 @@ HYPRE_IJVectorSetMaxOffProcElmts( HYPRE_IJVector vector,
return hypre_error_flag;
}

/*--------------------------------------------------------------------------
* HYPRE_IJVectorSetMaxOnProcElmts
*--------------------------------------------------------------------------*/

HYPRE_Int
HYPRE_IJVectorSetMaxOnProcElmts( HYPRE_IJVector vector,
HYPRE_Int max_on_proc_elmts )
{
hypre_IJVector *vec = (hypre_IJVector *) vector;

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

if ( hypre_IJVectorObjectType(vec) == HYPRE_PARCSR )
{
return( hypre_IJVectorSetMaxOnProcElmtsPar(vec, max_on_proc_elmts));
}
else
{
hypre_error_in_arg(1);
}

return hypre_error_flag;
}

/*--------------------------------------------------------------------------
* HYPRE_IJVectorSetOffProcSendElmts
*--------------------------------------------------------------------------*/

HYPRE_Int
HYPRE_IJVectorSetOffProcSendElmts( HYPRE_IJVector vector,
HYPRE_Int off_proc_send_elmts )
{
hypre_IJVector *vec = (hypre_IJVector *) vector;

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

if ( hypre_IJVectorObjectType(vec) == HYPRE_PARCSR )
{
return( hypre_IJVectorSetOffProcSendElmtsPar(vec, off_proc_send_elmts));
}
else
{
hypre_error_in_arg(1);
}

return hypre_error_flag;
}

/*--------------------------------------------------------------------------
* HYPRE_IJVectorSetOffProcRecvElmts
*--------------------------------------------------------------------------*/

HYPRE_Int
HYPRE_IJVectorSetOffProcRecvElmts( HYPRE_IJVector vector,
HYPRE_Int off_proc_recv_elmts )
{
hypre_IJVector *vec = (hypre_IJVector *) vector;

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

if ( hypre_IJVectorObjectType(vec) == HYPRE_PARCSR )
{
return( hypre_IJVectorSetOffProcRecvElmtsPar(vec, off_proc_recv_elmts));
}
else
{
hypre_error_in_arg(1);
}

return hypre_error_flag;
}

/*--------------------------------------------------------------------------
* HYPRE_IJVectorSetObjectType
*--------------------------------------------------------------------------*/
Expand Down
70 changes: 69 additions & 1 deletion src/IJ_mv/HYPRE_IJ_mv.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,40 @@ HYPRE_Int HYPRE_IJMatrixSetDiagOffdSizes(HYPRE_IJMatrix matrix,
HYPRE_Int HYPRE_IJMatrixSetMaxOffProcElmts(HYPRE_IJMatrix matrix,
HYPRE_Int max_off_proc_elmts);

/**
* (Optional) Sets the maximum number of elements that are expected to be set
* (or added) on this processor from this processor
* This routine can significantly improve the efficiency of matrix
* construction, and should always be utilized if possible.
*
* Not collective.
**/
HYPRE_Int HYPRE_IJMatrixSetMaxOnProcElmts(HYPRE_IJMatrix matrix,
HYPRE_Int max_on_proc_elmts);

/**
* (Optional) Sets the exact number of elements that are expected to be set
* added on other processors from this processor.
* This routine can significantly improve the efficiency of matrix
* construction, and should always be utilized if possible.
*
* Not collective.
**/
HYPRE_Int HYPRE_IJMatrixSetOffProcSendElmts(HYPRE_IJMatrix matrix,
HYPRE_Int off_proc_send_elmts);


/**
* (Optional) Sets the exact number of elements that are expected to be set
* added on this processor from other processors
* This routine can significantly improve the efficiency of matrix
* construction, and should always be utilized if possible.
*
* Not collective.
**/
HYPRE_Int HYPRE_IJMatrixSetOffProcRecvElmts(HYPRE_IJMatrix matrix,
HYPRE_Int off_proc_recv_elmts);

/**
* (Optional) Sets the print level, if the user wants to print
* error messages. The default is 0, i.e. no error messages are printed.
Expand Down Expand Up @@ -399,14 +433,48 @@ HYPRE_Int HYPRE_IJVectorInitialize_v2( HYPRE_IJVector vector, HYPRE_MemoryLocati
/**
* (Optional) Sets the maximum number of elements that are expected to be set
* (or added) on other processors from this processor
* This routine can significantly improve the efficiency of matrix
* This routine can significantly improve the efficiency of vector
* construction, and should always be utilized if possible.
*
* Not collective.
**/
HYPRE_Int HYPRE_IJVectorSetMaxOffProcElmts(HYPRE_IJVector vector,
HYPRE_Int max_off_proc_elmts);

/**
* (Optional) Sets the maximum number of elements that are expected to be set
* (or added) on this processor from this processor
* This routine can significantly improve the efficiency of vector
* construction, and should always be utilized if possible.
*
* Not collective.
**/
HYPRE_Int HYPRE_IJVectorSetMaxOnProcElmts(HYPRE_IJVector vector,
HYPRE_Int max_on_proc_elmts);

/**
* (Optional) Sets the exact number of elements that are expected to be set
* added on other processors from this processor.
* This routine can significantly improve the efficiency of vector
* construction, and should always be utilized if possible.
*
* Not collective.
**/
HYPRE_Int HYPRE_IJVectorSetOffProcSendElmts(HYPRE_IJVector vector,
HYPRE_Int off_proc_send_elmts);


/**
* (Optional) Sets the exact number of elements that are expected to be set
* added on this processor from other processors
* This routine can significantly improve the efficiency of vector
* construction, and should always be utilized if possible.
*
* Not collective.
**/
HYPRE_Int HYPRE_IJVectorSetOffProcRecvElmts(HYPRE_IJVector vector,
HYPRE_Int off_proc_recv_elmts);

/**
* Sets values in vector. The arrays \e values and \e indices
* are of dimension \e nvalues and contain the vector values to be
Expand Down
69 changes: 69 additions & 0 deletions src/IJ_mv/IJMatrix_parcsr.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ hypre_IJMatrixSetDiagOffdSizesParCSR(hypre_IJMatrix *matrix,
return hypre_error_flag;
}


/******************************************************************************
*
* hypre_IJMatrixSetMaxOnProcElmtsParCSR
Expand Down Expand Up @@ -246,6 +247,74 @@ hypre_IJMatrixSetMaxOffProcElmtsParCSR(hypre_IJMatrix *matrix,
return hypre_error_flag;
}


/******************************************************************************
*
* hypre_IJMatrixSetOffProcSendElmtsParCSR
*
*****************************************************************************/

HYPRE_Int
hypre_IJMatrixSetOffProcSendElmtsParCSR(hypre_IJMatrix *matrix,
HYPRE_Int off_proc_send_elmts)
{
hypre_AuxParCSRMatrix *aux_matrix;
HYPRE_Int local_num_rows, local_num_cols, my_id;
HYPRE_BigInt *row_partitioning = hypre_IJMatrixRowPartitioning(matrix);
HYPRE_BigInt *col_partitioning = hypre_IJMatrixColPartitioning(matrix);
MPI_Comm comm = hypre_IJMatrixComm(matrix);

hypre_MPI_Comm_rank(comm,&my_id);
aux_matrix = (hypre_AuxParCSRMatrix *) hypre_IJMatrixTranslator(matrix);
if (!aux_matrix)
{
local_num_rows = (HYPRE_Int)(row_partitioning[1]-row_partitioning[0]);
local_num_cols = (HYPRE_Int)(col_partitioning[1]-col_partitioning[0]);
hypre_AuxParCSRMatrixCreate(&aux_matrix, local_num_rows,
local_num_cols, NULL);
hypre_IJMatrixTranslator(matrix) = aux_matrix;
}
#if defined(HYPRE_USING_CUDA) || defined(HYPRE_USING_HIP)
hypre_AuxParCSRMatrixUsrOffProcSendElmts(aux_matrix) = off_proc_send_elmts;
hypre_AuxParCSRMatrixUsrElmtsFilled(aux_matrix) = 0;
#endif
return hypre_error_flag;
}


/******************************************************************************
*
* hypre_IJMatrixSetOffProcRecvElmtsParCSR
*
*****************************************************************************/

HYPRE_Int
hypre_IJMatrixSetOffProcRecvElmtsParCSR(hypre_IJMatrix *matrix,
HYPRE_Int off_proc_recv_elmts)
{
hypre_AuxParCSRMatrix *aux_matrix;
HYPRE_Int local_num_rows, local_num_cols, my_id;
HYPRE_BigInt *row_partitioning = hypre_IJMatrixRowPartitioning(matrix);
HYPRE_BigInt *col_partitioning = hypre_IJMatrixColPartitioning(matrix);
MPI_Comm comm = hypre_IJMatrixComm(matrix);

hypre_MPI_Comm_rank(comm,&my_id);
aux_matrix = (hypre_AuxParCSRMatrix *) hypre_IJMatrixTranslator(matrix);
if (!aux_matrix)
{
local_num_rows = (HYPRE_Int)(row_partitioning[1]-row_partitioning[0]);
local_num_cols = (HYPRE_Int)(col_partitioning[1]-col_partitioning[0]);
hypre_AuxParCSRMatrixCreate(&aux_matrix, local_num_rows,
local_num_cols, NULL);
hypre_IJMatrixTranslator(matrix) = aux_matrix;
}
#if defined(HYPRE_USING_CUDA) || defined(HYPRE_USING_HIP)
hypre_AuxParCSRMatrixUsrOffProcRecvElmts(aux_matrix) = off_proc_recv_elmts;
hypre_AuxParCSRMatrixUsrElmtsFilled(aux_matrix) = 0;
#endif
return hypre_error_flag;
}

/******************************************************************************
*
* hypre_IJMatrixInitializeParCSR
Expand Down
Loading

0 comments on commit 494094a

Please sign in to comment.