From 5fbdc01e477b1435fa4d4943d20b14989c5927ff Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sat, 17 Jun 2017 20:34:16 -0600 Subject: [PATCH] Move the CellDataTransferBuffer class out of an enclosing (useless) class. --- source/dofs/dof_handler_policy.cc | 222 +++++++++++++++--------------- 1 file changed, 109 insertions(+), 113 deletions(-) diff --git a/source/dofs/dof_handler_policy.cc b/source/dofs/dof_handler_policy.cc index 23c9c10957..39422c1034 100644 --- a/source/dofs/dof_handler_policy.cc +++ b/source/dofs/dof_handler_policy.cc @@ -1219,113 +1219,111 @@ namespace internal namespace { + /** + * A structure that allows the transfer of DoF indices from one processor + * to another. It corresponds to a packed buffer that stores a list of + * cells (in the form of a list of coarse mesh index -- i.e., the tree_index + * of the cell, and a corresponding list of quadrants within these trees), + * and a long array of DoF indices. + * + * The list of DoF indices stores first the number of indices for the + * first cell (=tree index and quadrant), then the indices for that cell, + * then the number of indices of the second cell, then the actual indices + * of the second cell, etc. + * + * The DoF indices array may or may not be used by algorithms using this + * class. + */ template - struct types + struct CellDataTransferBuffer { + std::vector tree_index; + std::vector::quadrant> quadrants; + std::vector dofs; - /** - * A structure that allows the transfer of DoF indices from one processor - * to another. It corresponds to a packed buffer that stores a list of - * cells (in the form of a list of coarse mesh index -- i.e., the tree_index - * of the cell, and a corresponding list of quadrants within these trees), - * and a long array of DoF indices. - * - * The list of DoF indices stores first the number of indices for the - * first cell (=tree index and quadrant), then the indices for that cell, - * then the number of indices of the second cell, then the actual indices - * of the second cell, etc. - */ - struct CellDataTransferBuffer - { - std::vector tree_index; - std::vector::quadrant> quadrants; - std::vector dofs; + unsigned int bytes_for_buffer () const + { + return (sizeof(unsigned int)*2 + + tree_index.size() * sizeof(unsigned int) + + quadrants.size() * sizeof(typename dealii::internal::p4est + ::types::quadrant) + + dofs.size() * sizeof(dealii::types::global_dof_index)); + } - unsigned int bytes_for_buffer () const - { - return (sizeof(unsigned int)*2 + - tree_index.size() * sizeof(unsigned int) + - quadrants.size() * sizeof(typename dealii::internal::p4est - ::types::quadrant) + - dofs.size() * sizeof(dealii::types::global_dof_index)); - } + void pack_data (std::vector &buffer) const + { + buffer.resize(bytes_for_buffer()); - void pack_data (std::vector &buffer) const - { - buffer.resize(bytes_for_buffer()); + char *ptr = &buffer[0]; - char *ptr = &buffer[0]; + const unsigned int num_cells = tree_index.size(); + std::memcpy(ptr, &num_cells, sizeof(unsigned int)); + ptr += sizeof(unsigned int); - const unsigned int num_cells = tree_index.size(); - std::memcpy(ptr, &num_cells, sizeof(unsigned int)); - ptr += sizeof(unsigned int); + const unsigned int num_dofs = dofs.size(); + std::memcpy(ptr, &num_dofs, sizeof(unsigned int)); + ptr += sizeof(unsigned int); - const unsigned int num_dofs = dofs.size(); - std::memcpy(ptr, &num_dofs, sizeof(unsigned int)); - ptr += sizeof(unsigned int); + std::memcpy(ptr, + &tree_index[0], + num_cells*sizeof(unsigned int)); + ptr += num_cells*sizeof(unsigned int); - std::memcpy(ptr, - &tree_index[0], - num_cells*sizeof(unsigned int)); - ptr += num_cells*sizeof(unsigned int); + std::memcpy(ptr, + &quadrants[0], + num_cells * sizeof(typename dealii::internal::p4est:: + types::quadrant)); + ptr += num_cells*sizeof(typename dealii::internal::p4est::types:: + quadrant); + if (num_dofs>0) std::memcpy(ptr, - &quadrants[0], - num_cells * sizeof(typename dealii::internal::p4est:: - types::quadrant)); - ptr += num_cells*sizeof(typename dealii::internal::p4est::types:: - quadrant); - - if (num_dofs>0) - std::memcpy(ptr, - &dofs[0], - dofs.size() * sizeof(dealii::types::global_dof_index)); - ptr += dofs.size() * sizeof(dealii::types::global_dof_index); - - Assert (ptr == &buffer[0]+buffer.size(), - ExcInternalError()); - } - + &dofs[0], + dofs.size() * sizeof(dealii::types::global_dof_index)); + ptr += dofs.size() * sizeof(dealii::types::global_dof_index); - void unpack_data(const std::vector &buffer) - { - const char *ptr = &buffer[0]; - unsigned int num_cells; - memcpy(&num_cells, ptr, sizeof(unsigned int)); - ptr+=sizeof(unsigned int); + Assert (ptr == &buffer[0]+buffer.size(), + ExcInternalError()); + } - unsigned int num_dofs; - memcpy(&num_dofs, ptr, sizeof(unsigned int)); - ptr+=sizeof(unsigned int); - tree_index.resize(num_cells); - std::memcpy(&tree_index[0], - ptr, - num_cells*sizeof(unsigned int)); - ptr += num_cells*sizeof(unsigned int); - - quadrants.resize(num_cells); - std::memcpy(&quadrants[0], + void unpack_data(const std::vector &buffer) + { + const char *ptr = &buffer[0]; + unsigned int num_cells; + memcpy(&num_cells, ptr, sizeof(unsigned int)); + ptr+=sizeof(unsigned int); + + unsigned int num_dofs; + memcpy(&num_dofs, ptr, sizeof(unsigned int)); + ptr+=sizeof(unsigned int); + + tree_index.resize(num_cells); + std::memcpy(&tree_index[0], + ptr, + num_cells*sizeof(unsigned int)); + ptr += num_cells*sizeof(unsigned int); + + quadrants.resize(num_cells); + std::memcpy(&quadrants[0], + ptr, + num_cells * sizeof(typename dealii::internal::p4est:: + types::quadrant)); + ptr += num_cells*sizeof(typename dealii::internal::p4est::types:: + quadrant); + + dofs.resize(num_dofs); + if (num_dofs>0) + std::memcpy(&dofs[0], ptr, - num_cells * sizeof(typename dealii::internal::p4est:: - types::quadrant)); - ptr += num_cells*sizeof(typename dealii::internal::p4est::types:: - quadrant); - - dofs.resize(num_dofs); - if (num_dofs>0) - std::memcpy(&dofs[0], - ptr, - dofs.size() * sizeof(dealii::types::global_dof_index)); - ptr += dofs.size() * sizeof(dealii::types::global_dof_index); - - Assert (ptr == &buffer[0]+buffer.size(), - ExcInternalError()); - } + dofs.size() * sizeof(dealii::types::global_dof_index)); + ptr += dofs.size() * sizeof(dealii::types::global_dof_index); - }; + Assert (ptr == &buffer[0]+buffer.size(), + ExcInternalError()); + } }; @@ -1338,7 +1336,7 @@ namespace internal const typename DoFHandler::level_cell_iterator &dealii_cell, const typename dealii::internal::p4est::types::quadrant &p4est_cell, const std::map > &vertices_with_ghost_neighbors, - std::map::CellDataTransferBuffer> &needs_to_get_cell) + std::map> &needs_to_get_cell) { // see if we have to recurse... if (dealii_cell->has_children()) @@ -1409,11 +1407,11 @@ namespace internal // already exists), // or create such // an object - typename std::map::CellDataTransferBuffer>::iterator - p - = needs_to_get_cell.insert (std::make_pair(subdomain, - typename types::CellDataTransferBuffer())) - .first; + typename std::map>::iterator + p + = needs_to_get_cell.insert (std::make_pair(subdomain, + CellDataTransferBuffer())) + .first; p->second.tree_index.push_back(tree_index); p->second.quadrants.push_back(p4est_cell); @@ -1435,7 +1433,7 @@ namespace internal const typename dealii::internal::p4est::types::quadrant &p4est_cell, const typename DoFHandler::level_cell_iterator &dealii_cell, const typename dealii::internal::p4est::types::quadrant &quadrant, - typename types::CellDataTransferBuffer &cell_info) + CellDataTransferBuffer &cell_data_transfer_buffer) { if (internal::p4est::quadrant_is_equal(p4est_cell, quadrant)) { @@ -1447,10 +1445,10 @@ namespace internal local_dof_indices (dealii_cell->get_fe().dofs_per_cell); dealii_cell->get_mg_dof_indices (local_dof_indices); - cell_info.dofs.push_back(dealii_cell->get_fe().dofs_per_cell); - cell_info.dofs.insert(cell_info.dofs.end(), - local_dof_indices.begin(), - local_dof_indices.end()); + cell_data_transfer_buffer.dofs.push_back(dealii_cell->get_fe().dofs_per_cell); + cell_data_transfer_buffer.dofs.insert(cell_data_transfer_buffer.dofs.end(), + local_dof_indices.begin(), + local_dof_indices.end()); return; // we are done } @@ -1467,7 +1465,7 @@ namespace internal for (unsigned int c=0; c::max_children_per_cell; ++c) get_mg_dofindices_recursively (tria, p4est_child[c], dealii_cell->child(c), - quadrant, cell_info); + quadrant, cell_data_transfer_buffer); } @@ -1477,7 +1475,7 @@ namespace internal const unsigned int tree_index, const typename DoFHandler::level_cell_iterator &dealii_cell, const typename dealii::internal::p4est::types::quadrant &p4est_cell, - std::map::CellDataTransferBuffer> &neighbor_cell_list) + std::map> &neighbor_cell_list) { // recurse... if (dealii_cell->has_children()) @@ -1497,10 +1495,8 @@ namespace internal if (dealii_cell->user_flag_set() && dealii_cell->level_subdomain_id() != tria.locally_owned_subdomain()) { - typename types::CellDataTransferBuffer &cell_info = neighbor_cell_list[dealii_cell->level_subdomain_id()]; - - cell_info.tree_index.push_back(tree_index); - cell_info.quadrants.push_back(p4est_cell); + neighbor_cell_list[dealii_cell->level_subdomain_id()].tree_index.push_back(tree_index); + neighbor_cell_list[dealii_cell->level_subdomain_id()].quadrants.push_back(p4est_cell); } } @@ -1580,12 +1576,12 @@ namespace internal { // build list of cells to request for each neighbor std::set level_ghost_owners = tria.level_ghost_owners(); - typedef std::map::CellDataTransferBuffer> cellmap_t; + typedef std::map> cellmap_t; cellmap_t neighbor_cell_list; for (std::set::iterator it = level_ghost_owners.begin(); it != level_ghost_owners.end(); ++it) - neighbor_cell_list.insert(std::make_pair(*it, typename types::CellDataTransferBuffer())); + neighbor_cell_list.insert(std::make_pair(*it, CellDataTransferBuffer())); for (typename DoFHandler::level_cell_iterator cell = dof_handler.begin(0); @@ -1634,7 +1630,7 @@ namespace internal for (unsigned int idx=0; idx receive; - typename types::CellDataTransferBuffer cell_data_transfer_buffer; + CellDataTransferBuffer cell_data_transfer_buffer; MPI_Status status; int len; @@ -1682,7 +1678,7 @@ namespace internal for (unsigned int idx=0; idx receive; - typename types::CellDataTransferBuffer cell_data_transfer_buffer; + CellDataTransferBuffer cell_data_transfer_buffer; MPI_Status status; int len; @@ -1856,8 +1852,8 @@ namespace internal // dof_indices for the // interested neighbors typedef - std::map::CellDataTransferBuffer> - cellmap_t; + std::map> + cellmap_t; cellmap_t needs_to_get_cells; for (typename DoFHandler::level_cell_iterator @@ -1961,7 +1957,7 @@ namespace internal tr->get_communicator(), &status); AssertThrowMPI(ierr); - typename types::CellDataTransferBuffer cell_data_transfer_buffer; + CellDataTransferBuffer cell_data_transfer_buffer; cell_data_transfer_buffer.unpack_data(receive); unsigned int cells = cell_data_transfer_buffer.tree_index.size(); dealii::types::global_dof_index *dofs = cell_data_transfer_buffer.dofs.data(); -- 2.39.5