Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Language: Cpp

BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
# AlignEscapedNewlinesLeft: false
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLambdasOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false

BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterExternBlock: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
# BeforeLambdaBody: true
SplitEmptyFunction: false
SplitEmptyNamespace: false
SplitEmptyRecord: false

BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
ColumnLimit: 80
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
FixNamespaceComments: true
IndentWidth: 4
NamespaceIndentation: Inner
PointerAlignment: Right
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementMacros: ["OPENPMD_private", "OPENPMD_protected"]
12 changes: 12 additions & 0 deletions .github/workflows/clang-format/clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

if (( $# > 0 )); then
# received arguments, format those files
clang-format-12 -i "$@"
else
# received no arguments, find files on our own
find include/ src/ test/ examples/ \
-regextype egrep \
-type f -regex '.*\.(hpp|cpp|hpp\.in)$' \
| xargs clang-format-12 -i
fi
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ repos:

# C++ formatting
# clang-format
- repo: local
hooks:
- id: clang-format
name: clang-format
description: Clang-format our code base
files: '^(include|src|test|examples)/.*\.(hpp|cpp|hpp\.in)$'
language: conda
entry: bash .github/workflows/clang-format/clang-format.sh
additional_dependencies: [-c, conda-forge, clang-format-12]

# Autoremoves unused Python imports
- repo: https://github.com/hadialqattan/pycln
Expand Down
7 changes: 7 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# I am a conda environment, used for our pre-commit hooks
name: openPMD-api-dev
channels:
- conda-forge
dependencies:
- clang-format-12=12.0.1
- bash=5
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);
}
}
Loading