Skip to content
Snippets Groups Projects
Commit 2dacdb31 authored by wenqing's avatar wenqing
Browse files

Changes with the comments by Nori, Tom and Lars

parent fc9407c9
No related branches found
No related tags found
No related merge requests found
/** /**
* @file DenseMatrix.tpp * @file DenseMatrix-imp.h
* @author Thomas Fischer and Haibing Shao * @author Thomas Fischer and Haibing Shao
* @date Jun 10, 2013 * @date Jun 10, 2013
* *
...@@ -54,7 +54,7 @@ DenseMatrix<FP_TYPE, IDX_TYPE>::~DenseMatrix () ...@@ -54,7 +54,7 @@ DenseMatrix<FP_TYPE, IDX_TYPE>::~DenseMatrix ()
} }
template <typename FP_TYPE, typename IDX_TYPE> template <typename FP_TYPE, typename IDX_TYPE>
FP_TYPE* DenseMatrix<FP_TYPE, IDX_TYPE>::getData() const const FP_TYPE* DenseMatrix<FP_TYPE, IDX_TYPE>::getEntries() const
{ {
return _data; return _data;
} }
......
...@@ -55,7 +55,7 @@ public: ...@@ -55,7 +55,7 @@ public:
/** /**
* Get the raw data directly * Get the raw data directly
*/ */
FP_TYPE *getData () const; const FP_TYPE *getEntries() const;
/** /**
* Assignment operator, makes a copy of the internal data of the object. * Assignment operator, makes a copy of the internal data of the object.
......
...@@ -18,36 +18,31 @@ ...@@ -18,36 +18,31 @@
namespace MathLib namespace MathLib
{ {
PETScMatrix::PETScMatrix (const PetscInt size, const PETScMatrixOption mat_opt) PETScMatrix::PETScMatrix (const PetscInt size, const PETScMatrixOption &mat_opt)
:_size(size), _n_loc_rows(PETSC_DECIDE), _n_loc_cols(mat_opt._n_local_cols)
{ {
_size = size; if(!mat_opt._is_global_size)
_loc_rows = PETSC_DECIDE;
_loc_cols = mat_opt._local_cols;
if(mat_opt._is_size_local_rows)
{ {
_size = PETSC_DECIDE; _size = PETSC_DECIDE;
_loc_rows = size; _n_loc_rows = size;
} }
MatCreate(PETSC_COMM_WORLD, &_A); MatCreate(PETSC_COMM_WORLD, &_A);
MatSetSizes(_A, _loc_rows, _loc_cols, _size, _size); MatSetSizes(_A, _n_loc_rows, _n_loc_cols, _size, _size);
MatSetFromOptions(_A); MatSetFromOptions(_A);
// for a dense matrix: MatSeqAIJSetPreallocation(_A, d_nz, PETSC_NULL); // for a dense matrix: MatSeqAIJSetPreallocation(_A, d_nz, PETSC_NULL);
MatMPIAIJSetPreallocation(_A, mat_opt._d_nz, PETSC_NULL, mat_opt._o_nz, PETSC_NULL); MatMPIAIJSetPreallocation(_A, mat_opt._d_nnz, PETSC_NULL, mat_opt._o_nnz, PETSC_NULL);
MatGetOwnershipRange(_A, &_start_rank, &_end_rank); MatGetOwnershipRange(_A, &_start_rank, &_end_rank);
MatGetSize(_A, &_size, PETSC_NULL); MatGetSize(_A, &_size, PETSC_NULL);
MatGetLocalSize(_A, &_loc_rows, &_loc_cols); MatGetLocalSize(_A, &_n_loc_rows, &_n_loc_cols);
} }
void PETScMatrix::setRowsColumnsZero(std::vector<PetscInt> const& row_pos) void PETScMatrix::setRowsColumnsZero(std::vector<PetscInt> const& row_pos)
{ {
// Each process indicates only rows it owns that are to be zeroed. // Each rank (compute core) processes only the rows that belong to the rank itself.
// If it is called, it must be called by all ranks of cores.
const PetscScalar one = 1.0; const PetscScalar one = 1.0;
const PetscInt nrows = static_cast<PetscInt> (row_pos.size()); const PetscInt nrows = static_cast<PetscInt> (row_pos.size());
......
...@@ -27,8 +27,6 @@ namespace MathLib ...@@ -27,8 +27,6 @@ namespace MathLib
{ {
/*! /*!
\class PETScVector
\brief Wrapper class for PETSc matrix routines \brief Wrapper class for PETSc matrix routines
*/ */
class PETScMatrix class PETScMatrix
...@@ -39,7 +37,7 @@ class PETScMatrix ...@@ -39,7 +37,7 @@ class PETScMatrix
\param size The dimension of the matrix. \param size The dimension of the matrix.
\param mat_op The configuration information for creating a matrix \param mat_op The configuration information for creating a matrix
*/ */
PETScMatrix(const PetscInt size, const PETScMatrixOption mat_op = PETScMatrixOption() ); PETScMatrix(const PetscInt size, const PETScMatrixOption &mat_op = PETScMatrixOption() );
~PETScMatrix() ~PETScMatrix()
{ {
...@@ -58,7 +56,7 @@ class PETScMatrix ...@@ -58,7 +56,7 @@ class PETScMatrix
} }
/// Get the dimension /// Get the dimension
PetscInt size() const PetscInt getDimension() const
{ {
return _size; return _size;
} }
...@@ -69,26 +67,26 @@ class PETScMatrix ...@@ -69,26 +67,26 @@ class PETScMatrix
return _start_rank; return _start_rank;
} }
/// Get the last global index of the row in the same rank /// Get the end global index of the rows in the same rank
PetscInt getRangeEnd() const PetscInt getRangeEnd() const
{ {
return _end_rank; return _end_rank;
} }
/// Get the number of local rows /// Get the number of local rows
PetscInt getLocalRows() const PetscInt getNLocalRows() const
{ {
return _loc_rows; return _n_loc_rows;
} }
/// Get the number of local columns /// Get the number of local columns
PetscInt getLocalColumns() const PetscInt getNLocalColumns() const
{ {
return _loc_cols; return _n_loc_cols;
} }
/// Get matrix reference /// Get matrix reference
PETSc_Mat &getData() PETSc_Mat &getRawMatrix()
{ {
return _A; return _A;
} }
...@@ -100,7 +98,9 @@ class PETScMatrix ...@@ -100,7 +98,9 @@ class PETScMatrix
} }
/* /*
\brief Set the specified rows and columns to zero except off-diagonal entries \brief Set the specified rows to zero except off-diagonal entries, i.e.
\f$A(k, j) = 0, j!=k, j=1,2,\cdots, n\f$, where \f$k \in \mbox{row\_pos}\f$
This fucntion must be called by all rank.
\param row_pos The row indicies of the specified rows. \param row_pos The row indicies of the specified rows.
*/ */
void setRowsColumnsZero(std::vector<PetscInt> const& row_pos); void setRowsColumnsZero(std::vector<PetscInt> const& row_pos);
...@@ -111,13 +111,13 @@ class PETScMatrix ...@@ -111,13 +111,13 @@ class PETScMatrix
\param vec_r The result vector, e.g. \f$ y \f$ \param vec_r The result vector, e.g. \f$ y \f$
Both of the two arguments must be created prior to be used. Both of the two arguments must be created prior to be used.
*/ */
void multVector(PETScVector &vec, PETScVector &vec_r) void multiVector(const PETScVector &vec, PETScVector &vec_r)
{ {
MatMult(_A, vec.getData(), vec_r.getData() ); MatMult(_A, vec.getData(), vec_r.getData() );
} }
/*! /*!
\brief Insert a single entry with value. \brief Set a single entry with a value.
\param i The row index \param i The row index
\param j The column index \param j The column index
\param value The entry value \param value The entry value
...@@ -179,12 +179,12 @@ class PETScMatrix ...@@ -179,12 +179,12 @@ class PETScMatrix
/// PETSc matrix /// PETSc matrix
PETSc_Mat _A; PETSc_Mat _A;
/// Dimension /// Dimension of matrix
PetscInt _size; PetscInt _size;
/// Number of the local rows /// Number of the local rows
PetscInt _loc_rows; PetscInt _n_loc_rows;
/// Number of the local columns /// Number of the local columns
PetscInt _loc_cols; PetscInt _n_loc_cols;
/// Starting index in a rank /// Starting index in a rank
PetscInt _start_rank; PetscInt _start_rank;
...@@ -208,7 +208,7 @@ void PETScMatrix::add(std::vector<PetscInt> const& row_pos, ...@@ -208,7 +208,7 @@ void PETScMatrix::add(std::vector<PetscInt> const& row_pos,
const PetscInt nrows = static_cast<PetscInt> (row_pos.size()); const PetscInt nrows = static_cast<PetscInt> (row_pos.size());
const PetscInt ncols = static_cast<PetscInt> (col_pos.size()); const PetscInt ncols = static_cast<PetscInt> (col_pos.size());
MatSetValues(_A, nrows, &row_pos[0], ncols, &col_pos[0], sub_mat.getData(), ADD_VALUES); MatSetValues(_A, nrows, &row_pos[0], ncols, &col_pos[0], sub_mat.getEntries(), ADD_VALUES);
}; };
/*! /*!
......
...@@ -19,38 +19,37 @@ ...@@ -19,38 +19,37 @@
namespace MathLib namespace MathLib
{ {
/*! /*!
\struct PETScMatrixOption
\brief This a struct data containing the configuration information to create a PETSc type matrix \brief This a struct data containing the configuration information to create a PETSc type matrix
*/ */
struct PETScMatrixOption struct PETScMatrixOption
{ {
PETScMatrixOption() : _is_size_local_rows(false), _local_cols(PETSC_DECIDE), PETScMatrixOption() : _is_global_size(true), _n_local_cols(PETSC_DECIDE),
_d_nz(10), _o_nz(10) _d_nnz(PETSC_DECIDE), _o_nnz(PETSC_DECIDE)
{ } { }
/*! /*!
\brief Flag for the type of the first argument of \brief Flag for the type of size, which is one of arguments of
the constructor of class PETScMatrix, size. the constructor of class PETScMatrix
true: the size is the number of local rows, true: the size is the number of local rows,
false: the size is the number of global rows. false: the size is the number of global rows.
The default is false. The default is false.
*/ */
bool _is_size_local_rows; bool _is_global_size;
/// Number of local columns. The default is PETSC_DECIDE. /// Number of local columns. The default is PETSC_DECIDE.
PetscInt _local_cols; PetscInt _n_local_cols;
/*! /*!
\brief Number of nonzeros per row in DIAGONAL portion of local submatrix \brief Number of nonzeros per row in DIAGONAL portion of local submatrix
(same value is used for all local rows), the default is 10 (same value is used for all local rows), the default is PETSC_DECIDE
*/ */
PetscInt _d_nz; PetscInt _d_nnz;
/*! /*!
\brief Number of nonzeros per row in the OFF-DIAGONAL portion of local submatrix \brief Number of nonzeros per row in the OFF-DIAGONAL portion of local submatrix
(same value is used for all local rows), the default is 10 (same value is used for all local rows), the default is PETSC_DECIDE
*/ */
PetscInt _o_nz; PetscInt _o_nnz;
}; };
} // end namespace } // end namespace
......
...@@ -39,7 +39,7 @@ class PETScVector ...@@ -39,7 +39,7 @@ class PETScVector
/*! /*!
\brief Constructor \brief Constructor
\param vec_size The size of the vector, either global or local \param vec_size The size of the vector, either global or local
\param is_global_size The flag of the type of vec_size, i.e. whether it is a global size \param is_global_size The flag of the type of vec_size, i.e. whether it is a global size
or local size. The default is true. or local size. The default is true.
*/ */
PETScVector(const PetscInt vec_size, const bool is_global_size = true); PETScVector(const PetscInt vec_size, const bool is_global_size = true);
...@@ -179,7 +179,7 @@ class PETScVector ...@@ -179,7 +179,7 @@ class PETScVector
} }
/// Get PETsc vector. Use it only for test purpose /// Get PETsc vector. Use it only for test purpose
PETSc_Vec &getData() const PETSc_Vec &getData() const
{ {
return _v; return _v;
} }
......
...@@ -42,7 +42,7 @@ void checkGlobalMatrixInterface(T_MATRIX &m) ...@@ -42,7 +42,7 @@ void checkGlobalMatrixInterface(T_MATRIX &m)
m.add(0, 0, 1.0); m.add(0, 0, 1.0);
m.setZero(); m.setZero();
MathLib::DenseMatrix<double, short> local_m(2, 2, 1.0); MathLib::DenseMatrix<double> local_m(2, 2, 1.0);
std::vector<std::size_t> vec_pos(2); std::vector<std::size_t> vec_pos(2);
vec_pos[0] = 1; vec_pos[0] = 1;
vec_pos[1] = 3; vec_pos[1] = 3;
...@@ -61,16 +61,16 @@ void checkGlobalMatrixInterfaceMPI(T_MATRIX &m, T_VECTOR &v) ...@@ -61,16 +61,16 @@ void checkGlobalMatrixInterfaceMPI(T_MATRIX &m, T_VECTOR &v)
MPI_Comm_rank(PETSC_COMM_WORLD, &mrank); MPI_Comm_rank(PETSC_COMM_WORLD, &mrank);
ASSERT_EQ(3u, msize); ASSERT_EQ(3u, msize);
ASSERT_EQ(6u, m.size()); ASSERT_EQ(6u, m.getDimension());
ASSERT_EQ(m.getRangeEnd()-m.getRangeBegin(), m.getLocalRows()); ASSERT_EQ(m.getRangeEnd()-m.getRangeBegin(), m.getNLocalRows());
int gathered_cols; int gathered_cols;
int local_cols = m.getLocalColumns(); int local_cols = m.getNLocalColumns();
MPI_Allreduce(&local_cols, &gathered_cols, 1, MPI_INT, MPI_SUM, PETSC_COMM_WORLD); MPI_Allreduce(&local_cols, &gathered_cols, 1, MPI_INT, MPI_SUM, PETSC_COMM_WORLD);
ASSERT_EQ(6u, gathered_cols); ASSERT_EQ(6u, gathered_cols);
// Add entries // Add entries
MathLib::DenseMatrix<double, short> loc_m(2); MathLib::DenseMatrix<double> loc_m(2, 2);
loc_m(0, 0) = 1.; loc_m(0, 0) = 1.;
loc_m(0, 1) = 2.; loc_m(0, 1) = 2.;
loc_m(1, 0) = 3.; loc_m(1, 0) = 3.;
...@@ -91,7 +91,7 @@ void checkGlobalMatrixInterfaceMPI(T_MATRIX &m, T_VECTOR &v) ...@@ -91,7 +91,7 @@ void checkGlobalMatrixInterfaceMPI(T_MATRIX &m, T_VECTOR &v)
v = 1.; v = 1.;
const bool deep_copy = false; const bool deep_copy = false;
T_VECTOR y(v, deep_copy); T_VECTOR y(v, deep_copy);
m.multVector(v, y); m.multiVector(v, y);
ASSERT_EQ(sqrt(3*(3*3 + 7*7)), y.getNorm()); ASSERT_EQ(sqrt(3*(3*3 + 7*7)), y.getNorm());
...@@ -102,7 +102,7 @@ void checkGlobalMatrixInterfaceMPI(T_MATRIX &m, T_VECTOR &v) ...@@ -102,7 +102,7 @@ void checkGlobalMatrixInterfaceMPI(T_MATRIX &m, T_VECTOR &v)
m.add(1, 1, 5.0); m.add(1, 1, 5.0);
} }
MathLib::finalizeMatrixAssembly(m); MathLib::finalizeMatrixAssembly(m);
m.multVector(v, y); m.multiVector(v, y);
ASSERT_EQ(sqrt((2*3*3 + 8*8 + 3*7*7)), y.getNorm()); ASSERT_EQ(sqrt((2*3*3 + 8*8 + 3*7*7)), y.getNorm());
} }
...@@ -128,10 +128,10 @@ TEST(Math, CheckInterface_LisMatrix) ...@@ -128,10 +128,10 @@ TEST(Math, CheckInterface_LisMatrix)
TEST(Math, CheckInterface_PETScMatrix_Local_Size) TEST(Math, CheckInterface_PETScMatrix_Local_Size)
{ {
MathLib::PETScMatrixOption opt; MathLib::PETScMatrixOption opt;
opt._d_nz = 2; opt._d_nnz = 2;
opt._o_nz = 0; opt._o_nnz = 0;
opt._is_size_local_rows = true; opt._is_global_size = false;
opt._local_cols = 2; opt._n_local_cols = 2;
MathLib::PETScMatrix A(2, opt); MathLib::PETScMatrix A(2, opt);
const bool is_gloabal_size = false; const bool is_gloabal_size = false;
...@@ -142,8 +142,8 @@ TEST(Math, CheckInterface_PETScMatrix_Local_Size) ...@@ -142,8 +142,8 @@ TEST(Math, CheckInterface_PETScMatrix_Local_Size)
TEST(Math, CheckInterface_PETScMatrix_Global_Size) TEST(Math, CheckInterface_PETScMatrix_Global_Size)
{ {
MathLib::PETScMatrixOption opt; MathLib::PETScMatrixOption opt;
opt._d_nz = 2; opt._d_nnz = 2;
opt._o_nz = 0; opt._o_nnz = 0;
MathLib::PETScMatrix A(6, opt); MathLib::PETScMatrix A(6, opt);
MathLib::PETScVector x(6); MathLib::PETScVector x(6);
......
...@@ -120,6 +120,10 @@ ENDIF() ...@@ -120,6 +120,10 @@ ENDIF()
IF(OGS_USE_PETSC) IF(OGS_USE_PETSC)
MESSAGE (STATUS "Configuring for PETSc" ) MESSAGE (STATUS "Configuring for PETSc" )
##Force CMake to accept a given PETSc configuration in case the failure of MPI tests
##This may cause the compilation broken.
SET(PETSC_EXECUTABLE_RUNS YES)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/scripts/cmake/findPETSC") SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/scripts/cmake/findPETSC")
FIND_PACKAGE(PETSc REQUIRED) FIND_PACKAGE(PETSc REQUIRED)
......
...@@ -320,12 +320,6 @@ int main(int argc,char *argv[]) { ...@@ -320,12 +320,6 @@ int main(int argc,char *argv[]) {
mark_as_advanced (PETSC_INCLUDES PETSC_LIBRARIES PETSC_COMPILER PETSC_DEFINITIONS PETSC_MPIEXEC PETSC_EXECUTABLE_RUNS) mark_as_advanced (PETSC_INCLUDES PETSC_LIBRARIES PETSC_COMPILER PETSC_DEFINITIONS PETSC_MPIEXEC PETSC_EXECUTABLE_RUNS)
endif () endif ()
# message (STATUS "dddd---${PETSC_INCLUDES}--${PETSC_LIBRARIES}-- ${petsc_includes_minimal} ")
# message (STATUS "dddd---${PETSC_EXECUTABLE_RUNS} ggggg ${PETSC_DEFINITIONS}")
set (PETSC_EXECUTABLE_RUNS "YES" CACHE BOOL
"Can the system successfully run a PETSc executable? This variable can be manually set to \"YES\" to force CMake to accept a given PETSc configuration, but this will almost always result in a broken build. If you change PETSC_DIR, PETSC_ARCH, or PETSC_CURRENT you would have to reset this variable." FORCE)
include (FindPackageHandleStandardArgs) include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (PETSc find_package_handle_standard_args (PETSc
"PETSc could not be found. Be sure to set PETSC_DIR and PETSC_ARCH." "PETSc could not be found. Be sure to set PETSC_DIR and PETSC_ARCH."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment