]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Rename some variables and clean up code. 6280/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 20 Apr 2018 23:39:04 +0000 (17:39 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 20 Apr 2018 23:39:04 +0000 (17:39 -0600)
include/deal.II/distributed/tria.h
source/distributed/tria.cc

index ccf57a85af242f89a48916fa6fa2149536ade144..00a9837433323125d6f019713ea7bddfca4881e5 100644 (file)
@@ -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
index d364fa2bd8f65a50406ef93b81cf81d9159fab7d..0796ab9e20f7ebc7d73e2e9d245e5ba163f8f7ed 100644 (file)
@@ -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<dealii::parallel::distributed::Triangulation<dim, spacedim>*>(this)
           ->attach_mesh_data();
         }
 
       dealii::internal::p4est::functions<dim>::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<dealii::parallel::distributed::Triangulation<dim, spacedim>*>(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<dim,spacedim>::
     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<dim>::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;
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.