c++ - Storing a list of rng's in a std::array for multithreading -



c++ - Storing a list of rng's in a std::array for multithreading -

i'd multithread rng part of code using c++11.

i create bunch of rng's this:

typedef std::mt19937 mersenne_twister; typedef std::uniform_real_distribution<double> unidist; // 8 rng engines 8 consecutive seeds const size_t nrng = 8; const array<uint32_t,nrng> seed_values = {0,1,2,3,4,5,6,7}; array<mersenne_twister,nrng> engines; const array<unidist,nrng> distributions; // default constructor [0,1] interval const array<????,nrng> rngs; // type set here? for( size_t i=0; i<nrng; ++i ) engines[i].seed(seed_values[i]); rngs[i] = std::bind(distributions[i], engines[i]);

with thought can later pass each of rng objects seperate std::thread fills array form of random numbers using supplied generator. don't know type need utilize rng array. know how create 1 rng, so:

auto rng = std::bind(unidist, generator);

but need explicitely have (decltyped?) type array.

one possible type std::function<double()>, note doesn't come free. actual type of result of bind unknowable, , cannot create container element type decltype(std::bind(...)), since types not guaranteed mutually convertible -- know convert function.

if performance-critical, suggest profile , compare cost of std::function direct utilize of unidist(rngs[i]) in target code. (the distribution stateless adapter should reentrant anyway, don't need maintain more 1 re-create of it.)

c++ random c++11 decltype

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -