Skip to content

Commit 941dbff

Browse files
committed
Linear algebra changes
1 parent 485b722 commit 941dbff

83 files changed

Lines changed: 2421 additions & 962 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"build": {
33
"dockerfile": "Dockerfile",
44
"args": {
5-
"GEOS_TPL_TAG": "312-717"
5+
"GEOS_TPL_TAG": "314-733"
66
}
77
},
88
"runArgs": [

src/cmake/thirdparty/SetupGeosxThirdParty.cmake

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -581,27 +581,17 @@ endif()
581581
if(DEFINED SCOTCH_DIR)
582582
message(STATUS "SCOTCH_DIR = ${SCOTCH_DIR}")
583583

584-
find_and_import(NAME scotch
585-
INCLUDE_DIRECTORIES ${SCOTCH_DIR}/include
586-
LIBRARY_DIRECTORIES ${SCOTCH_DIR}/lib
587-
HEADER scotch.h
588-
LIBRARIES scotch scotcherr )
589-
590-
find_and_import(NAME ptscotch
591-
INCLUDE_DIRECTORIES ${SCOTCH_DIR}/include
592-
LIBRARY_DIRECTORIES ${SCOTCH_DIR}/lib
593-
DEPENDS scotch
594-
HEADER ptscotch.h
595-
LIBRARIES ptscotch ptscotcherr )
596-
597-
extract_version_from_header( NAME scotch
598-
HEADER "${SCOTCH_DIR}/include/scotch.h"
599-
MAJOR_VERSION_STRING "SCOTCH_VERSION"
600-
MINOR_VERSION_STRING "SCOTCH_RELEASE"
601-
PATCH_VERSION_STRING "SCOTCH_PATCHLEVEL")
602-
603-
set(ENABLE_SCOTCH ON CACHE BOOL "")
604-
set(thirdPartyLibs ${thirdPartyLibs} scotch ptscotch)
584+
find_package(SCOTCH REQUIRED
585+
PATHS ${SCOTCH_DIR}
586+
NO_DEFAULT_PATH)
587+
588+
message( " ----> scotch_VERSION = ${SCOTCH_VERSION}")
589+
590+
foreach(_scotch_target SCOTCH::scotch SCOTCH::ptscotch SCOTCH::scotcherr )
591+
get_target_property(SCOTCH_INCLUDE_DIRS ${_scotch_target} INTERFACE_INCLUDE_DIRECTORIES)
592+
set_target_properties(${_scotch_target} PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${SCOTCH_INCLUDE_DIRS}")
593+
set(thirdPartyLibs ${thirdPartyLibs} ${_scotch_target})
594+
endforeach()
605595
else()
606596
if(ENABLE_SCOTCH)
607597
message(WARNING "ENABLE_SCOTCH is ON but SCOTCH_DIR isn't defined.")

src/coreComponents/codingUtilities/UnitTestUtilities.hpp

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,11 @@ inline void checkRelativeError( real64 const v1, real64 const v2, real64 const r
122122
EXPECT_PRED_FORMAT4( checkRelativeErrorFormat, v1, v2, relTol, absTol );
123123
}
124124

125-
template< typename ROW_INDEX, typename COL_INDEX, typename VALUE >
126-
void compareMatrixRow( ROW_INDEX const rowNumber, VALUE const relTol, VALUE const absTol,
125+
template< typename COL_INDEX, typename VALUE >
126+
void compareMatrixRow( VALUE const relTol, VALUE const absTol,
127127
localIndex const length1, COL_INDEX const * const indices1, VALUE const * const values1,
128128
localIndex const length2, COL_INDEX const * const indices2, VALUE const * const values2 )
129129
{
130-
SCOPED_TRACE( "Row " + std::to_string( rowNumber ));
131-
132130
EXPECT_EQ( length1, length2 );
133131

134132
for( localIndex j1 = 0, j2 = 0; j1 < length1 && j2 < length2; ++j1, ++j2 )
@@ -153,17 +151,31 @@ void compareMatrixRow( ROW_INDEX const rowNumber, VALUE const relTol, VALUE cons
153151
}
154152
}
155153

156-
template< typename ROW_INDEX, typename COL_INDEX, typename VALUE >
157-
void compareMatrixRow( ROW_INDEX const rowNumber, VALUE const relTol, VALUE const absTol,
158-
arraySlice1d< COL_INDEX const > indices1, arraySlice1d< VALUE const > values1,
159-
arraySlice1d< COL_INDEX const > indices2, arraySlice1d< VALUE const > values2 )
154+
template< typename T, typename COL_INDEX >
155+
void compareLocalMatrices( CRSMatrixView< T const, COL_INDEX const > const & matrix1,
156+
CRSMatrixView< T const, COL_INDEX const > const & matrix2,
157+
real64 const relTol = DEFAULT_REL_TOL,
158+
real64 const absTol = DEFAULT_ABS_TOL,
159+
globalIndex const rowOffset = 0 )
160160
{
161-
ASSERT_EQ( indices1.size(), values1.size() );
162-
ASSERT_EQ( indices2.size(), values2.size() );
161+
ASSERT_EQ( matrix1.numRows(), matrix2.numRows() );
162+
ASSERT_EQ( matrix1.numColumns(), matrix2.numColumns() );
163+
164+
matrix1.move( hostMemorySpace, false );
165+
matrix2.move( hostMemorySpace, false );
163166

164-
compareMatrixRow( rowNumber, relTol, absTol,
165-
indices1.size(), indices1.dataIfContiguous(), values1.dataIfContiguous(),
166-
indices2.size(), indices2.dataIfContiguous(), values2.dataIfContiguous() );
167+
// check the accuracy across local rows
168+
for( localIndex i = 0; i < matrix1.numRows(); ++i )
169+
{
170+
SCOPED_TRACE( GEOS_FMT( "Row {}", i + rowOffset ) );
171+
compareMatrixRow( relTol, absTol,
172+
matrix1.numNonZeros( i ),
173+
matrix1.getColumns( i ).dataIfContiguous(),
174+
matrix1.getEntries( i ).dataIfContiguous(),
175+
matrix2.numNonZeros( i ),
176+
matrix2.getColumns( i ).dataIfContiguous(),
177+
matrix2.getEntries( i ).dataIfContiguous() );
178+
}
167179
}
168180

169181
template< typename MATRIX >
@@ -178,45 +190,10 @@ void compareMatrices( MATRIX const & matrix1,
178190
ASSERT_EQ( matrix1.numLocalRows(), matrix2.numLocalRows() );
179191
ASSERT_EQ( matrix1.numLocalCols(), matrix2.numLocalCols() );
180192

181-
array1d< globalIndex > indices1, indices2;
182-
array1d< real64 > values1, values2;
183-
184-
// check the accuracy across local rows
185-
for( globalIndex i = matrix1.ilower(); i < matrix1.iupper(); ++i )
186-
{
187-
indices1.resize( matrix1.rowLength( i ) );
188-
values1.resize( matrix1.rowLength( i ) );
189-
matrix1.getRowCopy( i, indices1, values1 );
190-
191-
indices2.resize( matrix2.rowLength( i ) );
192-
values2.resize( matrix2.rowLength( i ) );
193-
matrix2.getRowCopy( i, indices2, values2 );
193+
CRSMatrix< real64, globalIndex > const mat1 = matrix1.extract();
194+
CRSMatrix< real64, globalIndex > const mat2 = matrix2.extract();
194195

195-
compareMatrixRow( i, relTol, absTol,
196-
indices1.size(), indices1.data(), values1.data(),
197-
indices2.size(), indices2.data(), values2.data() );
198-
}
199-
}
200-
201-
template< typename T, typename COL_INDEX >
202-
void compareLocalMatrices( CRSMatrixView< T const, COL_INDEX const > const & matrix1,
203-
CRSMatrixView< T const, COL_INDEX const > const & matrix2,
204-
real64 const relTol = DEFAULT_REL_TOL,
205-
real64 const absTol = DEFAULT_ABS_TOL )
206-
{
207-
ASSERT_EQ( matrix1.numRows(), matrix2.numRows() );
208-
ASSERT_EQ( matrix1.numColumns(), matrix2.numColumns() );
209-
210-
matrix1.move( hostMemorySpace, false );
211-
matrix2.move( hostMemorySpace, false );
212-
213-
// check the accuracy across local rows
214-
for( localIndex i = 0; i < matrix1.numRows(); ++i )
215-
{
216-
compareMatrixRow( i, relTol, absTol,
217-
matrix1.getColumns( i ), matrix1.getEntries( i ),
218-
matrix2.getColumns( i ), matrix2.getEntries( i ) );
219-
}
196+
compareLocalMatrices( mat1.toViewConst(), mat2.toViewConst(), relTol, absTol, matrix1.ilower() );
220197
}
221198

222199
} // namespace testing

src/coreComponents/common/DataTypes.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,12 @@ template< typename COL_INDEX, typename INDEX_TYPE=localIndex >
301301
using SparsityPatternView = LvArray::SparsityPatternView< COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer >;
302302

303303
/// Alias for CRS Matrix class.
304-
template< typename T, typename COL_INDEX=globalIndex >
305-
using CRSMatrix = LvArray::CRSMatrix< T, COL_INDEX, localIndex, LvArray::ChaiBuffer >;
304+
template< typename T, typename COL_INDEX=globalIndex, typename INDEX_TYPE=localIndex >
305+
using CRSMatrix = LvArray::CRSMatrix< T, COL_INDEX, INDEX_TYPE, LvArray::ChaiBuffer >;
306306

307307
/// Alias for CRS Matrix View.
308-
template< typename T, typename COL_INDEX=globalIndex >
309-
using CRSMatrixView = LvArray::CRSMatrixView< T, COL_INDEX, localIndex const, LvArray::ChaiBuffer >;
308+
template< typename T, typename COL_INDEX=globalIndex, typename INDEX_TYPE=localIndex >
309+
using CRSMatrixView = LvArray::CRSMatrixView< T, COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer >;
310310

311311
///@}
312312

src/coreComponents/common/GeosxConfig.hpp.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@
9898
/// Enables use of PETSc library (CMake option ENABLE_PETSC)
9999
#cmakedefine GEOS_USE_PETSC
100100

101+
/// Enables use of METIS library (CMake option ENABLE_METIS)
102+
#cmakedefine GEOSX_USE_METIS
103+
104+
/// Enables use of ParMETIS library (CMake option ENABLE_PARMETIS)
105+
#cmakedefine GEOSX_USE_PARMETIS
106+
101107
/// Enables use of Scotch library (CMake option ENABLE_SCOTCH)
102108
#cmakedefine GEOS_USE_SCOTCH
103109

src/coreComponents/common/MpiWrapper.hpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ struct MpiWrapper
382382
array1d< T > & recvbuf,
383383
MPI_Comm comm = MPI_COMM_GEOS );
384384

385+
template< typename T >
386+
static int allGatherv( arrayView1d< T const > const & sendbuf,
387+
array1d< T > & recvbuf,
388+
MPI_Comm comm = MPI_COMM_GEOS );
389+
385390
/**
386391
* @brief Convenience wrapper for the MPI_Allreduce function.
387392
* @tparam T type of data to reduce. Must correspond to a valid MPI_Datatype.
@@ -619,6 +624,22 @@ struct MpiWrapper
619624
MPI_Comm comm,
620625
MPI_Request * request );
621626

627+
/**
628+
* @brief Strongly typed wrapper around MPI_Send()
629+
* @param[in] buf The pointer to the buffer that contains the data to be sent.
630+
* @param[in] count The number of elements in \p buf.
631+
* @param[in] dest The rank of the destination process within \p comm.
632+
* @param[in] tag The message tag that is be used to distinguish different types of messages.
633+
* @param[in] comm The handle to the MPI_Comm.
634+
* @return
635+
*/
636+
template< typename T >
637+
static int send( T const * const buf,
638+
int count,
639+
int dest,
640+
int tag,
641+
MPI_Comm comm );
642+
622643
/**
623644
* @brief Strongly typed wrapper around MPI_Isend()
624645
* @param[in] buf The pointer to the buffer that contains the data to be sent.
@@ -985,6 +1006,38 @@ int MpiWrapper::allGather( arrayView1d< T const > const & sendValues,
9851006
#endif
9861007
}
9871008

1009+
template< typename T >
1010+
int MpiWrapper::allGatherv( arrayView1d< T const > const & sendValues,
1011+
array1d< T > & allValues,
1012+
MPI_Comm MPI_PARAM( comm ) )
1013+
{
1014+
int const sendSize = LvArray::integerConversion< int >( sendValues.size() );
1015+
#ifdef GEOS_USE_MPI
1016+
int const mpiSize = commSize( comm );
1017+
array1d< int > counts;
1018+
allGather( sendSize, counts, comm );
1019+
array1d< int > displs( mpiSize + 1 );
1020+
std::partial_sum( counts.begin(), counts.end(), displs.begin() + 1 );
1021+
allValues.resize( displs.back() );
1022+
return MPI_Allgatherv( sendValues.data(),
1023+
sendSize,
1024+
internal::getMpiType< T >(),
1025+
allValues.data(),
1026+
counts.data(),
1027+
displs.data(),
1028+
internal::getMpiType< T >(),
1029+
comm );
1030+
1031+
#else
1032+
allValues.resize( sendSize );
1033+
for( localIndex a=0; a<sendSize; ++a )
1034+
{
1035+
allValues[a] = sendValues[a];
1036+
}
1037+
return 0;
1038+
#endif
1039+
}
1040+
9881041
template< typename T >
9891042
int MpiWrapper::allReduce( T const * const sendbuf,
9901043
T * const recvbuf,
@@ -1239,6 +1292,20 @@ int MpiWrapper::iSend( arrayView1d< T > const & buf,
12391292
#endif
12401293
}
12411294

1295+
template< typename T >
1296+
int MpiWrapper::send( T const * const buf,
1297+
int count,
1298+
int dest,
1299+
int tag,
1300+
MPI_Comm comm )
1301+
{
1302+
#ifdef GEOS_USE_MPI
1303+
return MPI_Send( buf, count, internal::getMpiType< T >(), dest, tag, comm );
1304+
#else
1305+
GEOS_ERROR( "Not implemented without MPI" );
1306+
#endif
1307+
}
1308+
12421309
template< typename T >
12431310
int MpiWrapper::iSend( T const * const buf,
12441311
int count,

src/coreComponents/common/TimingMacros.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace timingHelpers
3535
{
3636
std::string input(prettyFunction);
3737
std::string::size_type const end = input.find_first_of( '(' );
38-
std::string::size_type const beg = input.find_last_of( ' ', end)+1;
38+
std::string::size_type const beg = input.find_last_of( ' ', end ) + 1;
3939
return input.substr( beg, end-beg );
4040
}
4141
}
@@ -96,10 +96,10 @@ namespace timingHelpers
9696
#include <iostream>
9797

9898
/// Mark a function or scope for timing with a given name
99-
#define GEOS_CALIPER_MARK_SCOPE(name) cali::Function __cali_ann##__LINE__(STRINGIZE_NX(name))
99+
#define GEOS_CALIPER_MARK_SCOPE(name) cali::Function GEOS_CONCAT(_cali_ann, __LINE__)(STRINGIZE_NX(name))
100100

101101
/// Mark a function for timing using a compiler-provided name
102-
#define GEOS_CALIPER_MARK_FUNCTION cali::Function __cali_ann##__func__(timingHelpers::stripPF(__PRETTY_FUNCTION__).c_str())
102+
#define GEOS_CALIPER_MARK_FUNCTION cali::Function _cali_ann_func(timingHelpers::stripPF(__PRETTY_FUNCTION__).c_str())
103103

104104
/// Mark the beginning of timed statement group
105105
#define GEOS_CALIPER_MARK_BEGIN(name) CALI_MARK_BEGIN(STRINGIZE(name))

src/coreComponents/linearAlgebra/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ set( linearAlgebra_headers
4444
solvers/PreconditionerBlockJacobi.hpp
4545
solvers/PreconditionerIdentity.hpp
4646
solvers/PreconditionerJacobi.hpp
47+
solvers/PreconditionerNull.hpp
48+
solvers/RichardsonSolver.hpp
4749
solvers/SeparateComponentPreconditioner.hpp
4850
utilities/Arnoldi.hpp
4951
utilities/BlockOperator.hpp
@@ -70,6 +72,7 @@ set( linearAlgebra_sources
7072
solvers/CgSolver.cpp
7173
solvers/GmresSolver.cpp
7274
solvers/KrylovSolver.cpp
75+
solvers/RichardsonSolver.cpp
7376
solvers/SeparateComponentPreconditioner.cpp
7477
utilities/ReverseCutHillMcKeeOrdering.cpp )
7578

0 commit comments

Comments
 (0)