]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Reduce cost to set up dictionary for compute_index_owner 13791/head
authorMartin Kronbichler <martin.kronbichler@uni-a.de>
Mon, 23 May 2022 10:07:59 +0000 (12:07 +0200)
committerMartin Kronbichler <martin.kronbichler@uni-a.de>
Tue, 24 May 2022 17:07:51 +0000 (19:07 +0200)
include/deal.II/base/mpi_compute_index_owner_internal.h
source/base/mpi_compute_index_owner_internal.cc

index 20efb739f40b7a0cc85d0a702dc3fb575d75ba78..88ea9c88bd7756f14c78a2d5c26155f76d475b74 100644 (file)
@@ -427,13 +427,13 @@ namespace Utilities
            * out the owner of the index that was requested (using the guess in
            * `owner_index`, as we typically might look up on the same rank
            * several times in a row, which avoids the binary search in
-           * Dictionary::get_owning_rank_index(). Once we know the rank of the
-           * owner, we the vector entry with the rank of the request. Here, we
-           * utilize the fact that requests are processed rank-by-rank, so we
-           * can simply look at the end of the vector if there is already some
-           * data stored or not. Finally, we build ranges, again using that
-           * the index list is sorted and we therefore only need to append at
-           * the end.
+           * Dictionary::get_owning_rank_index()). Once we know the rank of
+           * the owner, we fill the vector entry with the rank of the
+           * request. Here, we utilize the fact that requests are processed
+           * rank-by-rank, so we can simply look at the end of the vector
+           * whether there is already some data stored or not. Finally, we
+           * build ranges, again using that the index list is sorted and we
+           * therefore only need to append at the end.
            */
           void
           append_index_origin(const types::global_dof_index index,
index 92b82a3dd86392eb37d55cd4b93e1d8bd5a2d379..f115482350ef43a520499bac250e95c97bc5457b 100644 (file)
@@ -47,14 +47,11 @@ namespace Utilities
           this->use_vector = use_vector;
           this->size       = size;
 
-          data.clear();
+          data = {};
           data_map.clear();
 
-          if (use_vector)
-            {
-              data = {};
-              data.resize(size, invalid_index_value);
-            }
+          // do not initialize the vector but only upon first request in
+          // `fill`
         }
 
 
@@ -70,8 +67,27 @@ namespace Utilities
 
           if (use_vector)
             {
-              AssertDimension(data.size(), size);
-              std::fill(data.begin() + start, data.begin() + end, value);
+              if (data.empty() && end > start)
+                {
+                  // in debug mode, we want to track whether we set all
+                  // indices, so we first fill an invalid index and only later
+                  // the actual ones, whereas we simply assign the given rank
+                  // to the complete vector the first time we pass around in
+                  // this function in release mode to avoid touching data
+                  // unnecessarily (and overwrite the smaller pieces), as the
+                  // locally owned part comes first
+#ifdef DEBUG
+                  data.resize(size, invalid_index_value);
+                  std::fill(data.begin() + start, data.begin() + end, value);
+#else
+                  data.resize(size, value);
+#endif
+                }
+              else
+                {
+                  AssertDimension(data.size(), size);
+                  std::fill(data.begin() + start, data.begin() + end, value);
+                }
             }
           else
             {
@@ -131,6 +147,9 @@ namespace Utilities
 
           if (use_vector)
             {
+              if (data.empty())
+                return false;
+
               AssertDimension(data.size(), size);
               return data[index] != invalid_index_value;
             }

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.