Skip to content

Commit 2bb59cd

Browse files
committed
Linear algebra changes
1 parent 39e75de commit 2bb59cd

File tree

80 files changed

+2479
-935
lines changed

Some content is hidden

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

80 files changed

+2479
-935
lines changed

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
@@ -342,12 +342,12 @@ template< typename COL_INDEX, typename INDEX_TYPE=localIndex >
342342
using SparsityPatternView = LvArray::SparsityPatternView< COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer >;
343343

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

348348
/// Alias for CRS Matrix View.
349-
template< typename T, typename COL_INDEX=globalIndex >
350-
using CRSMatrixView = LvArray::CRSMatrixView< T, COL_INDEX, localIndex const, LvArray::ChaiBuffer >;
349+
template< typename T, typename COL_INDEX=globalIndex, typename INDEX_TYPE=localIndex >
350+
using CRSMatrixView = LvArray::CRSMatrixView< T, COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer >;
351351

352352
///@}
353353

src/coreComponents/common/GeosxConfig.hpp.in

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

86+
/// Enables use of METIS library (CMake option ENABLE_METIS)
87+
#cmakedefine GEOSX_USE_METIS
88+
89+
/// Enables use of ParMETIS library (CMake option ENABLE_PARMETIS)
90+
#cmakedefine GEOSX_USE_PARMETIS
91+
8692
/// Enables use of Scotch library (CMake option ENABLE_SCOTCH)
8793
#cmakedefine GEOSX_USE_SCOTCH
8894

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
@@ -343,6 +345,11 @@ struct MpiWrapper
343345
array1d< T > & recvbuf,
344346
MPI_Comm comm = MPI_COMM_GEOSX );
345347

348+
template< typename T >
349+
static int allGatherv( arrayView1d< T const > const & sendbuf,
350+
array1d< T > & recvbuf,
351+
MPI_Comm comm = MPI_COMM_GEOSX );
352+
346353
/**
347354
* @brief Strongly typed wrapper around MPI_Allreduce.
348355
* @param[in] sendbuf The pointer to the sending buffer.
@@ -522,6 +529,22 @@ struct MpiWrapper
522529
MPI_Comm comm,
523530
MPI_Request * request );
524531

532+
/**
533+
* @brief Strongly typed wrapper around MPI_Send()
534+
* @param[in] buf The pointer to the buffer that contains the data to be sent.
535+
* @param[in] count The number of elements in \p buf.
536+
* @param[in] dest The rank of the destination process within \p comm.
537+
* @param[in] tag The message tag that is be used to distinguish different types of messages.
538+
* @param[in] comm The handle to the MPI_Comm.
539+
* @return
540+
*/
541+
template< typename T >
542+
static int send( T const * const buf,
543+
int count,
544+
int dest,
545+
int tag,
546+
MPI_Comm comm );
547+
525548
/**
526549
* @brief Strongly typed wrapper around MPI_Isend()
527550
* @param[in] buf The pointer to the buffer that contains the data to be sent.
@@ -754,6 +777,38 @@ int MpiWrapper::allGather( arrayView1d< T const > const & sendValues,
754777
#endif
755778
}
756779

780+
template< typename T >
781+
int MpiWrapper::allGatherv( arrayView1d< T const > const & sendValues,
782+
array1d< T > & allValues,
783+
MPI_Comm MPI_PARAM( comm ) )
784+
{
785+
int const sendSize = LvArray::integerConversion< int >( sendValues.size() );
786+
#ifdef GEOSX_USE_MPI
787+
int const mpiSize = commSize( comm );
788+
array1d< int > counts;
789+
allGather( sendSize, counts, comm );
790+
array1d< int > displs( mpiSize + 1 );
791+
std::partial_sum( counts.begin(), counts.end(), displs.begin() + 1 );
792+
allValues.resize( displs.back() );
793+
return MPI_Allgatherv( sendValues.data(),
794+
sendSize,
795+
internal::getMpiType< T >(),
796+
allValues.data(),
797+
counts.data(),
798+
displs.data(),
799+
internal::getMpiType< T >(),
800+
comm );
801+
802+
#else
803+
allValues.resize( sendSize );
804+
for( localIndex a=0; a<sendSize; ++a )
805+
{
806+
allValues[a] = sendValues[a];
807+
}
808+
return 0;
809+
#endif
810+
}
811+
757812
template< typename T >
758813
int MpiWrapper::allReduce( T const * const sendbuf,
759814
T * const recvbuf,
@@ -989,6 +1044,20 @@ int MpiWrapper::iSend( arrayView1d< T > const & buf,
9891044
#endif
9901045
}
9911046

1047+
template< typename T >
1048+
int MpiWrapper::send( T const * const buf,
1049+
int count,
1050+
int dest,
1051+
int tag,
1052+
MPI_Comm comm )
1053+
{
1054+
#ifdef GEOSX_USE_MPI
1055+
return MPI_Send( buf, count, internal::getMpiType< T >(), dest, tag, comm );
1056+
#else
1057+
GEOS_ERROR( "Not implemented without MPI" );
1058+
#endif
1059+
}
1060+
9921061
template< typename T >
9931062
int MpiWrapper::iSend( T const * const buf,
9941063
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ set( linearAlgebra_headers
1919
solvers/PreconditionerBlockJacobi.hpp
2020
solvers/PreconditionerIdentity.hpp
2121
solvers/PreconditionerJacobi.hpp
22+
solvers/PreconditionerNull.hpp
23+
solvers/RichardsonSolver.hpp
2224
solvers/SeparateComponentPreconditioner.hpp
2325
utilities/Arnoldi.hpp
2426
utilities/BlockOperator.hpp
@@ -44,6 +46,7 @@ set( linearAlgebra_sources
4446
solvers/CgSolver.cpp
4547
solvers/GmresSolver.cpp
4648
solvers/KrylovSolver.cpp
49+
solvers/RichardsonSolver.cpp
4750
solvers/SeparateComponentPreconditioner.cpp
4851
utilities/ReverseCutHillMcKeeOrdering.cpp )
4952

0 commit comments

Comments
 (0)