Skip to content

Commit 354572b

Browse files
committed
PGI openacc compiler modifications
1 parent d9cbcdf commit 354572b

File tree

9 files changed

+88
-55
lines changed

9 files changed

+88
-55
lines changed

src/core/data/grid/gridlayout.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ namespace core
794794
* @brief AMRToLocal returns the local index associated with the given AMR one.
795795
* This method only deals with **cell** indexes.
796796
*/
797+
797798
template<typename T>
798799
auto AMRToLocal(Point<T, dimension> AMRPoint) const
799800
{

src/core/data/ions/particle_initializers/maxwellian_particle_initializer.hpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class MaxwellianParticleInitializer : public ParticleInitializer<ParticleArray,
5656

5757

5858
/**
59-
* @brief load pacore
60-
} // namespace PHARErticles in a ParticleArray in a domain defined by the given layout
59+
* @brief load particles in a ParticleArray in a domain defined by the given layout
6160
*/
6261
void loadParticles(ParticleArray& particles, GridLayout const& layout) const override;
6362

@@ -143,16 +142,6 @@ void MaxwellianParticleInitializer<ParticleArray, GridLayout>::loadParticles(
143142
};
144143

145144

146-
auto deltas = [](auto& pos, auto& gen) -> std::array<double, dimension> {
147-
if constexpr (dimension == 1)
148-
return {pos(gen)};
149-
if constexpr (dimension == 2)
150-
return {pos(gen), pos(gen)};
151-
if constexpr (dimension == 3)
152-
return {pos(gen), pos(gen), pos(gen)};
153-
};
154-
155-
156145
// in the following two calls,
157146
// primal indexes are given here because that's what cellCenteredCoordinates takes
158147

@@ -196,9 +185,10 @@ void MaxwellianParticleInitializer<ParticleArray, GridLayout>::loadParticles(
196185
if (basis_ == Basis::Magnetic)
197186
particleVelocity = basisTransform(basis, particleVelocity);
198187

199-
particles.emplace_back(Particle{cellWeight, particleCharge_,
200-
AMRCellIndex.template toArray<int>(),
201-
deltas(deltaDistrib, randGen), particleVelocity});
188+
particles.emplace_back(
189+
Particle{cellWeight, particleCharge_, AMRCellIndex.template toArray<int>(),
190+
core::ConstArrayFrom<dimension>([&] { return deltaDistrib(randGen); }),
191+
particleVelocity});
202192
}
203193
}
204194
}

src/core/data/particles/particle_packer.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010

1111
namespace PHARE::core
1212
{
13+
// PGI compiler (nvc++ 21.3-0) doesn't like static initializations of arrays,
14+
// would result in empty strings
15+
inline std::array<std::string, 5> packer_keys()
16+
{
17+
// The order of this array must match the tuple order of ParticlePacker::get(particle)
18+
return {"weight", "charge", "iCell", "delta", "v"};
19+
}
20+
1321
template<std::size_t dim>
1422
class ParticlePacker
1523
{
@@ -31,8 +39,6 @@ class ParticlePacker
3139
return get(particle);
3240
}
3341

34-
static auto& keys() { return keys_; }
35-
3642
auto get(std::size_t i) const { return get(particles_[i]); }
3743
bool hasNext() const { return it_ < particles_.size(); }
3844
auto next() { return get(it_++); }
@@ -55,10 +61,10 @@ class ParticlePacker
5561
}
5662
}
5763

64+
5865
private:
5966
ParticleArray<dim> const& particles_;
6067
std::size_t it_ = 0;
61-
static inline std::array<std::string, 5> keys_{"weight", "charge", "iCell", "delta", "v"};
6268
};
6369

6470

src/core/data/particles/particle_utilities.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ auto positionAsPoint(Particle<GridLayout::dimension> const& particle, GridLayout
2121
auto origin = layout.origin();
2222
auto startIndexes = layout.physicalStartIndex(QtyCentering::primal);
2323
auto meshSize = layout.meshSize();
24-
auto iCell = layout.AMRToLocal(Point{particle.iCell});
24+
auto iCell = layout.AMRToLocal(Point<int, GridLayout::dimension>{particle.iCell});
2525

2626
for (auto iDim = 0u; iDim < GridLayout::dimension; ++iDim)
2727
{

src/core/utilities/mpi_utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int rank();
3434
void barrier();
3535

3636
template<typename Data>
37-
auto mpi_type_for()
37+
MPI_Datatype mpi_type_for()
3838
{
3939
if constexpr (std::is_same_v<double, Data>)
4040
return MPI_DOUBLE;

src/core/utilities/point/point.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace core
3737
static constexpr std::size_t dimension = dim;
3838
using type = Type;
3939

40+
4041
template<typename... Indexes>
4142
constexpr Point(Indexes... index)
4243
: r{{index...}}
@@ -172,12 +173,15 @@ namespace core
172173
std::array<Type, dim> r{};
173174
};
174175

175-
template<typename... Indexes>
176+
template<typename... Indexes, // block constructor from use if not int/float/etc
177+
typename
178+
= typename std::enable_if<(true && ... && std::is_arithmetic_v<Indexes>), void>::type>
176179
Point(Indexes... indexes)
177180
->Point<typename std::tuple_element<0, std::tuple<Indexes...>>::type, sizeof...(indexes)>;
178181

179182

180183

184+
181185
} // namespace core
182186
} // namespace PHARE
183187

src/core/utilities/types.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ namespace core
167167
return arr;
168168
}
169169

170+
template<std::size_t size, typename FN>
171+
constexpr auto ConstArrayFrom(FN fn)
172+
{
173+
std::array<decltype(fn()), size> arr{};
174+
for (uint8_t i = 0; i < size; i++)
175+
arr[i] = fn();
176+
return arr;
177+
}
178+
170179
template<typename Type>
171180
std::vector<Type> displacementFrom(std::vector<Type> const& input)
172181
{

src/diagnostic/detail/h5writer.hpp

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,16 @@ void Writer<ModelView>::createDatasetsPerMPI(HiFile& h5file, std::string path, S
309309
auto mpi_size = core::mpi::size();
310310
auto sizes = core::mpi::collect(dataSetSize, mpi_size);
311311
auto paths = core::mpi::collect(path, mpi_size);
312+
312313
for (int i = 0; i < mpi_size; i++)
313314
{
314315
if (is_zero(sizes[i]))
315316
continue;
317+
316318
createGroupsToDataSet(h5file, paths[i]);
319+
320+
assert(paths[i].back() != '/');
321+
317322
h5file.createDataSet<Type>(paths[i], HighFive::DataSpace(sizes[i]));
318323
}
319324
}
@@ -328,34 +333,43 @@ void Writer<ModelView>::createDatasetsPerMPI(HiFile& h5file, std::string path, S
328333
* sizes. Recommended to use similar sized paths, if possible. key is always assumed to the be
329334
* the same
330335
*/
336+
namespace
337+
{
338+
// openacc compiler has issues with the lambda version
339+
template<typename H5Node, typename T>
340+
void _doAttribute(H5Node&& node, std::string const& key, core::Span<T, int> const& value)
341+
{
342+
node.template createAttribute<T>(key, HighFive::DataSpace(value.size()))
343+
.write(value.data());
344+
}
345+
346+
template<typename H5Node, typename T>
347+
void _doAttribute(H5Node&& node, std::string const& key, T const& value)
348+
{
349+
node.template createAttribute<T>(key, HighFive::DataSpace::From(value)).write(value);
350+
}
351+
352+
template<typename T>
353+
auto _values(std::vector<T> const& data, int mpi_size)
354+
{
355+
return core::mpi::collect_raw(data, mpi_size);
356+
}
357+
358+
template<typename T>
359+
auto _values(T const& data, int mpi_size)
360+
{
361+
return core::mpi::collect(data, mpi_size);
362+
}
363+
} // namespace
364+
331365
template<typename ModelView>
332366
template<typename Data>
333367
void Writer<ModelView>::writeAttributesPerMPI(HiFile& h5file, std::string path, std::string key,
334368
Data const& data)
335369
{
336-
constexpr bool data_is_vector = core::is_std_vector_v<Data>;
337-
338-
auto doAttribute = [&](auto node, auto const& _key, auto const& value) {
339-
if constexpr (data_is_vector)
340-
{
341-
if (value.size())
342-
node.template createAttribute<typename Data::value_type>(
343-
_key, HighFive::DataSpace(value.size()))
344-
.write(value.data());
345-
}
346-
else
347-
node.template createAttribute<Data>(_key, HighFive::DataSpace::From(value))
348-
.write(value);
349-
};
350-
351370
int mpi_size = core::mpi::size();
352-
auto values = [&]() {
353-
if constexpr (data_is_vector)
354-
return core::mpi::collect_raw(data, mpi_size);
355-
else
356-
return core::mpi::collect(data, mpi_size);
357-
}();
358-
auto paths = core::mpi::collect(path, mpi_size);
371+
auto values = _values(data, mpi_size);
372+
auto paths = core::mpi::collect(path, mpi_size);
359373

360374
for (int i = 0; i < mpi_size; i++)
361375
{
@@ -366,13 +380,13 @@ void Writer<ModelView>::writeAttributesPerMPI(HiFile& h5file, std::string path,
366380
if (h5file.exist(keyPath) && h5file.getObjectType(keyPath) == HighFive::ObjectType::Dataset)
367381
{
368382
if (!h5file.getDataSet(keyPath).hasAttribute(key))
369-
doAttribute(h5file.getDataSet(keyPath), key, values[i]);
383+
_doAttribute(h5file.getDataSet(keyPath), key, values[i]);
370384
}
371385
else // group
372386
{
373387
createGroupsToDataSet(h5file, keyPath + "/dataset");
374388
if (!h5file.getGroup(keyPath).hasAttribute(key))
375-
doAttribute(h5file.getGroup(keyPath), key, values[i]);
389+
_doAttribute(h5file.getGroup(keyPath), key, values[i]);
376390
}
377391
}
378392
}
@@ -454,4 +468,6 @@ void Writer<ModelView>::writeDatasets_(std::vector<DiagnosticProperties*> const&
454468

455469
} /* namespace PHARE::diagnostic::h5 */
456470

471+
472+
457473
#endif /* PHARE_DETAIL_DIAGNOSTIC_HIGHFIVE_H */

src/diagnostic/detail/types/particle.hpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <string>
1313
#include <memory>
1414

15+
16+
1517
namespace PHARE::diagnostic::h5
1618
{
1719
/*
@@ -61,6 +63,10 @@ class ParticlesDiagnosticWriter : public H5TypeWriter<H5Writer>
6163
DiagnosticProperties&, Attributes&,
6264
std::unordered_map<std::size_t, std::vector<std::pair<std::string, Attributes>>>&,
6365
std::size_t maxLevel) override;
66+
67+
private:
68+
// PGI compiler (nvc++ 21.3-0) doesn't like static initializations of arrays
69+
std::array<std::string, 5> packer_keys_ = core::packer_keys();
6470
};
6571

6672

@@ -95,8 +101,9 @@ void ParticlesDiagnosticWriter<H5Writer>::getDataSetInfo(DiagnosticProperties& d
95101

96102
auto particleInfo = [&](auto& attr, auto& particles) {
97103
std::size_t part_idx = 0;
104+
auto const& keys = packer_keys_;
98105
core::apply(Packer::empty(), [&](auto const& arg) {
99-
attr[Packer::keys()[part_idx]] = getSize(arg, particles.size());
106+
attr[keys[part_idx]] = getSize(arg, particles.size());
100107
++part_idx;
101108
});
102109
};
@@ -147,8 +154,8 @@ void ParticlesDiagnosticWriter<H5Writer>::initDataSets(
147154
std::string path{h5Writer_.getPatchPathAddTimestamp(lvl, patchID) + "/"};
148155
std::size_t part_idx = 0;
149156
core::apply(Packer::empty(), [&](auto const& arg) {
150-
createDataSet(path + Packer::keys()[part_idx], attr, Packer::keys()[part_idx], arg,
151-
null);
157+
auto const& keys = packer_keys_;
158+
createDataSet(path + keys[part_idx], attr, keys[part_idx], arg, null);
152159
++part_idx;
153160
});
154161
this->writeGhostsAttr_(h5file, path, core::ghostWidthForParticles<interpOrder>(), null);
@@ -187,12 +194,12 @@ void ParticlesDiagnosticWriter<H5Writer>::write(DiagnosticProperties& diagnostic
187194
core::ContiguousParticles<dimension> copy{particles.size()};
188195
packer.pack(copy);
189196

190-
191-
h5file.template write_data_set_flat<2>(path + packer.keys()[0], copy.weight.data());
192-
h5file.template write_data_set_flat<2>(path + packer.keys()[1], copy.charge.data());
193-
h5file.template write_data_set_flat<2>(path + packer.keys()[2], copy.iCell.data());
194-
h5file.template write_data_set_flat<2>(path + packer.keys()[3], copy.delta.data());
195-
h5file.template write_data_set_flat<2>(path + packer.keys()[4], copy.v.data());
197+
auto const& keys = packer_keys_;
198+
h5file.template write_data_set_flat<2>(path + keys[0], copy.weight.data());
199+
h5file.template write_data_set_flat<2>(path + keys[1], copy.charge.data());
200+
h5file.template write_data_set_flat<2>(path + keys[2], copy.iCell.data());
201+
h5file.template write_data_set_flat<2>(path + keys[3], copy.delta.data());
202+
h5file.template write_data_set_flat<2>(path + keys[4], copy.v.data());
196203
};
197204

198205
auto checkWrite = [&](auto& tree, auto pType, auto& ps) {
@@ -237,7 +244,7 @@ void ParticlesDiagnosticWriter<H5Writer>::writeAttributes(
237244
writeAttributes_(diagnostic, h5file, fileAttributes, patchAttributes, maxLevel);
238245
}
239246

240-
241247
} // namespace PHARE::diagnostic::h5
242248

249+
243250
#endif /* PHARE_DIAGNOSTIC_DETAIL_TYPES_PARTICLE_H */

0 commit comments

Comments
 (0)