Skip to content

Commit

Permalink
Apply pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tools authored and franzpoeschel committed Nov 23, 2021
1 parent 8592bf8 commit c7dbf24
Show file tree
Hide file tree
Showing 177 changed files with 22,131 additions and 21,184 deletions.
41 changes: 20 additions & 21 deletions examples/10_streaming_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,48 @@
using std::cout;
using namespace openPMD;

int
main()
int main()
{
#if openPMD_HAVE_ADIOS2
using position_t = double;
auto backends = openPMD::getFileExtensions();
if( std::find( backends.begin(), backends.end(), "sst" ) == backends.end() )
if (std::find(backends.begin(), backends.end(), "sst") == backends.end())
{
std::cout << "SST engine not available in ADIOS2." << std::endl;
return 0;
}

Series series = Series( "electrons.sst", Access::READ_ONLY );
Series series = Series("electrons.sst", Access::READ_ONLY);

for( IndexedIteration iteration : series.readIterations() )
for (IndexedIteration iteration : series.readIterations())
{
std::cout << "Current iteration: " << iteration.iterationIndex
<< std::endl;
Record electronPositions = iteration.particles[ "e" ][ "position" ];
std::array< std::shared_ptr< position_t >, 3 > loadedChunks;
std::array< Extent, 3 > extents;
std::array< std::string, 3 > const dimensions{ { "x", "y", "z" } };
Record electronPositions = iteration.particles["e"]["position"];
std::array<std::shared_ptr<position_t>, 3> loadedChunks;
std::array<Extent, 3> extents;
std::array<std::string, 3> const dimensions{{"x", "y", "z"}};

for( size_t i = 0; i < 3; ++i )
for (size_t i = 0; i < 3; ++i)
{
std::string dim = dimensions[ i ];
RecordComponent rc = electronPositions[ dim ];
loadedChunks[ i ] = rc.loadChunk< position_t >(
Offset( rc.getDimensionality(), 0 ), rc.getExtent() );
extents[ i ] = rc.getExtent();
std::string dim = dimensions[i];
RecordComponent rc = electronPositions[dim];
loadedChunks[i] = rc.loadChunk<position_t>(
Offset(rc.getDimensionality(), 0), rc.getExtent());
extents[i] = rc.getExtent();
}

iteration.close();

for( size_t i = 0; i < 3; ++i )
for (size_t i = 0; i < 3; ++i)
{
std::string dim = dimensions[ i ];
Extent const & extent = extents[ i ];
std::string dim = dimensions[i];
Extent const &extent = extents[i];
std::cout << "\ndim: " << dim << "\n" << std::endl;
auto chunk = loadedChunks[ i ];
for( size_t j = 0; j < extent[ 0 ]; ++j )
auto chunk = loadedChunks[i];
for (size_t j = 0; j < extent[0]; ++j)
{
std::cout << chunk.get()[ j ] << ", ";
std::cout << chunk.get()[j] << ", ";
}
std::cout << "\n----------\n" << std::endl;
}
Expand Down
34 changes: 16 additions & 18 deletions examples/10_streaming_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,39 @@
using std::cout;
using namespace openPMD;

int
main()
int main()
{
#if openPMD_HAVE_ADIOS2
using position_t = double;
auto backends = openPMD::getFileExtensions();
if( std::find( backends.begin(), backends.end(), "sst" ) == backends.end() )
if (std::find(backends.begin(), backends.end(), "sst") == backends.end())
{
std::cout << "SST engine not available in ADIOS2." << std::endl;
return 0;
}

// open file for writing
Series series = Series( "electrons.sst", Access::CREATE );
Series series = Series("electrons.sst", Access::CREATE);

Datatype datatype = determineDatatype< position_t >();
Datatype datatype = determineDatatype<position_t>();
constexpr unsigned long length = 10ul;
Extent global_extent = { length };
Dataset dataset = Dataset( datatype, global_extent );
std::shared_ptr< position_t > local_data(
new position_t[ length ],
[]( position_t const * ptr ) { delete[] ptr; } );
Extent global_extent = {length};
Dataset dataset = Dataset(datatype, global_extent);
std::shared_ptr<position_t> local_data(
new position_t[length], [](position_t const *ptr) { delete[] ptr; });

WriteIterations iterations = series.writeIterations();
for( size_t i = 0; i < 100; ++i )
for (size_t i = 0; i < 100; ++i)
{
Iteration iteration = iterations[ i ];
Record electronPositions = iteration.particles[ "e" ][ "position" ];
Iteration iteration = iterations[i];
Record electronPositions = iteration.particles["e"]["position"];

std::iota( local_data.get(), local_data.get() + length, i * length );
for( auto const & dim : { "x", "y", "z" } )
std::iota(local_data.get(), local_data.get() + length, i * length);
for (auto const &dim : {"x", "y", "z"})
{
RecordComponent pos = electronPositions[ dim ];
pos.resetDataset( dataset );
pos.storeChunk( local_data, Offset{ 0 }, global_extent );
RecordComponent pos = electronPositions[dim];
pos.resetDataset(dataset);
pos.storeChunk(local_data, Offset{0}, global_extent);
}
iteration.close();
}
Expand Down
53 changes: 26 additions & 27 deletions examples/12_span_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
#include <numeric> // std::iota
#include <vector>

void span_write( std::string const & filename )
void span_write(std::string const &filename)
{
using namespace openPMD;
using position_t = double;
// open file for writing
Series series = Series( filename, Access::CREATE );
Series series = Series(filename, Access::CREATE);

Datatype datatype = determineDatatype< position_t >();
Datatype datatype = determineDatatype<position_t>();
constexpr unsigned long length = 10ul;
Extent extent = { length };
Dataset dataset = Dataset( datatype, extent );
Extent extent = {length};
Dataset dataset = Dataset(datatype, extent);

std::vector< position_t > fallbackBuffer;
std::vector<position_t> fallbackBuffer;

WriteIterations iterations = series.writeIterations();
for( size_t i = 0; i < 10; ++i )
for (size_t i = 0; i < 10; ++i)
{
Iteration iteration = iterations[ i ];
Record electronPositions = iteration.particles[ "e" ][ "position" ];
Iteration iteration = iterations[i];
Record electronPositions = iteration.particles["e"]["position"];

size_t j = 0;
for( auto const & dim : { "x", "y", "z" } )
for (auto const &dim : {"x", "y", "z"})
{
RecordComponent pos = electronPositions[ dim ];
pos.resetDataset( dataset );
RecordComponent pos = electronPositions[dim];
pos.resetDataset(dataset);
/*
* This demonstrates the storeChunk() strategy (to be) used in
* PIConGPU:
Expand All @@ -45,16 +45,15 @@ void span_write( std::string const & filename )
* flushed in each iteration to make the buffer reusable.
*/
bool fallbackBufferIsUsed = false;
auto dynamicMemoryView = pos.storeChunk< position_t >(
Offset{ 0 },
auto dynamicMemoryView = pos.storeChunk<position_t>(
Offset{0},
extent,
[ &fallbackBuffer, &fallbackBufferIsUsed ]( size_t size )
{
[&fallbackBuffer, &fallbackBufferIsUsed](size_t size) {
fallbackBufferIsUsed = true;
fallbackBuffer.resize( size );
return std::shared_ptr< position_t >(
fallbackBuffer.data(), []( auto const * ) {} );
} );
fallbackBuffer.resize(size);
return std::shared_ptr<position_t>(
fallbackBuffer.data(), [](auto const *) {});
});

/*
* ADIOS2 might reallocate its internal buffers when writing
Expand All @@ -63,21 +62,21 @@ void span_write( std::string const & filename )
* directly before writing.
*/
auto span = dynamicMemoryView.currentBuffer();
if( ( i + j ) % 2 == 0 )
if ((i + j) % 2 == 0)
{
std::iota(
span.begin(),
span.end(),
position_t( 3 * i * length + j * length ) );
position_t(3 * i * length + j * length));
}
else
{
std::iota(
span.rbegin(),
span.rend(),
position_t( 3 * i * length + j * length ) );
position_t(3 * i * length + j * length));
}
if( fallbackBufferIsUsed )
if (fallbackBufferIsUsed)
{
iteration.seriesFlush();
}
Expand All @@ -89,12 +88,12 @@ void span_write( std::string const & filename )

int main()
{
for( auto const & ext : openPMD::getFileExtensions() )
for (auto const &ext : openPMD::getFileExtensions())
{
if( ext == "sst" || ext == "ssc" )
if (ext == "sst" || ext == "ssc")
{
continue;
}
span_write( "../samples/span_write." + ext );
span_write("../samples/span_write." + ext);
}
}
27 changes: 16 additions & 11 deletions examples/1_structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,33 @@
*/
#include <openPMD/openPMD.hpp>


using namespace openPMD;

int main()
{
/* The root of any openPMD output spans across all data for all iterations is a 'Series'.
/* The root of any openPMD output spans across all data for all iterations
* is a 'Series'.
* Data is either in a single file or spread across multiple files. */
Series series = Series("../samples/1_structure.h5", Access::CREATE);

/* Every element that structures your file (groups and datasets for example) can be annotated with attributes. */
series.setComment("This string will show up at the root ('/') of the output with key 'comment'.");
/* Every element that structures your file (groups and datasets for example)
* can be annotated with attributes. */
series.setComment(
"This string will show up at the root ('/') of the output with key "
"'comment'.");

/* Access to individual positions inside happens hierarchically, according to the openPMD standard.
* Creation of new elements happens on access inside the tree-like structure.
* Required attributes are initialized to reasonable defaults for every object. */
/* Access to individual positions inside happens hierarchically, according
* to the openPMD standard. Creation of new elements happens on access
* inside the tree-like structure. Required attributes are initialized to
* reasonable defaults for every object. */
ParticleSpecies electrons = series.iterations[1].particles["electrons"];

/* Data to be moved from memory to persistent storage is structured into Records,
* each holding an unbounded number of RecordComponents.
* If a Record only contains a single (scalar) component, it is treated slightly differently.
/* Data to be moved from memory to persistent storage is structured into
* Records, each holding an unbounded number of RecordComponents. If a
* Record only contains a single (scalar) component, it is treated slightly
* differently.
* https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#scalar-vector-and-tensor-records*/
Record mass = electrons["mass"];
Record mass = electrons["mass"];
RecordComponent mass_scalar = mass[RecordComponent::SCALAR];

Dataset dataset = Dataset(Datatype::DOUBLE, Extent{1});
Expand Down
50 changes: 27 additions & 23 deletions examples/2_read_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,56 @@
*/
#include <openPMD/openPMD.hpp>

#include <cstddef>
#include <iostream>
#include <memory>
#include <cstddef>


using std::cout;
using namespace openPMD;

int main()
{
Series series = Series(
"../samples/git-sample/data%T.h5",
Access::READ_ONLY
);
cout << "Read a Series with openPMD standard version "
<< series.openPMD() << '\n';
Series series =
Series("../samples/git-sample/data%T.h5", Access::READ_ONLY);
cout << "Read a Series with openPMD standard version " << series.openPMD()
<< '\n';

cout << "The Series contains " << series.iterations.size() << " iterations:";
for( auto const& i : series.iterations )
cout << "The Series contains " << series.iterations.size()
<< " iterations:";
for (auto const &i : series.iterations)
cout << "\n\t" << i.first;
cout << '\n';

Iteration i = series.iterations[100];
cout << "Iteration 100 contains " << i.meshes.size() << " meshes:";
for( auto const& m : i.meshes )
for (auto const &m : i.meshes)
cout << "\n\t" << m.first;
cout << '\n';
cout << "Iteration 100 contains " << i.particles.size() << " particle species:";
for( auto const& ps : i.particles ) {
cout << "Iteration 100 contains " << i.particles.size()
<< " particle species:";
for (auto const &ps : i.particles)
{
cout << "\n\t" << ps.first;
for( auto const& r : ps.second ) {
for (auto const &r : ps.second)
{
cout << "\n\t" << r.first;
cout << '\n';
}
}

openPMD::ParticleSpecies electrons = i.particles["electrons"];
std::shared_ptr<double> charge = electrons["charge"][openPMD::RecordComponent::SCALAR].loadChunk<double>();
std::shared_ptr<double> charge =
electrons["charge"][openPMD::RecordComponent::SCALAR]
.loadChunk<double>();
series.flush();
cout << "And the first electron particle has a charge = " << charge.get()[0];
cout << "And the first electron particle has a charge = "
<< charge.get()[0];
cout << '\n';

MeshRecordComponent E_x = i.meshes["E"]["x"];
Extent extent = E_x.getExtent();
cout << "Field E/x has shape (";
for( auto const& dim : extent )
for (auto const &dim : extent)
cout << dim << ',';
cout << ") and has datatype " << E_x.getDatatype() << '\n';

Expand All @@ -77,19 +81,19 @@ int main()
series.flush();
cout << "Chunk has been read from disk\n"
<< "Read chunk contains:\n";
for( size_t row = 0; row < chunk_extent[0]; ++row )
for (size_t row = 0; row < chunk_extent[0]; ++row)
{
for( size_t col = 0; col < chunk_extent[1]; ++col )
cout << "\t"
<< '(' << row + chunk_offset[0] << '|' << col + chunk_offset[1] << '|' << 1 << ")\t"
<< chunk_data.get()[row*chunk_extent[1]+col];
for (size_t col = 0; col < chunk_extent[1]; ++col)
cout << "\t" << '(' << row + chunk_offset[0] << '|'
<< col + chunk_offset[1] << '|' << 1 << ")\t"
<< chunk_data.get()[row * chunk_extent[1] + col];
cout << '\n';
}

auto all_data = E_x.loadChunk<double>();
series.flush();
cout << "Full E/x starts with:\n\t{";
for( size_t col = 0; col < extent[1] && col < 5; ++col )
for (size_t col = 0; col < extent[1] && col < 5; ++col)
cout << all_data.get()[col] << ", ";
cout << "...}\n";

Expand Down
Loading

0 comments on commit c7dbf24

Please sign in to comment.