Commit 13866370 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#982 Remove a debug function from matrix: to make it fully work in parallel we...

#982 Remove a debug function from matrix: to make it fully work in parallel we need GodOfDof directly. Fix the implementation to make it work in parallel.
parent cecb96bf
......@@ -48,65 +48,6 @@ namespace HappyHeart
}
#ifndef NDEBUG
void AssertMatrixRespectPattern(const Wrappers::Mpi& mpi,
const GlobalMatrix& matrix,
const Wrappers::Petsc::MatrixPattern& pattern,
const char* invoking_file, int invoking_line)
{
try
{
const auto Nrow = matrix.GetProcessorWiseSize(invoking_file, invoking_line).first;
if (Nrow != static_cast<int>(pattern.Nrow()))
throw Exception("Number of rows in pattern and matrix is not the same!",
invoking_file, invoking_line);
decltype(auto) iCsr = pattern.GetICsr();
decltype(auto) jCsr = pattern.GetJCsr();
assert(iCsr.size() == static_cast<std::size_t>(Nrow + 1)
&& "This would highlight a bug within MatrixPattern class");
auto current_jcsr_index = 0ul;
for (auto i = 0; i < Nrow; ++i)
{
std::vector<PetscInt> position_list_in_matrix;
std::vector<PetscScalar> value_list_in_matrix;
matrix.GetRow(i, position_list_in_matrix, value_list_in_matrix, invoking_file, invoking_line);
const auto Nvalue_in_pattern_row =
static_cast<std::size_t>(iCsr[static_cast<std::size_t>(i + 1)] - iCsr[static_cast<std::size_t>(i)]);
std::vector<PetscInt> position_list_in_pattern;
for (auto j = 0ul; j < Nvalue_in_pattern_row; ++j)
{
assert(current_jcsr_index < jCsr.size());
position_list_in_pattern.push_back(static_cast<PetscInt>(jCsr[current_jcsr_index + j]));
}
current_jcsr_index += Nvalue_in_pattern_row;
if (!std::includes(position_list_in_pattern.cbegin(),
position_list_in_pattern.cend(),
position_list_in_matrix.cbegin(),
position_list_in_matrix.cend()))
{
throw Exception("Position in the actual matrix must match those defined in the pattern!",
invoking_file, invoking_line);
}
}
}
catch(const Exception& e)
{
ExceptionNS::PrintAndAbort(mpi, e.what());
}
}
void AssertSameNumberingSubset(const GlobalMatrix& matrix1,
const GlobalMatrix& matrix2)
{
......@@ -123,9 +64,5 @@ namespace HappyHeart
<< matrix.GetColNumberingSubset().GetUniqueId() << std::endl;
}
#endif // NDEBUG
} // namespace HappyHeart
......@@ -118,20 +118,7 @@ namespace HappyHeart
* \copydetails doxygen_hide_invoking_file_and_line
*/
/*!
* \copydoc doxygen_hide_assert_matrix_respect_pattern_function
*
* \copydetails doxygen_hide_mpi_param
* \param[in] pattern Object that describe the sparse pattern the matrix is expected to follow. In HappyHeart
* such objects are stored in the GodOfDof.
*
* \note A slightly more convenient overload is available in GodOfDof.hpp.
*/
void AssertMatrixRespectPattern(const Wrappers::Mpi& mpi,
const GlobalMatrix& matrix,
const Wrappers::Petsc::MatrixPattern& pattern,
const char* invoking_file, int invoking_line);
/*!
* \brief Assert two matrices share the same \a NumberingSubset.
......
......@@ -12,6 +12,7 @@
#include "Utilities/Filesystem/File.hpp"
#include "Utilities/TimeKeep/TimeKeep.hpp"
#include "Utilities/Exceptions/PrintAndAbort.hpp"
#include "ThirdParty/Wrappers/Petsc/Vector/AccessVectorContent.hpp"
......@@ -382,13 +383,12 @@ namespace HappyHeart
assert(!(!numbering_subset_ptr));
unsigned int current_processor_wise_or_ghost_dof_index = 0u;
{
Internal::FEltSpaceNS
::ComputeDofIndexesForNumberingSubset<MpiScale::processor_wise>(node_bearer_list,
CurrentDofNumberingScheme(),
numbering_subset_ptr,
current_processor_wise_or_ghost_dof_index);
}
Internal::FEltSpaceNS
::ComputeDofIndexesForNumberingSubset<MpiScale::processor_wise>(node_bearer_list,
CurrentDofNumberingScheme(),
numbering_subset_ptr,
current_processor_wise_or_ghost_dof_index);
// Ghost dofs are created similarly; the same index keeps being used (so we get first all processor-wise dofs
// and then all ghost in a Petsc parallel vector).
......@@ -1159,15 +1159,104 @@ namespace HappyHeart
const GlobalMatrix& matrix,
const char* invoking_file, int invoking_line)
{
decltype(auto) mpi = god_of_dof.MpiHappyHeart();
decltype(auto) pattern = god_of_dof.GetMatrixPattern(matrix.GetRowNumberingSubset(),
matrix.GetColNumberingSubset());
AssertMatrixRespectPattern(god_of_dof.MpiHappyHeart(),
matrix,
pattern,
invoking_file, invoking_line);
try
{
decltype(auto) pattern = god_of_dof.GetMatrixPattern(matrix.GetRowNumberingSubset(),
matrix.GetColNumberingSubset());
const auto Nrow = static_cast<unsigned int>(matrix.GetProcessorWiseSize(invoking_file, invoking_line).first);
if (Nrow != static_cast<unsigned int>(pattern.Nrow()))
throw Exception("Number of rows in pattern and matrix is not the same!",
invoking_file, invoking_line);
decltype(auto) iCsr = pattern.GetICsr();
decltype(auto) jCsr = pattern.GetJCsr();
assert(iCsr.size() == static_cast<std::size_t>(Nrow + 1)
&& "This would highlight a bug within MatrixPattern class");
auto current_jcsr_index = 0ul;
decltype(auto) processor_wise_dof_list = god_of_dof.GetProcessorWiseDofList();
std::vector<PetscInt> position_list_in_matrix;
std::vector<PetscScalar> value_list_in_matrix;
decltype(auto) row_numbering_subset = matrix.GetRowNumberingSubset();
Dof::vector_shared_ptr processor_wise_dof_list_in_row_numbering_subset;
std::copy_if(processor_wise_dof_list.cbegin(),
processor_wise_dof_list.cend(),
std::back_inserter(processor_wise_dof_list_in_row_numbering_subset),
[&row_numbering_subset](const auto& dof_ptr)
{
assert(!(!dof_ptr));
return dof_ptr->IsInNumberingSubset(row_numbering_subset);
});
for (auto row_index = 0u; row_index < Nrow; ++row_index)
{
position_list_in_matrix.clear();
value_list_in_matrix.clear();
const auto it = std::find_if(processor_wise_dof_list_in_row_numbering_subset.cbegin(),
processor_wise_dof_list_in_row_numbering_subset.cend(),
[&row_numbering_subset, row_index](const auto& dof_ptr)
{
assert(!(!dof_ptr));
return dof_ptr->GetProcessorWiseOrGhostIndex(row_numbering_subset) == row_index;
});
assert(it != processor_wise_dof_list.cend());
assert(!(!(*it)));
const auto program_wise_index = static_cast<PetscInt>((*it)->GetProgramWiseIndex(row_numbering_subset));
matrix.GetRow(program_wise_index, position_list_in_matrix, value_list_in_matrix, invoking_file, invoking_line);
const auto Nvalue_in_pattern_row =
static_cast<std::size_t>(iCsr[static_cast<std::size_t>(row_index + 1)] - iCsr[static_cast<std::size_t>(row_index)]);
std::vector<PetscInt> position_list_in_pattern;
for (auto j = 0ul; j < Nvalue_in_pattern_row; ++j)
{
assert(current_jcsr_index + j < jCsr.size());
position_list_in_pattern.push_back(static_cast<PetscInt>(jCsr[current_jcsr_index + j]));
}
current_jcsr_index += Nvalue_in_pattern_row;
if (!std::includes(position_list_in_pattern.cbegin(),
position_list_in_pattern.cend(),
position_list_in_matrix.cbegin(),
position_list_in_matrix.cend()))
{
PrintNumberingSubset("matrix", matrix);
std::ostringstream oconv;
oconv << "Position in the actual matrix must match those defined in the pattern! Not the case "
"for row " << program_wise_index << " (program-wise numbering) on processor " << mpi.GetRank<int>();
Utilities::PrintContainer(position_list_in_matrix, oconv, ", ", "\n\t- Position in matrix -> [");
Utilities::PrintContainer(position_list_in_pattern, oconv, ", ", "\t- Position in pattern -> [");
throw Exception(oconv.str(),
invoking_file, invoking_line);
}
}
}
catch(const Exception& e)
{
ExceptionNS::PrintAndAbort(mpi, e.what());
}
}
# endif // NDEBUG
......
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