Commit a6125f71 authored by DIAZ Jerome's avatar DIAZ Jerome Committed by GILLES Sebastien
Browse files

#1486 Added most of the PETSc wrappers for the valgrind memcheck test.

parent 8e30b68b
......@@ -35,108 +35,205 @@ namespace MoReFEM::TestNS::PetscNS::MatrixOperationsNS
decltype(auto) numbering_subset = god_of_dof.GetNumberingSubset(1);
decltype(auto) mpi = god_of_dof.GetMpi();
vector_ = std::make_unique<GlobalVector>(numbering_subset);
auto& vector = *vector_;
vector_init_1_ = std::make_unique<GlobalVector>(numbering_subset);
vector_init_2_ = std::make_unique<GlobalVector>(numbering_subset);
vector_init_3_ = std::make_unique<GlobalVector>(numbering_subset);
AllocateGlobalVector(god_of_dof, vector);
matrix_a_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
matrix_b_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
matrix_c_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
matrix_d_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
auto& matrix_a = *matrix_a_;
auto& matrix_b = *matrix_b_;
auto& matrix_c = *matrix_c_; // no initiliazation
auto& matrix_d = *matrix_d_; // no initiliazation
AllocateGlobalMatrix(god_of_dof, matrix_a);
AllocateGlobalMatrix(god_of_dof, matrix_b);
auto& vector_init_1 = *vector_init_1_;
auto& vector_init_2 = *vector_init_2_;
auto& vector_init_3 = *vector_init_3_;
AllocateGlobalVector(god_of_dof, vector_init_1);
AllocateGlobalVector(god_of_dof, vector_init_2);
AllocateGlobalVector(god_of_dof, vector_init_3);
matrix_init_1_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
matrix_init_2_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
matrix_init_3_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
matrix_4_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
matrix_5_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
matrix_6_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
matrix_7_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
matrix_8_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
matrix_9_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
matrix_10_ = std::make_unique<GlobalMatrix>(numbering_subset, numbering_subset);
auto& matrix_init_1 = *matrix_init_1_;
auto& matrix_init_2 = *matrix_init_2_;
auto& matrix_init_3 = *matrix_init_3_;
// no initialization for the following matrices:
auto& matrix_4 = *matrix_4_;
auto& matrix_5 = *matrix_5_;
auto& matrix_6 = *matrix_6_;
auto& matrix_7 = *matrix_7_;
auto& matrix_8 = *matrix_8_;
auto& matrix_9 = *matrix_9_;
auto& matrix_10 = *matrix_10_;
// only three matrices allocated, all the others are set to PETSC_NULL
AllocateGlobalMatrix(god_of_dof, matrix_init_1);
AllocateGlobalMatrix(god_of_dof, matrix_init_2);
AllocateGlobalMatrix(god_of_dof, matrix_init_3);
{
Wrappers::Petsc::AccessVectorContent<Utilities::Access::read_and_write> content(vector,
Wrappers::Petsc::AccessVectorContent<Utilities::Access::read_and_write> content(vector_init_1,
__FILE__, __LINE__);
const auto size = content.GetSize(__FILE__, __LINE__);
const auto rank_plus_one = static_cast<double>(1 + mpi.GetRank<int>());
for (auto i = 0u; i < size; ++i)
content[i] = rank_plus_one * std::sqrt(i); // completely arbitrary value with no redundancy!
Wrappers::Petsc::MatMatMult(matrix_a,
matrix_b,
matrix_c,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::no);
// First all wrappers that do not use a DeReuseMatrix policy
Wrappers::Petsc::MatCreateTranspose(matrix_init_1,
matrix_4,
__FILE__, __LINE__);
Wrappers::Petsc::AXPY<NonZeroPattern::same>(1.,
matrix_init_1,
matrix_init_2,
__FILE__, __LINE__);
Wrappers::Petsc::MatShift(1.,
matrix_init_1,
__FILE__, __LINE__);
Wrappers::Petsc::MatMatMult(matrix_a,
matrix_b,
matrix_c,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::yes);
Wrappers::Petsc::MatTranspose(matrix_a,
matrix_d,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::no);
Wrappers::Petsc::MatMult(matrix_init_1,
vector_init_1,
vector_init_2,
__FILE__, __LINE__);
Wrappers::Petsc::MatTranspose(matrix_a,
matrix_d,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::yes);
Wrappers::Petsc::MatMultAdd(matrix_init_1,
vector_init_1,
vector_init_2,
vector_init_3,
__FILE__, __LINE__);
// std::cout << "Before in place transpose" << std::endl;
// matrix_a.View(mpi, __FILE__, __LINE__);
Wrappers::Petsc::MatTranspose(matrix_a,
matrix_a,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::in_place);
// std::cout << "After inplace transpose" << std::endl;
// matrix_a.View(mpi, __FILE__, __LINE__);
// Wrappers::Petsc::MatCreateTranspose(matrix_a,
// matrix_b,
// __FILE__, __LINE__);
/*
*
* All Petsc wrappers that construct an intermediate
* Mat result
*
*/
Wrappers::Petsc::MatMultTranspose(matrix_init_1,
vector_init_1,
vector_init_2,
__FILE__, __LINE__);
Wrappers::Petsc::MatMultTransposeAdd(matrix_init_1,
vector_init_1,
vector_init_2,
vector_init_3,
__FILE__, __LINE__);
// Petsc wrappers that have a DoReuseMatrix policy
{
Wrappers::Petsc::MatTranspose(matrix_init_1,
matrix_5,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::no);
Wrappers::Petsc::MatTranspose(matrix_init_1,
matrix_5,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::yes);
Wrappers::Petsc::MatTranspose(matrix_init_1,
matrix_init_1,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::in_place);
}
{
Wrappers::Petsc::MatMatMult(matrix_init_1,
matrix_init_2,
matrix_6,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::no);
Wrappers::Petsc::MatMatMult(matrix_init_1,
matrix_init_2,
matrix_6,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::yes);
}
{
Wrappers::Petsc::MatTransposeMatMult(matrix_init_1,
matrix_init_2,
matrix_7,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::no);
// MatTranspose(MatrixT& matrix1,
// MatrixU& matrix2,
// const char* invoking_file, int invoking_line)
//
// MatCreateTranspose(const MatrixT& A,
// MatrixU& transpose,
// const char* invoking_file, int invoking_line)
//
// MatTransposeMatMult(const MatrixT& matrix1,
// const MatrixU& matrix2,
// MatrixV& matrix3,
// const char* invoking_file, int invoking_line,
// DoReuseMatrix do_reuse_matrix) // C = A' * B
//
// MatMatTransposeMult(const MatrixT& matrix1,
// const MatrixU& matrix2,
// MatrixV& matrix3,
// const char* invoking_file, int invoking_line,
// DoReuseMatrix do_reuse_matrix) // C = A * B'
//
// MatMatMatMult(const MatrixT& matrix1,
// const MatrixU& matrix2,
// const MatrixV& matrix3,
// MatrixW& out,
// const char* invoking_file, int invoking_line,
// DoReuseMatrix do_reuse_matrix) // D = A * B * C
//
// PtAP(const MatrixT& A,
// const MatrixU& P,
// MatrixV& out,
// const char* invoking_file, int invoking_line,
// DoReuseMatrix do_reuse_matrix = DoReuseMatrix::no); // B = P' * A * P
Wrappers::Petsc::MatTransposeMatMult(matrix_init_1,
matrix_init_2,
matrix_7,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::yes);
}
{
Wrappers::Petsc::MatMatTransposeMult(matrix_init_1,
matrix_init_2,
matrix_8,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::no);
Wrappers::Petsc::MatMatTransposeMult(matrix_init_1,
matrix_init_2,
matrix_8,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::yes);
}
{
Wrappers::Petsc::PtAP(matrix_init_1,
matrix_init_2,
matrix_9,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::no);
Wrappers::Petsc::PtAP(matrix_init_1,
matrix_init_2,
matrix_9,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::yes);
}
{
Wrappers::Petsc::MatMatMatMult(matrix_init_1,
matrix_init_2,
matrix_init_3,
matrix_10,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::no);
Wrappers::Petsc::MatMatMatMult(matrix_init_1,
matrix_init_2,
matrix_init_3,
matrix_10,
__FILE__, __LINE__,
Wrappers::Petsc::DoReuseMatrix::yes);
}
// todo
// IS *rperm;
// IS *cperm;
// Wrappers::Petsc::GetOrdering(matrix_init_1,
// MATORDERINGNATURAL,
// rperm,
// cperm,
// __FILE__, __LINE__);
// Wrappers::Petsc::LUFactor(MatrixT& A,
// IS row, IS col,
// const MatFactorInfo *info,
// __FILE__, __LINE__);
// Wrappers::Petsc::MatMatSolve(matrix_init_1,
// matrix_init_2,
// matrix_4,
// __FILE__, __LINE__);
// Wrappers::Petsc::CholeskyFactor(MatrixT& mat,
// IS perm,
// const MatFactorInfo *info,
// __FILE__, __LINE__);
}
}
......
......@@ -120,19 +120,8 @@ namespace MoReFEM
*/
void SupplFinalize();
//! Accessor to the vector used for tests.
const GlobalVector& GetVector() const noexcept;
//! Accessor to the matrix A used for tests.
const GlobalMatrix& GetMatrixA() const noexcept;
//! Accessor to the matrix B used for tests.
const GlobalMatrix& GetMatrixB() const noexcept;
//! Accessor to the matrix C used for tests.
const GlobalMatrix& GetMatrixC() const noexcept;
private:
private:
//! \copydoc doxygen_hide_model_SupplHasFinishedConditions_always_true
......@@ -151,21 +140,30 @@ namespace MoReFEM
private:
//! Global vector which is used in the tests.
GlobalVector::unique_ptr vector_ = nullptr;
//! Global matrix A which is used in the tests.
GlobalMatrix::unique_ptr matrix_a_ = nullptr;
//! Global matrix B which is used in the tests.
GlobalMatrix::unique_ptr matrix_b_ = nullptr;
GlobalVector::unique_ptr vector_init_1_ = nullptr;
//! Global vector which is used in the tests.
GlobalVector::unique_ptr vector_init_2_ = nullptr;
//! Global matrix C which is used in the tests.
GlobalMatrix::unique_ptr matrix_c_ = nullptr;
//! Global vector which is used in the tests.
GlobalVector::unique_ptr vector_init_3_ = nullptr;
//! Global matrix D which is used in the tests.
GlobalMatrix::unique_ptr matrix_d_ = nullptr;
/// \name Global matrices used by the PETSc wrappers
///@{
GlobalMatrix::unique_ptr matrix_init_1_ = nullptr;
GlobalMatrix::unique_ptr matrix_init_2_ = nullptr;
GlobalMatrix::unique_ptr matrix_init_3_ = nullptr;
GlobalMatrix::unique_ptr matrix_4_ = nullptr;
GlobalMatrix::unique_ptr matrix_5_ = nullptr;
GlobalMatrix::unique_ptr matrix_6_ = nullptr;
GlobalMatrix::unique_ptr matrix_7_ = nullptr;
GlobalMatrix::unique_ptr matrix_8_ = nullptr;
GlobalMatrix::unique_ptr matrix_9_ = nullptr;
GlobalMatrix::unique_ptr matrix_10_ = nullptr;
///@}
};
} // namespace TestNS::PetscNS::MatrixOperationsNS
......
......@@ -35,34 +35,6 @@ namespace MoReFEM
{ }
inline const GlobalVector& Model::GetVector() const noexcept
{
assert(!(!vector_));
return *vector_;
}
inline const GlobalMatrix& Model::GetMatrixA() const noexcept
{
assert(!(!matrix_a_));
return *matrix_a_;
}
inline const GlobalMatrix& Model::GetMatrixB() const noexcept
{
assert(!(!matrix_b_));
return *matrix_b_;
}
inline const GlobalMatrix& Model::GetMatrixC() const noexcept
{
assert(!(!matrix_c_));
return *matrix_c_;
}
} // namespace TestNS::PetscNS::MatrixOperationsNS
......
......@@ -426,7 +426,7 @@ namespace MoReFEM
int error_code = MatGetValues(Internal(),
1, &row_index,
1, & column_index,
1, &column_index,
&ret);
if (error_code)
......
......@@ -83,7 +83,7 @@ namespace MoReFEM
Mat result;
int error_code { };
switch(do_reuse_matrix)
switch (do_reuse_matrix)
{
case DoReuseMatrix::yes:
{
......@@ -107,6 +107,7 @@ namespace MoReFEM
}
case DoReuseMatrix::in_place:
{
static_cast<void>(error_code);
assert(false && "In place matrix option not supported for this function.");
break;
}
......@@ -142,7 +143,7 @@ namespace MoReFEM
Mat result;
int error_code;
switch(do_reuse_matrix)
switch (do_reuse_matrix)
{
case DoReuseMatrix::yes:
{
......@@ -171,6 +172,7 @@ namespace MoReFEM
}
case DoReuseMatrix::in_place:
{
static_cast<void>(error_code);
assert(false && "In place matrix option not supported for this function.");
break;
}
......@@ -266,15 +268,6 @@ namespace MoReFEM
{
result = matrix2.Internal();
error_code = ::MatTranspose(matrix1.Internal(), MAT_REUSE_MATRIX, &result);
// int error_code_copy = ::MatCopy(result, matrix2.Internal(), SAME_NONZERO_PATTERN);
// int error_destroy = ::MatDestroy(&result); // necessary?
//
// if (error_destroy)
// throw ExceptionNS::Exception(error_code, "MatDestroy", invoking_file, invoking_line);
// if (error_code_copy)
// throw ExceptionNS::Exception(error_code_copy, "MatCopy", invoking_file, invoking_line);
break;
}
case DoReuseMatrix::in_place:
......@@ -356,7 +349,7 @@ namespace MoReFEM
int error_code;
switch(do_reuse_matrix)
switch (do_reuse_matrix)
{
case DoReuseMatrix::yes:
{
......@@ -382,13 +375,12 @@ namespace MoReFEM
break;
}
case DoReuseMatrix::in_place:
{
static_cast<void>(error_code);
assert(false && "In place matrix option not supported for this function.");
break;
}
} // switch
if (error_code)
......@@ -418,7 +410,7 @@ namespace MoReFEM
Mat result;
int error_code;
switch(do_reuse_matrix)
switch (do_reuse_matrix)
{
case DoReuseMatrix::yes:
{
......@@ -443,6 +435,7 @@ namespace MoReFEM
}
case DoReuseMatrix::in_place:
{
static_cast<void>(error_code);
assert(false && "In place matrix option not supported for this function.");
break;
}
......@@ -476,7 +469,7 @@ namespace MoReFEM
Mat result;
int error_code;
switch(do_reuse_matrix)
switch (do_reuse_matrix)
{
case DoReuseMatrix::yes:
{
......@@ -500,6 +493,7 @@ namespace MoReFEM
}
case DoReuseMatrix::in_place:
{
static_cast<void>(error_code);
assert(false && "In place matrix option not supported for this function.");
break;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment