Skip to content

Commit 5bf97fd

Browse files
authored
Merge pull request #177 from entity-toolkit/1.3.3rc
Fixed the random number generator issue on large # of GPUs
2 parents eeef561 + 09b177b commit 5bf97fd

8 files changed

Lines changed: 26 additions & 15 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set(PROJECT_NAME entity)
77

88
project(
99
${PROJECT_NAME}
10-
VERSION 1.3.2
10+
VERSION 1.3.3
1111
LANGUAGES CXX C)
1212
add_compile_options("-D ENTITY_VERSION=\"${PROJECT_VERSION}\"")
1313
set(hash_cmd "git diff --quiet src/ && echo $(git rev-parse HEAD) ")

pgens/accretion/pgen.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ namespace user {
231231

232232
inline void InitPrtls(Domain<S, M>& local_domain) {
233233
const auto energy_dist = arch::Maxwellian<S, M>(local_domain.mesh.metric,
234-
local_domain.random_pool,
234+
local_domain.random_pool(),
235235
temperature);
236236
const auto spatial_dist = PointDistribution<S, M>(xi_min,
237237
xi_max,
@@ -252,7 +252,7 @@ namespace user {
252252

253253
void CustomPostStep(std::size_t, long double time, Domain<S, M>& local_domain) {
254254
const auto energy_dist = arch::Maxwellian<S, M>(local_domain.mesh.metric,
255-
local_domain.random_pool,
255+
local_domain.random_pool(),
256256
temperature);
257257
const auto spatial_dist = PointDistribution<S, M>(xi_min,
258258
xi_max,

pgens/reconnection/pgen.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ namespace user {
212212

213213
// current layer
214214
auto edist_cs = arch::Maxwellian<S, M>(local_domain.mesh.metric,
215-
local_domain.random_pool,
215+
local_domain.random_pool(),
216216
cs_temperature,
217217
{ ZERO, ZERO, cs_drift_u });
218218
const auto sdist_cs = CurrentLayer<S, M>(local_domain.mesh.metric,
@@ -239,7 +239,7 @@ namespace user {
239239
}
240240

241241
const auto energy_dist = arch::Maxwellian<S, M>(domain.mesh.metric,
242-
domain.random_pool,
242+
domain.random_pool(),
243243
bg_temperature);
244244

245245
const auto dx = domain.mesh.metric.template sqrt_h_<1, 1>({});

pgens/turbulence/pgen.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ namespace user {
398398

399399
// particle escape (resample velocities)
400400
const auto energy_dist = arch::Maxwellian<S, M>(domain.mesh.metric,
401-
domain.random_pool,
401+
domain.random_pool(),
402402
temperature);
403403
for (const auto& sp : { 0, 1 }) {
404404
if (domain.species[sp].npld_r() > 1) {

src/archetypes/particle_injector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ namespace arch {
254254
energy_dists.first,
255255
energy_dists.second,
256256
ONE / params.template get<real_t>("scales.V0"),
257-
domain.random_pool));
257+
domain.random_pool()));
258258
domain.species[species.first - 1].set_npart(
259259
domain.species[species.first - 1].npart() + nparticles);
260260
domain.species[species.second - 1].set_npart(
@@ -372,7 +372,7 @@ namespace arch {
372372
energy_dists.second,
373373
spatial_dist,
374374
ONE / params.template get<real_t>("scales.V0"),
375-
domain.random_pool);
375+
domain.random_pool());
376376
Kokkos::parallel_for("InjectNonUniformNumberDensity",
377377
cell_range,
378378
injector_kernel);

src/archetypes/utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ namespace arch {
5353
const auto temperature_2 = temperatures.second / mass_2;
5454

5555
const auto maxwellian_1 = arch::Maxwellian<S, M>(domain.mesh.metric,
56-
domain.random_pool,
56+
domain.random_pool(),
5757
temperature_1,
5858
drift_four_vels.first);
5959
const auto maxwellian_2 = arch::Maxwellian<S, M>(domain.mesh.metric,
60-
domain.random_pool,
60+
domain.random_pool(),
6161
temperature_2,
6262
drift_four_vels.second);
6363

src/engines/srpic.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ namespace ntt {
12911291
}
12921292

12931293
const auto maxwellian = arch::Maxwellian<S, M> { domain.mesh.metric,
1294-
domain.random_pool,
1294+
domain.random_pool(),
12951295
temp };
12961296

12971297
if (dim == in::x1) {

src/framework/domain/domain.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
#include <iomanip>
5555
#include <map>
56+
#include <optional>
5657
#include <string>
5758
#include <vector>
5859

@@ -65,7 +66,6 @@ namespace ntt {
6566
Mesh<M> mesh;
6667
Fields<D, S> fields;
6768
std::vector<Particles<D, M::CoordType>> species;
68-
random_number_pool_t random_pool;
6969

7070
/**
7171
* @brief constructor for "empty" allocation of non-local domain placeholders
@@ -81,7 +81,6 @@ namespace ntt {
8181
: mesh { ncells, extent, metric_params }
8282
, fields {}
8383
, species {}
84-
, random_pool { constant::RandomSeed }
8584
, m_index { index }
8685
, m_offset_ndomains { offset_ndomains }
8786
, m_offset_ncells { offset_ncells } {}
@@ -96,10 +95,11 @@ namespace ntt {
9695
: mesh { ncells, extent, metric_params }
9796
, fields { ncells }
9897
, species { species_params.begin(), species_params.end() }
99-
, random_pool { constant::RandomSeed + static_cast<std::uint64_t>(index) }
10098
, m_index { index }
10199
, m_offset_ndomains { offset_ndomains }
102-
, m_offset_ncells { offset_ncells } {}
100+
, m_offset_ncells { offset_ncells }
101+
, m_random_number_pool { constant::RandomSeed +
102+
static_cast<std::uint64_t>(index) } {}
103103

104104
#if defined(MPI_ENABLED)
105105
[[nodiscard]]
@@ -145,6 +145,14 @@ namespace ntt {
145145
return fields.memory_footprint() == 0 and sp_footprint == 0;
146146
}
147147

148+
[[nodiscard]]
149+
auto random_pool() -> random_number_pool_t& {
150+
raise::ErrorIf(not m_random_number_pool.has_value(),
151+
"random_pool() called on a placeholder domain",
152+
HERE);
153+
return m_random_number_pool.value();
154+
}
155+
148156
/* setters -------------------------------------------------------------- */
149157
auto set_neighbor_idx(const dir::direction_t<D>& dir, unsigned int idx) -> void {
150158
m_neighbor_idx[dir] = idx;
@@ -161,6 +169,9 @@ namespace ntt {
161169
dir::map_t<D, unsigned int> m_neighbor_idx;
162170
// MPI rank of the domain (used only when MPI enabled)
163171
int m_mpi_rank;
172+
173+
// random number pool for the domain
174+
std::optional<random_number_pool_t> m_random_number_pool;
164175
};
165176

166177
template <SimEngine::type S, class M>

0 commit comments

Comments
 (0)