Skip to content

Commit

Permalink
PGI C++ compiling/test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Apr 29, 2021
1 parent 5a3c7ce commit dd76496
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 61 deletions.
2 changes: 2 additions & 0 deletions res/cmake/dep/highfive.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ if(HighFive)
)
set(HIGHFIVE_USE_BOOST OFF)
set(HIGHFIVE_BUILD_DOCS OFF) # conflicts with phare doc target
set(HIGHFIVE_EXAMPLES OFF)
set(HIGHFIVE_PARALLEL_HDF5 ON) # causes failure if cannot occure
add_subdirectory(${HIGHFIVE_SRC})

message("HighFive enabled - checking HDF5")
Expand Down
3 changes: 2 additions & 1 deletion res/cmake/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# if level >= PHARE_EXEC_LEVEL_MIN AND level <= PHARE_EXEC_LEVEL_MAX
#

# this define breaks pgcc / and appears unnecessary
# sed -i 's/# define GTEST_CAN_STREAM_RESULTS_ 1/# define GTEST_CAN_STREAM_RESULTS_ 0/g' subprojects/googletest/googletest/include/gtest/internal/gtest-port.h

if (test AND ${PHARE_EXEC_LEVEL_MIN} GREATER 0) # 0 = no tests

Expand All @@ -34,7 +36,6 @@ if (test AND ${PHARE_EXEC_LEVEL_MIN} GREATER 0) # 0 = no tests

function(set_exe_paths_ binary)
set_property(TEST ${binary} PROPERTY ENVIRONMENT "PYTHONPATH=${PHARE_PYTHONPATH}")
set_property(TEST ${binary} APPEND PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}")
endfunction(set_exe_paths_)

function(add_phare_test_ binary)
Expand Down
2 changes: 1 addition & 1 deletion src/amr/tagging/tagger.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#ifndef PHARE_TAGGER_H
#define PHARE_TAGGER_H

#include "physical_models/physical_model.h"
#include "amr/types/amr_types.h"
#include "solver/physical_models/physical_model.h"

#include <memory>

Expand Down
9 changes: 8 additions & 1 deletion src/core/data/grid/gridlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,9 @@ namespace core
* @brief AMRToLocal returns the local index associated with the given AMR one.
* This method only deals with **cell** indexes.
*/

template<typename T>
auto AMRToLocal(Point<T, dimension> AMRPoint) const
auto AMRToLocal(std::array<T, dimension> const& AMRPoint) const
{
static_assert(std::is_integral_v<T>, "Error, must be MeshIndex (integral Point)");
Point<T, dimension> localPoint;
Expand All @@ -774,6 +775,12 @@ namespace core
return localPoint;
}

template<typename T>
auto AMRToLocal(Point<T, dimension> AMRPoint) const
{
return AMRToLocal(AMRPoint());
}


/**
* @brief AMRToLocal returns the local Box associated with the given AMR one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,6 @@ void MaxwellianParticleInitializer<ParticleArray, GridLayout>::loadParticles(
};


auto deltas = [](auto& pos, auto& gen) -> std::array<float, dimension> {
if constexpr (dimension == 1)
return {pos(gen)};
if constexpr (dimension == 2)
return {pos(gen), pos(gen)};
if constexpr (dimension == 3)
return {pos(gen), pos(gen), pos(gen)};
};


// in the following two calls,
// primal indexes are given here because that's what cellCenteredCoordinates takes

Expand Down Expand Up @@ -197,9 +187,10 @@ void MaxwellianParticleInitializer<ParticleArray, GridLayout>::loadParticles(
if (basis_ == Basis::Magnetic)
particleVelocity = basisTransform(basis, particleVelocity);

particles.emplace_back(Particle{cellWeight, particleCharge_,
AMRCellIndex.template toArray<int>(),
deltas(deltaDistrib, randGen), particleVelocity});
particles.emplace_back(
Particle{cellWeight, particleCharge_, AMRCellIndex.template toArray<int>(),
core::ConstArrayFrom<dimension>([&] { return deltaDistrib(randGen); }),
particleVelocity});
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/core/data/particles/particle_packer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

namespace PHARE::core
{
// PGI compiler doesn't (didn't at least) like static initializations of arrays, would result in an
// empty string
inline std::array<std::string, 5> packer_keys()
{
return {"weight", "charge", "iCell", "delta", "v"};
}

template<std::size_t dim>
class ParticlePacker
{
Expand All @@ -31,8 +38,6 @@ class ParticlePacker
return get(particle);
}

static auto& keys() { return keys_; }

auto get(std::size_t i) const { return get(particles_[i]); }
bool hasNext() const { return it_ < particles_.size(); }
auto next() { return get(it_++); }
Expand All @@ -55,10 +60,10 @@ class ParticlePacker
}
}


private:
ParticleArray<dim> const& particles_;
std::size_t it_ = 0;
static inline std::array<std::string, 5> keys_{"weight", "charge", "iCell", "delta", "v"};
};


Expand Down
2 changes: 1 addition & 1 deletion src/core/data/particles/particle_utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace core
auto origin = layout.origin();
auto startIndexes = layout.physicalStartIndex(QtyCentering::primal);
auto meshSize = layout.meshSize();
auto iCell = layout.AMRToLocal(Point{particle.iCell});
auto iCell = layout.AMRToLocal(particle.iCell);

for (auto iDim = 0u; iDim < GridLayout::dimension; ++iDim)
{
Expand Down
8 changes: 4 additions & 4 deletions src/core/numerics/interpolator/interpolator.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ namespace core
auto indexAndWeightDual = [this, &layout](auto const& part) {
for (auto iDim = 0u; iDim < dimension; ++iDim)
{
auto iCell = layout.AMRToLocal(Point{part.iCell});
auto iCell = layout.AMRToLocal(part.iCell);
double normalizedPos = iCell[iDim] + part.delta[iDim] + dualOffset(interpOrder);

startIndex_[centering2int(QtyCentering::dual)][iDim]
Expand All @@ -550,7 +550,7 @@ namespace core
auto indexAndWeightPrimal = [this, &layout](auto const& part) {
for (auto iDim = 0u; iDim < dimension; ++iDim)
{
auto iCell = layout.AMRToLocal(Point{part.iCell});
auto iCell = layout.AMRToLocal(part.iCell);
double normalizedPos = iCell[iDim] + part.delta[iDim];

startIndex_[centering2int(QtyCentering::primal)][iDim]
Expand Down Expand Up @@ -623,7 +623,7 @@ namespace core
auto indexAndWeightDual = [this, &layout](auto const& part) {
for (auto iDim = 0u; iDim < dimension; ++iDim)
{
auto iCell = layout.AMRToLocal(Point{part.iCell});
auto iCell = layout.AMRToLocal(part.iCell);
double normalizedPos = iCell[iDim] + part.delta[iDim] + dualOffset(interpOrder);

startIndex_[centering2int(QtyCentering::dual)][iDim]
Expand All @@ -639,7 +639,7 @@ namespace core
auto indexAndWeightPrimal = [this, &layout](auto const& part) {
for (auto iDim = 0u; iDim < dimension; ++iDim)
{
auto iCell = layout.AMRToLocal(Point{part.iCell});
auto iCell = layout.AMRToLocal(part.iCell);
double normalizedPos = iCell[iDim] + part.delta[iDim];

startIndex_[centering2int(QtyCentering::primal)][iDim]
Expand Down
10 changes: 5 additions & 5 deletions src/core/utilities/mpi_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int size();
int rank();

template<typename Data>
auto mpi_type_for()
MPI_Datatype mpi_type_for()
{
if constexpr (std::is_same_v<double, Data>)
return MPI_DOUBLE;
Expand All @@ -45,7 +45,7 @@ auto mpi_type_for()
return MPI_UINT64_T;
else if constexpr (std::is_same_v<char, Data>)
return MPI_CHAR;

// don't return anything = compile failure if tried to use this function
}

Expand Down Expand Up @@ -73,9 +73,9 @@ void _collect_vector(SendBuff const& sendBuff, RcvBuff& rcvBuff, std::vector<int
std::vector<int> const& displs, int const mpi_size)
{
auto mpi_type = mpi_type_for<Data>();

assert(recvcounts.size() == displs.size() and static_cast<int>(displs.size()) == mpi_size);

MPI_Allgatherv( // MPI_Allgatherv
sendBuff.data(), // void *sendbuf,
sendBuff.size(), // int sendcount,
Expand All @@ -85,7 +85,7 @@ void _collect_vector(SendBuff const& sendBuff, RcvBuff& rcvBuff, std::vector<int
displs.data(), // int *displs,
mpi_type, // MPI_Datatype recvtype,
MPI_COMM_WORLD // MPI_Comm comm
);
);
}

template<typename Vector>
Expand Down
1 change: 1 addition & 0 deletions src/core/utilities/point/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ namespace core
auto begin() { return r.begin(); }
auto end() { return r.end(); }

auto const& operator()() const { return r; }

private:
std::array<Type, dim> r{};
Expand Down
9 changes: 9 additions & 0 deletions src/core/utilities/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ namespace core
return arr;
}

template<std::size_t size, typename FN>
constexpr auto ConstArrayFrom(FN fn)
{
std::array<decltype(fn()), size> arr{};
for (uint8_t i = 0; i < size; i++)
arr[i] = fn();
return arr;
}

template<typename Type>
std::vector<Type> displacementFrom(std::vector<Type> const& input)
{
Expand Down
62 changes: 41 additions & 21 deletions src/diagnostic/detail/h5writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "core/utilities/types.h"



namespace PHARE::diagnostic::h5
{
template<typename H5Writer>
Expand Down Expand Up @@ -287,11 +288,16 @@ void Writer<ModelView>::createDatasetsPerMPI(HiFile& h5file, std::string path,
auto mpi_size = core::mpi::size();
auto sizes = core::mpi::collect(dataSetSize, mpi_size);
auto paths = core::mpi::collect(path, mpi_size);

for (int i = 0; i < mpi_size; i++)
{
if (sizes[i] == 0)
continue;

createGroupsToDataSet(h5file, paths[i]);

assert(paths[i].back() != '/');

h5file.createDataSet<Type>(paths[i], HighFive::DataSpace(sizes[i]));
}
}
Expand All @@ -306,31 +312,43 @@ void Writer<ModelView>::createDatasetsPerMPI(HiFile& h5file, std::string path,
* sizes. Recommended to use similar sized paths, if possible. key is always assumed to the be
* the same
*/
namespace
{
// openacc compiler has issues with the lambda version
template<typename H5Node, typename T>
void _doAttribute(H5Node&& node, std::string const& key, core::Span<T, int> const& value)
{
node.template createAttribute<T>(key, HighFive::DataSpace(value.size()))
.write(value.data());
}

template<typename H5Node, typename T>
void _doAttribute(H5Node&& node, std::string const& key, T const& value)
{
node.template createAttribute<T>(key, HighFive::DataSpace::From(value)).write(value);
}

template<typename T>
auto _values(std::vector<T> const& data, int mpi_size)
{
return core::mpi::collect_raw(data, mpi_size);
}

template<typename T>
auto _values(T const& data, int mpi_size)
{
return core::mpi::collect(data, mpi_size);
}
}

template<typename ModelView>
template<typename Data>
void Writer<ModelView>::writeAttributesPerMPI(HiFile& h5file, std::string path, std::string key,
Data const& data)
{
constexpr bool data_is_vector = core::is_std_vector_v<Data>;

auto doAttribute = [&](auto node, auto const& _key, auto const& value) {
if constexpr (data_is_vector)
node.template createAttribute<typename Data::value_type>(
_key, HighFive::DataSpace(value.size()))
.write(value.data());
else
node.template createAttribute<Data>(_key, HighFive::DataSpace::From(value))
.write(value);
};

int mpi_size = core::mpi::size();
auto values = [&]() {
if constexpr (data_is_vector)
return core::mpi::collect_raw(data, mpi_size);
else
return core::mpi::collect(data, mpi_size);
}();
auto paths = core::mpi::collect(path, mpi_size);
auto values = _values(data, mpi_size);
auto paths = core::mpi::collect(path, mpi_size);

for (int i = 0; i < mpi_size; i++)
{
Expand All @@ -341,13 +359,13 @@ void Writer<ModelView>::writeAttributesPerMPI(HiFile& h5file, std::string path,
if (h5file.exist(keyPath) && h5file.getObjectType(keyPath) == HighFive::ObjectType::Dataset)
{
if (!h5file.getDataSet(keyPath).hasAttribute(key))
doAttribute(h5file.getDataSet(keyPath), key, values[i]);
_doAttribute(h5file.getDataSet(keyPath), key, values[i]);
}
else // group
{
createGroupsToDataSet(h5file, keyPath + "/dataset");
if (!h5file.getGroup(keyPath).hasAttribute(key))
doAttribute(h5file.getGroup(keyPath), key, values[i]);
_doAttribute(h5file.getGroup(keyPath), key, values[i]);
}
}
}
Expand Down Expand Up @@ -428,4 +446,6 @@ void Writer<ModelView>::writeDatasets_(std::vector<DiagnosticProperties*> const&

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



#endif /* PHARE_DETAIL_DIAGNOSTIC_HIGHFIVE_H */
Loading

0 comments on commit dd76496

Please sign in to comment.