]> https://gitweb.dealii.org/ - dealii.git/commitdiff
use range loop in SparsityTools::distribute_sparsity_pattern()
authorDenis Davydov <davydden@gmail.com>
Wed, 20 Mar 2019 10:59:53 +0000 (11:59 +0100)
committerDenis Davydov <davydden@gmail.com>
Wed, 20 Mar 2019 10:59:53 +0000 (11:59 +0100)
source/lac/sparsity_tools.cc

index eeba2592de4bdfa0dedc5ff2d8531122dc01d60f..2ec2422ad64f60d6f08d948fa971e9777ed5e7bf 100644 (file)
@@ -925,30 +925,27 @@ namespace SparsityTools
     for (DynamicSparsityPattern::size_type i = 0; i < rows_per_cpu.size(); ++i)
       start_index[i + 1] = start_index[i] + rows_per_cpu[i];
 
+    IndexSet owned(start_index.back());
+    owned.add_range(start_index[myid], start_index[myid] + rows_per_cpu[myid]);
+
+    IndexSet myrange_non_owned(myrange);
+    myrange_non_owned.subtract_set(owned);
+
     using map_vec_t =
       std::map<unsigned int, std::vector<DynamicSparsityPattern::size_type>>;
 
     map_vec_t send_data;
 
     {
-      unsigned int dest_cpu         = 0;
-      const auto   n_local_rel_rows = myrange.n_elements();
-      for (DynamicSparsityPattern::size_type row_idx = 0;
-           row_idx < n_local_rel_rows;
-           ++row_idx)
+      unsigned int dest_cpu = 0;
+      for (const auto &row : myrange_non_owned)
         {
-          const auto row = myrange.nth_index_in_set(row_idx);
-
           // calculate destination CPU
           while (row >= start_index[dest_cpu + 1])
             ++dest_cpu;
 
-          // skip myself
-          if (dest_cpu == myid)
-            {
-              row_idx += rows_per_cpu[myid] - 1;
-              continue;
-            }
+          // we removed owned, thus shall not hit ourselves
+          Assert(dest_cpu != myid, ExcInternalError());
 
           const auto rlen = dsp.row_length(row);
 

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.