Skip to content

Commit

Permalink
Add optional use of contiguous arrays for sparse matrix
Browse files Browse the repository at this point in the history
The reference sparse matrix data structures in GenerateProblem_ref.cpp
can be allocated with a single “new” statement. This feature is turned
on by using the new compile-time macro HPCG_CONTIGUOUS_ARRAYS.  This
features is off by default, but can turned on in the same ways as
working with other HPCG_* defines.
  • Loading branch information
maherou committed May 14, 2016
1 parent 93b599e commit 299047b
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 5 deletions.
5 changes: 5 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ options and their meaning are:

-DHPCG_DEBUG

* Compile with sparse matrix arrays allocated contiguously. This option
* may be helpful on systems with pre-fetch::

-DHPCG_CONTIGUOUS_ARRAYS

* Compile with voluminous debugging information turned on::

-DHPCG_DETAILED_DEBUG
Expand Down
1 change: 1 addition & 0 deletions setup/Make.GCC_OMP
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HPCG_LIBS =
#
# -DHPCG_NO_MPI Define to disable MPI
# -DHPCG_NO_OPENMP Define to disable OPENMP
# -DHPCG_CONTIGUOUS_ARRAYS Define to have sparse matrix arrays long and contiguous
# -DHPCG_DEBUG Define to enable debugging output
# -DHPCG_DETAILED_DEBUG Define to enable very detailed debugging output
#
Expand Down
1 change: 1 addition & 0 deletions setup/Make.ICPC_OMP
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HPCG_LIBS =
#
# -DHPCG_NO_MPI Define to disable MPI
# -DHPCG_NO_OPENMP Define to disable OPENMP
# -DHPCG_CONTIGUOUS_ARRAYS Define to have sparse matrix arrays long and contiguous
# -DHPCG_DEBUG Define to enable debugging output
# -DHPCG_DETAILED_DEBUG Define to enable very detailed debugging output
#
Expand Down
1 change: 1 addition & 0 deletions setup/Make.Linux_MPI
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HPCG_LIBS =
#
# -DHPCG_NO_MPI Define to disable MPI
# -DHPCG_NO_OPENMP Define to disable OPENMP
# -DHPCG_CONTIGUOUS_ARRAYS Define to have sparse matrix arrays long and contiguous
# -DHPCG_DEBUG Define to enable debugging output
# -DHPCG_DETAILED_DEBUG Define to enable very detailed debugging output
#
Expand Down
1 change: 1 addition & 0 deletions setup/Make.Linux_Serial
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HPCG_LIBS =
#
# -DHPCG_NO_MPI Define to disable MPI
# -DHPCG_NO_OPENMP Define to disable OPENMP
# -DHPCG_CONTIGUOUS_ARRAYS Define to have sparse matrix arrays long and contiguous
# -DHPCG_DEBUG Define to enable debugging output
# -DHPCG_DETAILED_DEBUG Define to enable very detailed debugging output
#
Expand Down
1 change: 1 addition & 0 deletions setup/Make.MPIICPC_OMP
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HPCG_LIBS =
#
# -DHPCG_NO_MPI Define to disable MPI
# -DHPCG_NO_OPENMP Define to disable OPENMP
# -DHPCG_CONTIGUOUS_ARRAYS Define to have sparse matrix arrays long and contiguous
# -DHPCG_DEBUG Define to enable debugging output
# -DHPCG_DETAILED_DEBUG Define to enable very detailed debugging output
#
Expand Down
1 change: 1 addition & 0 deletions setup/Make.MPI_GCC_OMP
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HPCG_LIBS =
#
# -DHPCG_NO_MPI Define to disable MPI
# -DHPCG_NO_OPENMP Define to disable OPENMP
# -DHPCG_CONTIGUOUS_ARRAYS Define to have sparse matrix arrays long and contiguous
# -DHPCG_DEBUG Define to enable debugging output
# -DHPCG_DETAILED_DEBUG Define to enable very detailed debugging output
#
Expand Down
1 change: 1 addition & 0 deletions setup/Make.MPI_ICPC
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HPCG_LIBS =
#
# -DHPCG_NO_MPI Define to disable MPI
# -DHPCG_NO_OPENMP Define to disable OPENMP
# -DHPCG_CONTIGUOUS_ARRAYS Define to have sparse matrix arrays long and contiguous
# -DHPCG_DEBUG Define to enable debugging output
# -DHPCG_DETAILED_DEBUG Define to enable very detailed debugging output
#
Expand Down
1 change: 1 addition & 0 deletions setup/Make.MPI_ICPC_OMP
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HPCG_LIBS =
#
# -DHPCG_NO_MPI Define to enable MPI
# -DHPCG_NO_OPENMP Define to disable OPENMP
# -DHPCG_CONTIGUOUS_ARRAYS Define to have sparse matrix arrays long and contiguous
# -DHPCG_DEBUG Define to enable debugging output
# -DHPCG_DETAILED_DEBUG Define to enable very detailed debugging output
#
Expand Down
1 change: 1 addition & 0 deletions setup/Make.Mac_MPI
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HPCG_LIBS =
#
# -DHPCG_NO_MPI Define to disable MPI
# -DHPCG_NO_OPENMP Define to disable OPENMP
# -DHPCG_CONTIGUOUS_ARRAYS Define to have sparse matrix arrays long and contiguous
# -DHPCG_DEBUG Define to enable debugging output
# -DHPCG_DETAILED_DEBUG Define to enable very detailed debugging output
#
Expand Down
1 change: 1 addition & 0 deletions setup/Make.Mac_Serial
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HPCG_LIBS =
#
# -DHPCG_NO_MPI Define to disable MPI
# -DHPCG_NO_OPENMP Define to disable OPENMP
# -DHPCG_CONTIGUOUS_ARRAYS Define to have sparse matrix arrays long and contiguous
# -DHPCG_DEBUG Define to enable debugging output
# -DHPCG_DETAILED_DEBUG Define to enable very detailed debugging output
#
Expand Down
1 change: 1 addition & 0 deletions setup/Make.Mac_Serial_debug
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HPCG_LIBS =
#
# -DHPCG_NO_MPI Define to disable MPI
# -DHPCG_NO_OPENMP Define to disable OPENMP
# -DHPCG_CONTIGUOUS_ARRAYS Define to have sparse matrix arrays long and contiguous
# -DHPCG_DEBUG Define to enable debugging output
# -DHPCG_DETAILED_DEBUG Define to enable very detailed debugging output
#
Expand Down
22 changes: 18 additions & 4 deletions src/GenerateProblem_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,28 @@ void GenerateProblem_ref(SparseMatrix & A, Vector * b, Vector * x, Vector * xexa
mtxIndG[i] = 0;
mtxIndL[i] = 0;
}

#ifndef HPCG_CONTIGUOUS_ARRAYS
// Now allocate the arrays pointed to
for (local_int_t i=0; i< localNumberOfRows; ++i) {
for (local_int_t i=0; i< localNumberOfRows; ++i)
mtxIndL[i] = new local_int_t[numberOfNonzerosPerRow];
for (local_int_t i=0; i< localNumberOfRows; ++i)
matrixValues[i] = new double[numberOfNonzerosPerRow];
mtxIndG[i] = new global_int_t[numberOfNonzerosPerRow];
}

for (local_int_t i=0; i< localNumberOfRows; ++i)
mtxIndG[i] = new global_int_t[numberOfNonzerosPerRow];

#else
// Now allocate the arrays pointed to
mtxIndL[0] = new local_int_t[localNumberOfRows * numberOfNonzerosPerRow];
matrixValues[0] = new double[localNumberOfRows * numberOfNonzerosPerRow];
mtxIndG[0] = new global_int_t[localNumberOfRows * numberOfNonzerosPerRow];

for (local_int_t i=1; i< localNumberOfRows; ++i) {
mtxIndL[i] = mtxIndL[0] + i * numberOfNonzerosPerRow;
matrixValues[i] = matrixValues[0] + i * numberOfNonzerosPerRow;
mtxIndG[i] = mtxIndG[0] + i * numberOfNonzerosPerRow;
}
#endif

local_int_t localNumberOfNonzeros = 0;
// TODO: This triply nested loop could be flattened or use nested parallelism
Expand Down
7 changes: 6 additions & 1 deletion src/SparseMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,17 @@ inline void ReplaceMatrixDiagonal(SparseMatrix & A, Vector & diagonal) {
*/
inline void DeleteMatrix(SparseMatrix & A) {

#ifndef HPCG_CONTIGUOUS_ARRAYS
for (local_int_t i = 0; i< A.localNumberOfRows; ++i) {
delete [] A.matrixValues[i];
delete [] A.mtxIndG[i];
delete [] A.mtxIndL[i];
}

#else
delete [] A.matrixValues[0];
delete [] A.mtxIndG[0];
delete [] A.mtxIndL[0];
#endif
if (A.title) delete [] A.title;
if (A.nonzerosInRow) delete [] A.nonzerosInRow;
if (A.mtxIndG) delete [] A.mtxIndG;
Expand Down

0 comments on commit 299047b

Please sign in to comment.