Commit 4b537cf3 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#1534 Add matrix operations tests (which at the moment doesn nothing beyond...

#1534 Add matrix operations tests (which at the moment doesn nothing beyond initializing the matrices and vectors - the old content is commented and will be rewritten as tests).
parent 817e073b
......@@ -7,8 +7,23 @@ add_executable(MoReFEMTestPetscMatrixOperations
)
target_link_libraries(MoReFEMTestPetscMatrixOperations
${ALL_LOAD_BEGIN_FLAG}
${MOREFEM_MODEL}
${ALL_LOAD_END_FLAG})
${MOREFEM_TEST_TOOLS})
add_test(PetscMatrixOperations
MoReFEMTestPetscMatrixOperations
--
${MOREFEM_ROOT}
${MOREFEM_TEST_OUTPUT_DIR}/Seq)
set_tests_properties(PetscMatrixOperations PROPERTIES TIMEOUT 20)
add_test(PetscMatrixOperations-mpi
${OPEN_MPI_INCL_DIR}/../bin/mpirun
--oversubscribe
-np 4
MoReFEMTestPetscMatrixOperations
--
${MOREFEM_ROOT}
${MOREFEM_TEST_OUTPUT_DIR}/Mpi4)
set_tests_properties(PetscMatrixOperations-mpi PROPERTIES TIMEOUT 20)
......@@ -76,186 +76,20 @@ namespace MoReFEM::TestNS::PetscNS::MatrixOperationsNS
AllocateGlobalMatrix(god_of_dof, matrix_init_1);
AllocateGlobalMatrix(god_of_dof, matrix_init_2);
AllocateGlobalMatrix(god_of_dof, matrix_init_3);
// Init vector_init_1
{
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!
// First all wrappers that do not use a DoReuseMatrix 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::MatMult(matrix_init_1,
vector_init_1,
vector_init_2,
__FILE__, __LINE__);
Wrappers::Petsc::MatMultAdd(matrix_init_1,
vector_init_1,
vector_init_2,
vector_init_3,
__FILE__, __LINE__);
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);
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);
}
{
IS rperm;
IS cperm;
Wrappers::Petsc::GetOrdering(matrix_init_1,
MATORDERINGNATURAL,
&rperm,
&cperm,
__FILE__, __LINE__);
ISDestroy(&rperm);
ISDestroy(&cperm);
}
// \todo
//
// {
// IS perm;
//
// Wrappers::Petsc::CholeskyFactor(matrix_init_1,
// perm,
// NULL,
// __FILE__, __LINE__);
// }
//
// {
// IS row;
// IS col;
//
// Wrappers::Petsc::LUFactor(matrix_init_1,
// NULL,
// NULL,
// NULL,
// __FILE__, __LINE__);
// }
//
// {
//
// Wrappers::Petsc::MatMatSolve(matrix_init_1,
// matrix_init_2,
// matrix_4,
// __FILE__, __LINE__);
//
// }
}
}
void Model::Forward()
{ }
......
......@@ -9,66 +9,247 @@
#include <cstdlib>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Utilities/Exceptions/PrintAndAbort.hpp"
#define BOOST_TEST_MODULE petsc_matrix_operations
#include "ThirdParty/IncludeWithoutWarning/Boost/Test.hpp"
#include "ThirdParty/Wrappers/Tclap/StringPair.hpp"
#include "Utilities/Numeric/Numeric.hpp"
#include "Utilities/Exceptions/PrintAndAbort.hpp"
#include "Utilities/Filesystem/File.hpp"
#include "Core/MoReFEMData/MoReFEMData.hpp"
#include "Test/ThirdParty/PETSc/MatrixOperations/InputData.hpp"
#include "Test/Tools/Fixture/Model.hpp"
#include "Test/ThirdParty/PETSc/MatrixOperations/Model.hpp"
int main(int argc, char** argv)
using namespace MoReFEM;
namespace // anonymous
{
static_cast<void>(argc);
static_cast<void>(argv);
using namespace MoReFEM;
//! \copydoc doxygen_hide_model_specific_input_data
using InputData = TestNS::PetscNS::MatrixOperationsNS::InputData;
try
{
MoReFEMData<InputData, program_type::test> morefem_data(argc, argv);
const auto& mpi = morefem_data.GetMpi();
try
{
TestNS::PetscNS::MatrixOperationsNS::Model model(morefem_data);
model.Run();
}
catch(const ExceptionNS::GracefulExit&)
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
{
ExceptionNS::PrintAndAbort(mpi, e.what());
}
}
catch(const ExceptionNS::GracefulExit&)
struct LuaFile
{
return EXIT_SUCCESS;
}
catch(const std::exception& e)
static std::string GetPath();
};
using fixture_type =
TestNS::FixtureNS::Model
<
TestNS::PetscNS::MatrixOperationsNS::Model,
LuaFile
>;
} // namespace anonymous
PRAGMA_DIAGNOSTIC(push)
#include "Utilities/Warnings/Internal/IgnoreWarning/disabled-macro-expansion.hpp"
BOOST_FIXTURE_TEST_CASE(creation, fixture_type)
{
decltype(auto) model = GetModel();
static_cast<void>(model);
}
/**
{
// First all wrappers that do not use a DoReuseMatrix 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::MatMult(matrix_init_1,
vector_init_1,
vector_init_2,
__FILE__, __LINE__);
Wrappers::Petsc::MatMultAdd(matrix_init_1,
vector_init_1,
vector_init_2,
vector_init_3,
__FILE__, __LINE__);
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);
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);
}
{
IS rperm;
IS cperm;
Wrappers::Petsc::GetOrdering(matrix_init_1,
MATORDERINGNATURAL,
&rperm,
&cperm,
__FILE__, __LINE__);
ISDestroy(&rperm);
ISDestroy(&cperm);
}
// \todo
//
// {
// IS perm;
//
// Wrappers::Petsc::CholeskyFactor(matrix_init_1,
// perm,
// NULL,
// __FILE__, __LINE__);
// }
//
// {
// IS row;
// IS col;
//
// Wrappers::Petsc::LUFactor(matrix_init_1,
// NULL,
// NULL,
// NULL,
// __FILE__, __LINE__);
// }
//
// {
//
// Wrappers::Petsc::MatMatSolve(matrix_init_1,
// matrix_init_2,
// matrix_4,
// __FILE__, __LINE__);
//
// }
*/
PRAGMA_DIAGNOSTIC(pop)
namespace // anonymous
{
std::string LuaFile::GetPath()
{
std::ostringstream oconv;
oconv << "Exception caught from MoReFEMData<InputData>: " << e.what() << std::endl;
std::cout << oconv.str();
return EXIT_FAILURE;
decltype(auto) environment = Utilities::Environment::CreateOrGetInstance(__FILE__, __LINE__);
return
environment.SubstituteValues("${MOREFEM_ROOT}/Sources/Test/ThirdParty/PETSc/MatrixOperations/demo.lua");
}
return EXIT_SUCCESS;
}
} // namespace anonymous
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