Skip to content

Commit 0672950

Browse files
committed
Moving to uint64_t and updating MPI types as requested by @paulromano
1 parent 2a802a1 commit 0672950

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

include/openmc/constants.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define OPENMC_CONSTANTS_H
66

77
#include <cmath>
8+
#include <cstdint>
89
#include <limits>
910

1011
#include "openmc/array.h"
@@ -342,7 +343,7 @@ enum class GeometryType { CSG, DAG };
342343
//==============================================================================
343344
// Volume Calculation Constants
344345

345-
constexpr size_t SIZE_T_MAX {std::numeric_limits<size_t>::max()};
346+
constexpr uint64_t UINT64_T_MAX {std::numeric_limits<uint64_t>::max()};
346347

347348
} // namespace openmc
348349

include/openmc/volume_calc.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#ifndef OPENMC_VOLUME_CALC_H
22
#define OPENMC_VOLUME_CALC_H
33

4+
#include <cstdint>
5+
#include <string>
6+
47
#include "openmc/array.h"
58
#include "openmc/position.h"
69
#include "openmc/tallies/trigger.h"
@@ -10,7 +13,6 @@
1013
#include "xtensor/xtensor.hpp"
1114

1215
#include <gsl/gsl-lite.hpp>
13-
#include <string>
1416

1517
namespace openmc {
1618

@@ -69,7 +71,8 @@ class VolumeCalculation {
6971
//! \param[in] i_material Index in global materials vector
7072
//! \param[in,out] indices Vector of material indices
7173
//! \param[in,out] hits Number of hits corresponding to each material
72-
void check_hit(int i_material, vector<int>& indices, vector<int>& hits) const;
74+
void check_hit(
75+
int i_material, vector<uint64_t>& indices, vector<uint64_t>& hits) const;
7376
};
7477

7578
//==============================================================================

src/volume_calc.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@ vector<VolumeCalculation::Result> VolumeCalculation::execute() const
9999
{
100100
// Shared data that is collected from all threads
101101
int n = domain_ids_.size();
102-
vector<vector<int32_t>> master_indices(
102+
vector<vector<uint64_t>> master_indices(
103103
n); // List of material indices for each domain
104-
vector<vector<size_t>> master_hits(
104+
vector<vector<uint64_t>> master_hits(
105105
n); // Number of hits for each material in each domain
106106
int iterations = 0;
107107

108108
// Divide work over MPI processes
109-
size_t min_samples = n_samples_ / mpi::n_procs;
110-
size_t remainder = n_samples_ % mpi::n_procs;
111-
size_t i_start, i_end;
109+
uint64_t min_samples = n_samples_ / mpi::n_procs;
110+
uint64_t remainder = n_samples_ % mpi::n_procs;
111+
uint64_t i_start, i_end;
112112
if (mpi::rank < remainder) {
113113
i_start = (min_samples + 1) * mpi::rank;
114114
i_end = i_start + min_samples + 1;
@@ -123,14 +123,14 @@ vector<VolumeCalculation::Result> VolumeCalculation::execute() const
123123
#pragma omp parallel
124124
{
125125
// Variables that are private to each thread
126-
vector<vector<int>> indices(n);
127-
vector<vector<int>> hits(n);
126+
vector<vector<uint64_t>> indices(n);
127+
vector<vector<uint64_t>> hits(n);
128128
Particle p;
129129

130130
// Sample locations and count hits
131131
#pragma omp for
132132
for (size_t i = i_start; i < i_end; i++) {
133-
int64_t id = iterations * n_samples_ + i;
133+
uint64_t id = iterations * n_samples_ + i;
134134
uint64_t seed = init_seed(id, STREAM_VOLUME);
135135

136136
p.n_coord() = 1;
@@ -223,12 +223,13 @@ vector<VolumeCalculation::Result> VolumeCalculation::execute() const
223223
// bump iteration counter and get total number
224224
// of samples at this point
225225
iterations++;
226-
size_t total_samples = iterations * n_samples_;
226+
uint64_t total_samples = iterations * n_samples_;
227227

228228
// warn user if total sample size is greater than what the size_t type can
229229
// represent
230-
if (total_samples > SIZE_T_MAX) {
231-
warning("The number of samples has exceeded the size_t type. Volume "
230+
if (total_samples > UINT64_T_MAX) {
231+
warning("The number of samples has exceeded the type used to track hits. "
232+
"Volume "
232233
"results may be inaccurate.");
233234
}
234235

@@ -253,10 +254,11 @@ vector<VolumeCalculation::Result> VolumeCalculation::execute() const
253254
if (mpi::master) {
254255
for (int j = 1; j < mpi::n_procs; j++) {
255256
int q;
257+
// retrieve results
256258
MPI_Recv(
257-
&q, 1, MPI_INTEGER, j, 2 * j, mpi::intracomm, MPI_STATUS_IGNORE);
258-
vector<int> buffer(2 * q);
259-
MPI_Recv(buffer.data(), 2 * q, MPI_INTEGER, j, 2 * j + 1,
259+
&q, 1, MPI_UINT64_T, j, 2 * j, mpi::intracomm, MPI_STATUS_IGNORE);
260+
vector<uint64_t> buffer(2 * q);
261+
MPI_Recv(buffer.data(), 2 * q, MPI_UINT64_T, j, 2 * j + 1,
260262
mpi::intracomm, MPI_STATUS_IGNORE);
261263
for (int k = 0; k < q; ++k) {
262264
bool already_added = false;
@@ -275,14 +277,14 @@ vector<VolumeCalculation::Result> VolumeCalculation::execute() const
275277
}
276278
} else {
277279
int q = master_indices[i_domain].size();
278-
vector<int> buffer(2 * q);
280+
vector<uint64_t> buffer(2 * q);
279281
for (int k = 0; k < q; ++k) {
280282
buffer[2 * k] = master_indices[i_domain][k];
281283
buffer[2 * k + 1] = master_hits[i_domain][k];
282284
}
283285

284-
MPI_Send(&q, 1, MPI_INTEGER, 0, 2 * mpi::rank, mpi::intracomm);
285-
MPI_Send(buffer.data(), 2 * q, MPI_INTEGER, 0, 2 * mpi::rank + 1,
286+
MPI_Send(&q, 1, MPI_UINT64_T, 0, 2 * mpi::rank, mpi::intracomm);
287+
MPI_Send(buffer.data(), 2 * q, MPI_UINT64_T, 0, 2 * mpi::rank + 1,
286288
mpi::intracomm);
287289
}
288290
#endif
@@ -471,7 +473,7 @@ void VolumeCalculation::to_hdf5(
471473
}
472474

473475
void VolumeCalculation::check_hit(
474-
int i_material, vector<int>& indices, vector<int>& hits) const
476+
int i_material, vector<uint64_t>& indices, vector<uint64_t>& hits) const
475477
{
476478

477479
// Check if this material was previously hit and if so, increment count

0 commit comments

Comments
 (0)