Skip to content

Commit

Permalink
Format the whole codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
clang-format authored and franzpoeschel committed Feb 15, 2022
1 parent 7a8a392 commit 0404103
Show file tree
Hide file tree
Showing 178 changed files with 22,784 additions and 22,000 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: MultiLine
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false

Expand Down
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);
}
}
44 changes: 21 additions & 23 deletions examples/13_write_dynamic_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
using std::cout;
using namespace openPMD;


int main()
{
if( !getVariants()["adios2"] )
if (!getVariants()["adios2"])
{
// Example configuration below selects the ADIOS2 backend
return 0;
Expand Down Expand Up @@ -67,28 +66,27 @@ chunks = "auto"

// open file for writing
Series series =
Series( "../samples/dynamicConfig.bp", Access::CREATE, defaults );
Series("../samples/dynamicConfig.bp", Access::CREATE, defaults);

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);
}

/*
Expand Down Expand Up @@ -118,14 +116,14 @@ chunks = "auto"
}
}
})END";
Dataset differentlyCompressedDataset{ Datatype::INT, { 10 } };
Dataset differentlyCompressedDataset{Datatype::INT, {10}};
differentlyCompressedDataset.options = differentCompressionSettings;

auto someMesh = iteration.meshes[ "differentCompressionSettings" ]
[ RecordComponent::SCALAR ];
someMesh.resetDataset( differentlyCompressedDataset );
std::vector< int > dataVec( 10, i );
someMesh.storeChunk( dataVec, { 0 }, { 10 } );
auto someMesh = iteration.meshes["differentCompressionSettings"]
[RecordComponent::SCALAR];
someMesh.resetDataset(differentlyCompressedDataset);
std::vector<int> dataVec(10, i);
someMesh.storeChunk(dataVec, {0}, {10});

iteration.close();
}
Expand Down
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
Loading

0 comments on commit 0404103

Please sign in to comment.