From cd050dcd6fdd9e4668367ebd4e2482f0abe934a1 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 20 Apr 2018 17:39:04 -0600 Subject: [PATCH] Rename some variables and clean up code. --- include/deal.II/distributed/tria.h | 8 +++-- source/distributed/tria.cc | 53 +++++++++++++++--------------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/include/deal.II/distributed/tria.h b/include/deal.II/distributed/tria.h index ccf57a85af..00a9837433 100644 --- a/include/deal.II/distributed/tria.h +++ b/include/deal.II/distributed/tria.h @@ -847,10 +847,12 @@ namespace parallel struct CellAttachedData { /** - * number of bytes that get attached to the Triangulation through - * register_data_attach() for example SolutionTransfer. + * Cumulative size in bytes of the buffers that those functions that + * have called register_data_attach() want to attach to each cell. + * This number only pertains to fixed-sized buffers where the data + * attached to each cell has exactly the same size. */ - unsigned int attached_data_size; + unsigned int cumulative_fixed_data_size; /** * number of functions that get attached to the Triangulation through diff --git a/source/distributed/tria.cc b/source/distributed/tria.cc index d364fa2bd8..0796ab9e20 100644 --- a/source/distributed/tria.cc +++ b/source/distributed/tria.cc @@ -1795,37 +1795,39 @@ namespace parallel { Assert(cell_attached_data.n_attached_deserialize==0, ExcMessage ("not all SolutionTransfer's got deserialized after the last load()")); + Assert(this->n_cells()>0, ExcMessage("Can not save() an empty Triangulation.")); // signal that serialization is going to happen this->signals.pre_distributed_save(); - int real_data_size = 0; - if (cell_attached_data.attached_data_size>0) - real_data_size = cell_attached_data.attached_data_size+sizeof(CellStatus); - - Assert(this->n_cells()>0, ExcMessage("Can not save() an empty Triangulation.")); - if (this->my_subdomain==0) { + const unsigned int buffer_size_per_cell + = (cell_attached_data.cumulative_fixed_data_size > 0 + ? + cell_attached_data.cumulative_fixed_data_size+sizeof(CellStatus) + : + 0); + std::string fname=std::string(filename)+".info"; std::ofstream f(fname.c_str()); f << "version nproc attached_bytes n_attached_objs n_coarse_cells" << std::endl << 2 << " " << Utilities::MPI::n_mpi_processes (this->mpi_communicator) << " " - << real_data_size << " " + << buffer_size_per_cell << " " << cell_attached_data.attached_data_pack_callbacks.size() << " " << this->n_cells(0) << std::endl; } - if (cell_attached_data.attached_data_size>0) + if (cell_attached_data.cumulative_fixed_data_size>0) { const_cast*>(this) ->attach_mesh_data(); } dealii::internal::p4est::functions::save(filename, parallel_forest, - cell_attached_data.attached_data_size>0); + cell_attached_data.cumulative_fixed_data_size>0); // clear all of the callback data, as explained in the documentation of // register_data_attach() @@ -1834,7 +1836,7 @@ namespace parallel = const_cast*>(this); tria->cell_attached_data.n_attached_datas = 0; - tria->cell_attached_data.attached_data_size = 0; + tria->cell_attached_data.cumulative_fixed_data_size = 0; tria->cell_attached_data.attached_data_pack_callbacks.clear(); } @@ -1888,7 +1890,7 @@ namespace parallel // clear all of the callback data, as explained in the documentation of // register_data_attach() - cell_attached_data.attached_data_size = 0; + cell_attached_data.cumulative_fixed_data_size = 0; cell_attached_data.n_attached_datas = 0; cell_attached_data.n_attached_deserialize = attached_count; @@ -3247,12 +3249,14 @@ namespace parallel Assert(cell_attached_data.attached_data_pack_callbacks.size()==cell_attached_data.n_attached_datas, ExcMessage("register_data_attach(), not all data has been unpacked last time?")); - const unsigned int offset = cell_attached_data.attached_data_size+sizeof(CellStatus); + const unsigned int current_buffer_positition = cell_attached_data.cumulative_fixed_data_size+sizeof(CellStatus); ++cell_attached_data.n_attached_datas; - cell_attached_data.attached_data_size += size; - cell_attached_data.attached_data_pack_callbacks.emplace_back(offset, pack_callback); + cell_attached_data.cumulative_fixed_data_size += size; + cell_attached_data.attached_data_pack_callbacks.emplace_back(current_buffer_positition, pack_callback); - return offset; + // use the offset as the handle that callers receive and later hand back + // to notify_ready_to_unpack() + return current_buffer_positition; } @@ -3267,7 +3271,7 @@ namespace parallel { Assert (handle >= sizeof(CellStatus), ExcMessage ("Invalid offset.")); - Assert (handle < sizeof(CellStatus)+cell_attached_data.attached_data_size, + Assert (handle < cell_attached_data.cumulative_fixed_data_size + sizeof(CellStatus), ExcMessage ("Invalid offset.")); Assert (cell_attached_data.n_attached_datas > 0, ExcMessage ("The notify_ready_to_unpack() has already been called " @@ -3319,7 +3323,7 @@ namespace parallel cell_attached_data.n_attached_deserialize == 0) { // everybody got their data, time for cleanup! - cell_attached_data.attached_data_size = 0; + cell_attached_data.cumulative_fixed_data_size = 0; cell_attached_data.attached_data_pack_callbacks.clear(); // and release the data @@ -3586,7 +3590,7 @@ namespace parallel + MemoryConsumption::memory_consumption(triangulation_has_content) + MemoryConsumption::memory_consumption(connectivity) + MemoryConsumption::memory_consumption(parallel_forest) - + MemoryConsumption::memory_consumption(cell_attached_data.attached_data_size) + + MemoryConsumption::memory_consumption(cell_attached_data.cumulative_fixed_data_size) + MemoryConsumption::memory_consumption(cell_attached_data.n_attached_datas) // + MemoryConsumption::memory_consumption(attached_data_pack_callbacks) //TODO[TH]: how? + MemoryConsumption::memory_consumption(coarse_cell_to_p4est_tree_permutation) @@ -3638,7 +3642,7 @@ namespace parallel { coarse_cell_to_p4est_tree_permutation = other_tria_x->coarse_cell_to_p4est_tree_permutation; p4est_tree_to_coarse_cell_permutation = other_tria_x->p4est_tree_to_coarse_cell_permutation; - cell_attached_data.attached_data_size = other_tria_x->cell_attached_data.attached_data_size; + cell_attached_data.cumulative_fixed_data_size = other_tria_x->cell_attached_data.cumulative_fixed_data_size; cell_attached_data.n_attached_datas = other_tria_x->cell_attached_data.n_attached_datas; settings = other_tria_x->settings; @@ -3672,20 +3676,17 @@ namespace parallel Triangulation:: attach_mesh_data() { - // determine size of memory in bytes to attach to each cell. This needs - // to be constant because of p4est. - if (cell_attached_data.attached_data_size==0) + // check if there is anything at all to do here + if (cell_attached_data.cumulative_fixed_data_size==0) { Assert(cell_attached_data.n_attached_datas==0, ExcInternalError()); - - //nothing to do return; } - // realloc user_data in p4est + // reallocate user_data in p4est void *userptr = parallel_forest->user_pointer; dealii::internal::p4est::functions::reset_data (parallel_forest, - cell_attached_data.attached_data_size+sizeof(CellStatus), + cell_attached_data.cumulative_fixed_data_size+sizeof(CellStatus), nullptr, nullptr); parallel_forest->user_pointer = userptr; -- 2.39.5