]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix overflow in tria.n_global_active_cells() 9540/head
authorTimo Heister <timo.heister@gmail.com>
Mon, 17 Feb 2020 04:10:10 +0000 (23:10 -0500)
committerTimo Heister <timo.heister@gmail.com>
Mon, 17 Feb 2020 04:10:10 +0000 (23:10 -0500)
for large computations.

source/distributed/tria_base.cc

index 87b76f80daa35beb9112e538a3200de888022a14..189be2a997ab78799a02d9018ccf9d7a5b38a3a3 100644 (file)
@@ -217,9 +217,12 @@ namespace parallel
         if (cell->subdomain_id() == my_subdomain)
           ++number_cache.n_locally_owned_active_cells;
 
+    // Potentially cast to a 64 bit type before accumulating to avoid overflow:
     number_cache.n_global_active_cells =
-      Utilities::MPI::sum(number_cache.n_locally_owned_active_cells,
+      Utilities::MPI::sum(static_cast<types::global_dof_index>(
+                            number_cache.n_locally_owned_active_cells),
                           this->mpi_communicator);
+
     number_cache.n_global_levels =
       Utilities::MPI::max(this->n_levels(), this->mpi_communicator);
   }

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.