From: Timo Heister Date: Mon, 23 Apr 2018 16:52:47 +0000 (-0400) Subject: address comments X-Git-Tag: v9.0.0-rc1~14^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27610449389cccdef4e66aa93655efac5334a04d;p=dealii.git address comments --- diff --git a/include/deal.II/lac/constraint_matrix.h b/include/deal.II/lac/constraint_matrix.h index 652cfc17f7..64106c4a72 100644 --- a/include/deal.II/lac/constraint_matrix.h +++ b/include/deal.II/lac/constraint_matrix.h @@ -1177,6 +1177,16 @@ public: * object. */ std::size_t memory_consumption () const; + + /** + * Support for boost:serialization. + */ + template + void serialize(Archive &ar, const unsigned int) + { + ar &index &entries &inhomogeneity; + } + }; diff --git a/source/lac/constraint_matrix.cc b/source/lac/constraint_matrix.cc index f4e24359a1..dbbd8cdd73 100644 --- a/source/lac/constraint_matrix.cc +++ b/source/lac/constraint_matrix.cc @@ -104,90 +104,77 @@ const ConstraintMatrix::LineRange ConstraintMatrix::get_lines() const } -namespace -{ - struct line - { - types::global_dof_index row; - double inhom; - std::vector< std::pair > entries; - - template - void serialize(Archive &ar, const unsigned int) - { - ar &row &entries &inhom; - } - - line() {} - - line(const ConstraintMatrix &cm, const types::global_dof_index row) - : row (row) - { - inhom = cm.get_inhomogeneity(row); - if (auto v=cm.get_constraint_entries(row)) - entries = *v; - } - }; -} bool ConstraintMatrix::is_consistent_in_parallel(const std::vector &locally_owned_dofs, const IndexSet &locally_active_dofs, const MPI_Comm mpi_communicator, const bool verbose) const { + ConstraintLine empty= {}; + // Helper to return a reference to the ConstraintLine object that belongs to row @p row. + // We don't want to make copies but to return a reference, we need an empty object that + // we store above. + auto get_line = [&] (const size_type row) -> const ConstraintLine& + { + const size_type line_index = calculate_line_index(row); + if (line_index >= lines_cache.size() || + lines_cache[line_index] == numbers::invalid_size_type) + { + empty.index = row; + return empty; + } + else + return lines[lines_cache[line_index]]; + }; + // identify non-owned rows and send to owner: - std::map< unsigned int, std::vector > to_send; + std::map< unsigned int, std::vector > to_send; const unsigned int myid = dealii::Utilities::MPI::this_mpi_process(mpi_communicator); + const unsigned int nproc = dealii::Utilities::MPI::n_mpi_processes(mpi_communicator); // We will send all locally active dofs that are not locally owned for checking. Note // that we allow constraints to differ on locally_relevant (and not active) DoFs. IndexSet non_owned = locally_active_dofs; non_owned.subtract_set(locally_owned_dofs[myid]); - for (auto it = non_owned.begin(); it != non_owned.end(); ++it) + for (unsigned int owner=0; owner > received = Utilities::MPI::some_to_some (MPI_COMM_WORLD, to_send); + std::map > received = Utilities::MPI::some_to_some (mpi_communicator, to_send); unsigned int inconsistent = 0; - // from each processor: - for (auto &kv : received) + for (const auto &kv : received) { // for each incoming line: for (auto &lineit : kv.second) { - line ref(*this, lineit.row); + const ConstraintLine &reference = get_line(lineit.index); - if (lineit.inhom!=ref.inhom) + if (lineit.inhomogeneity != reference.inhomogeneity) { ++inconsistent; if (verbose) std::cout << "Proc " << myid - << " got line " << lineit.row + << " got line " << lineit.index << " from " << kv.first - << " inhomogeneity " << lineit.inhom << " != " << ref.inhom << std::endl; + << " inhomogeneity " << lineit.inhomogeneity << " != " << reference.inhomogeneity << std::endl; } - else if (ref.entries != lineit.entries) + else if (lineit.entries != reference.entries) { ++inconsistent; if (verbose) std::cout << "Proc " << myid - << " got line " << lineit.row + << " got line " << lineit.index << " from " << kv.first << " wrong values!" << std::endl;