Skip to content

Commit dfbc927

Browse files
committed
Linear algebra changes
1 parent 991327d commit dfbc927

80 files changed

Lines changed: 2486 additions & 940 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.

src/cmake/GeosxConfig.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ function( make_full_config_file
7777
set( GEOSX_LA_INTERFACE_HYPRE ON )
7878
set( GEOSX_LA_INTERFACE_TRILINOS OFF )
7979
set( GEOSX_LA_INTERFACE_PETSC OFF )
80+
set( Python3_VERSION "3.10.8" )
8081

8182
configure_file( ${CMAKE_SOURCE_DIR}/coreComponents/common/GeosxConfig.hpp.in
8283
${CMAKE_SOURCE_DIR}/docs/doxygen/GeosxConfig.hpp )

src/coreComponents/codingUtilities/UnitTestUtilities.hpp

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

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

133131
for( localIndex j1 = 0, j2 = 0; j1 < length1 && j2 < length2; ++j1, ++j2 )
@@ -152,17 +150,31 @@ void compareMatrixRow( ROW_INDEX const rowNumber, VALUE const relTol, VALUE cons
152150
}
153151
}
154152

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

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

168180
template< typename MATRIX >
@@ -177,45 +189,10 @@ void compareMatrices( MATRIX const & matrix1,
177189
ASSERT_EQ( matrix1.numLocalRows(), matrix2.numLocalRows() );
178190
ASSERT_EQ( matrix1.numLocalCols(), matrix2.numLocalCols() );
179191

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

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

221198
} // namespace testing

src/coreComponents/common/DataTypes.hpp

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

340340
/// Alias for CRS Matrix class.
341-
template< typename T, typename COL_INDEX=globalIndex >
342-
using CRSMatrix = LvArray::CRSMatrix< T, COL_INDEX, localIndex, LvArray::ChaiBuffer >;
341+
template< typename T, typename COL_INDEX=globalIndex, typename INDEX_TYPE=localIndex >
342+
using CRSMatrix = LvArray::CRSMatrix< T, COL_INDEX, INDEX_TYPE, LvArray::ChaiBuffer >;
343343

344344
/// Alias for CRS Matrix View.
345-
template< typename T, typename COL_INDEX=globalIndex >
346-
using CRSMatrixView = LvArray::CRSMatrixView< T, COL_INDEX, localIndex const, LvArray::ChaiBuffer >;
345+
template< typename T, typename COL_INDEX=globalIndex, typename INDEX_TYPE=localIndex >
346+
using CRSMatrixView = LvArray::CRSMatrixView< T, COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer >;
347347

348348
///@}
349349

src/coreComponents/common/GeosxConfig.hpp.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@
8989
/// Enables use of PETSc library (CMake option ENABLE_PETSC)
9090
#cmakedefine GEOSX_USE_PETSC
9191

92+
/// Enables use of METIS library (CMake option ENABLE_METIS)
93+
#cmakedefine GEOSX_USE_METIS
94+
95+
/// Enables use of ParMETIS library (CMake option ENABLE_PARMETIS)
96+
#cmakedefine GEOSX_USE_PARMETIS
97+
9298
/// Enables use of Scotch library (CMake option ENABLE_SCOTCH)
9399
#cmakedefine GEOSX_USE_SCOTCH
94100

src/coreComponents/common/MpiWrapper.hpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "common/Span.hpp"
2323
#include "mesh/ElementType.hpp"
2424

25+
#include <numeric>
26+
2527
#if defined(GEOSX_USE_MPI)
2628
#include <mpi.h>
2729
#define MPI_PARAM( x ) x
@@ -337,6 +339,11 @@ struct MpiWrapper
337339
array1d< T > & recvbuf,
338340
MPI_Comm comm = MPI_COMM_GEOSX );
339341

342+
template< typename T >
343+
static int allGatherv( arrayView1d< T const > const & sendbuf,
344+
array1d< T > & recvbuf,
345+
MPI_Comm comm = MPI_COMM_GEOSX );
346+
340347
/**
341348
* @brief Strongly typed wrapper around MPI_Allreduce.
342349
* @param[in] sendbuf The pointer to the sending buffer.
@@ -459,6 +466,22 @@ struct MpiWrapper
459466
MPI_Comm comm,
460467
MPI_Request * request );
461468

469+
/**
470+
* @brief Strongly typed wrapper around MPI_Send()
471+
* @param[in] buf The pointer to the buffer that contains the data to be sent.
472+
* @param[in] count The number of elements in \p buf.
473+
* @param[in] dest The rank of the destination process within \p comm.
474+
* @param[in] tag The message tag that is be used to distinguish different types of messages.
475+
* @param[in] comm The handle to the MPI_Comm.
476+
* @return
477+
*/
478+
template< typename T >
479+
static int send( T const * const buf,
480+
int count,
481+
int dest,
482+
int tag,
483+
MPI_Comm comm );
484+
462485
/**
463486
* @brief Strongly typed wrapper around MPI_Isend()
464487
* @param[in] buf The pointer to the buffer that contains the data to be sent.
@@ -713,6 +736,38 @@ int MpiWrapper::allGather( arrayView1d< T const > const & sendValues,
713736
#endif
714737
}
715738

739+
template< typename T >
740+
int MpiWrapper::allGatherv( arrayView1d< T const > const & sendValues,
741+
array1d< T > & allValues,
742+
MPI_Comm MPI_PARAM( comm ) )
743+
{
744+
int const sendSize = LvArray::integerConversion< int >( sendValues.size() );
745+
#ifdef GEOSX_USE_MPI
746+
int const mpiSize = commSize( comm );
747+
array1d< int > counts;
748+
allGather( sendSize, counts, comm );
749+
array1d< int > displs( mpiSize + 1 );
750+
std::partial_sum( counts.begin(), counts.end(), displs.begin() + 1 );
751+
allValues.resize( displs.back() );
752+
return MPI_Allgatherv( sendValues.data(),
753+
sendSize,
754+
internal::getMpiType< T >(),
755+
allValues.data(),
756+
counts.data(),
757+
displs.data(),
758+
internal::getMpiType< T >(),
759+
comm );
760+
761+
#else
762+
allValues.resize( sendSize );
763+
for( localIndex a=0; a<sendSize; ++a )
764+
{
765+
allValues[a] = sendValues[a];
766+
}
767+
return 0;
768+
#endif
769+
}
770+
716771
template< typename T >
717772
int MpiWrapper::allReduce( T const * const sendbuf,
718773
T * const recvbuf,
@@ -928,6 +983,20 @@ int MpiWrapper::iSend( arrayView1d< T > const & buf,
928983
#endif
929984
}
930985

986+
template< typename T >
987+
int MpiWrapper::send( T const * const buf,
988+
int count,
989+
int dest,
990+
int tag,
991+
MPI_Comm comm )
992+
{
993+
#ifdef GEOSX_USE_MPI
994+
return MPI_Send( buf, count, internal::getMpiType< T >(), dest, tag, comm );
995+
#else
996+
GEOS_ERROR( "Not implemented without MPI" );
997+
#endif
998+
}
999+
9311000
template< typename T >
9321001
int MpiWrapper::iSend( T const * const buf,
9331002
int count,

src/coreComponents/common/TimingMacros.hpp

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

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

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

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

src/coreComponents/linearAlgebra/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ set( linearAlgebra_headers
2121
solvers/PreconditionerBlockJacobi.hpp
2222
solvers/PreconditionerIdentity.hpp
2323
solvers/PreconditionerJacobi.hpp
24+
solvers/PreconditionerNull.hpp
25+
solvers/RichardsonSolver.hpp
2426
solvers/SeparateComponentPreconditioner.hpp
2527
utilities/Arnoldi.hpp
2628
utilities/BlockOperator.hpp
@@ -49,8 +51,9 @@ set( linearAlgebra_sources
4951
solvers/CgSolver.cpp
5052
solvers/GmresSolver.cpp
5153
solvers/KrylovSolver.cpp
54+
solvers/RichardsonSolver.cpp
5255
solvers/SeparateComponentPreconditioner.cpp
53-
utilities/ReverseCutHillMcKeeOrdering.cpp
56+
utilities/ReverseCutHillMcKeeOrdering.cpp
5457
)
5558

5659
set( dependencyList ${parallelDeps} mesh denseLinearAlgebra )

0 commit comments

Comments
 (0)