From: Daniel Arndt Date: Thu, 27 Jun 2019 20:20:10 +0000 (-0400) Subject: Use std::iota, document problems X-Git-Tag: v9.2.0-rc1~1418^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4395c31119d90170d45c46c2f3d8dadc1d182315;p=dealii.git Use std::iota, document problems --- diff --git a/source/base/function_parser.cc b/source/base/function_parser.cc index e128460f79..1c40150bfa 100644 --- a/source/base/function_parser.cc +++ b/source/base/function_parser.cc @@ -248,6 +248,8 @@ namespace internal // for each seed an unique random number generator is created, // which is initialized with the seed itself + // we could use std::mt19937 but doing so results in compiler-dependent + // output. static std::map rng_map; if (rng_map.find(seed) == rng_map.end()) diff --git a/source/base/utilities.cc b/source/base/utilities.cc index 84d268deb5..7b77133809 100644 --- a/source/base/utilities.cc +++ b/source/base/utilities.cc @@ -764,7 +764,9 @@ namespace Utilities // in a thread context. one could use rand_r, but this does not // produce reproducible results between threads either (though at // least it is reentrant). these two approaches being - // non-workable, use a thread-local random number generator here + // non-workable, use a thread-local random number generator here. + // we could use std::mt19937 but doing so results in compiler-dependent + // output. static Threads::ThreadLocalStorage random_number_generator; return boost::normal_distribution<>(a, sigma)(random_number_generator.get()); diff --git a/source/dofs/dof_renumbering.cc b/source/dofs/dof_renumbering.cc index 8487699a8d..9e22ce347f 100644 --- a/source/dofs/dof_renumbering.cc +++ b/source/dofs/dof_renumbering.cc @@ -2134,11 +2134,14 @@ namespace DoFRenumbering Assert(new_indices.size() == n_dofs, ExcDimensionMismatch(new_indices.size(), n_dofs)); - for (unsigned int i = 0; i < n_dofs; ++i) - new_indices[i] = i; + std::iota(new_indices.begin(), + new_indices.end(), + types::global_dof_index(0)); // shuffle the elements; the following is essentially std::shuffle (which // is new in C++11) but with a boost URNG + // we could use std::mt19937 here but doing so results in compiler-dependent + // output ::boost::mt19937 random_number_generator; for (unsigned int i = 1; i < n_dofs; ++i) { @@ -2165,11 +2168,14 @@ namespace DoFRenumbering Assert(new_indices.size() == n_dofs, ExcDimensionMismatch(new_indices.size(), n_dofs)); - for (unsigned int i = 0; i < n_dofs; ++i) - new_indices[i] = i; + std::iota(new_indices.begin(), + new_indices.end(), + types::global_dof_index(0)); // shuffle the elements; the following is essentially std::shuffle (which // is new in C++11) but with a boost URNG + // we could use std::mt19937 here but doing so results in + // compiler-dependent output ::boost::mt19937 random_number_generator; for (unsigned int i = 1; i < n_dofs; ++i) { diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index 3f28240a68..d0890f014d 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -1172,6 +1172,8 @@ namespace GridTools // if you call the function twice on the same mesh, then you will // get the same mesh. this would not be the case if you used // the rand() function, which carries around some internal state + // we could use std::mt19937 but doing so results in compiler-dependent + // output. boost::random::mt19937 rng; boost::random::uniform_real_distribution<> uniform_distribution(-1, 1);