Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for particle filters #2397

Merged
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
5 changes: 4 additions & 1 deletion include/picongpu/plugins/CountParticles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <pmacc/mappings/kernel/AreaMapping.hpp>

#include "picongpu/plugins/ISimulationPlugin.hpp"
#include "picongpu/particles/filter/filter.hpp"

#include <pmacc/mpi/reduceMethods/Reduce.hpp>
#include <pmacc/mpi/MPIReduce.hpp>
Expand Down Expand Up @@ -175,11 +176,13 @@ class CountParticles : public ISimulationPlugin
DataConnector &dc = Environment<>::get().DataConnector();
auto particles = dc.get< ParticlesType >( ParticlesType::FrameType::getName(), true );

particles::filter::All parFilter{};
/*count local particles*/
size = pmacc::CountParticles::countOnDevice<AREA>(*particles,
*cellDescription,
DataSpace<simDim>(),
localSize);
localSize,
parFilter);
dc.releaseData( ParticlesType::FrameType::getName() );

uint64_cu reducedValueMax;
Expand Down
4 changes: 3 additions & 1 deletion include/picongpu/plugins/ResourceLog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "picongpu/plugins/ILightweightPlugin.hpp"
#include "ILightweightPlugin.hpp"
#include "picongpu/simulation_defines.hpp"
#include "picongpu/particles/filter/filter.hpp"

// Boost
#include <boost/property_tree/ptree.hpp>
Expand Down Expand Up @@ -115,7 +116,8 @@ namespace picongpu

if(contains(propertyMap,"particleCount"))
{
std::vector<size_t> particleCounts = resourceMonitor.getParticleCounts<VectorAllSpecies>(*cellDescription);
particles::filter::All parFilter{};
std::vector<size_t> particleCounts = resourceMonitor.getParticleCounts<VectorAllSpecies>(*cellDescription, parFilter );
pt.put("resourceLog.particleCount", std::accumulate(particleCounts.begin(), particleCounts.end(), 0));
}

Expand Down
13 changes: 7 additions & 6 deletions include/picongpu/plugins/adios/ADIOSCountParticles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ using namespace pmacc;
* @tparam T_Species type of species
*
*/
template< typename T_Species >
template< typename T_SpeciesFilter >
struct ADIOSCountParticles
{
public:

typedef T_Species ThisSpecies;
typedef typename T_SpeciesFilter::Species ThisSpecies;
typedef typename ThisSpecies::FrameType FrameType;
typedef typename FrameType::ParticleDescription ParticleDescription;
typedef typename FrameType::ValueTypeSeq ParticleAttributeList;
Expand Down Expand Up @@ -96,20 +96,21 @@ struct ADIOSCountParticles
uint64_t mpiSize = gc.getGlobalSize();
uint64_t mpiRank = gc.getGlobalRank();

const std::string speciesGroup( FrameType::getName() + "/" );
const std::string speciesGroup( T_SpeciesFilter::getName() + "/" );
const std::string speciesPath( params->adiosBasePath +
std::string(ADIOS_PATH_PARTICLES) + speciesGroup );

/* load particle without copy particle data to host */
auto speciesTmp = dc.get< ThisSpecies >( ThisSpecies::FrameType::getName(), true );

typename T_SpeciesFilter::Filter particleFilter{};
/* count total number of particles on the device */
uint64_cu totalNumParticles = 0;
totalNumParticles = pmacc::CountParticles::countOnDevice < CORE + BORDER > (
*speciesTmp,
*(params->cellDescription),
params->localWindowToDomainOffset,
params->window.localDimensions.size);
params->window.localDimensions.size,
particleFilter);

/* MPI_Allgather to compute global size and my offset */
uint64_t myNumParticles = totalNumParticles;
Expand Down Expand Up @@ -137,7 +138,7 @@ struct ADIOSCountParticles

/* openPMD ED-PIC: additional attributes */
traits::PICToAdios<float_64> adiosDoubleType;
const float_64 particleShape( GetShape<T_Species>::type::support - 1 );
const float_64 particleShape( GetShape<ThisSpecies>::type::support - 1 );
ADIOS_CMD(adios_define_attribute_byvalue(params->adiosGroupHandle,
"particleShape", speciesPath.c_str(),
adiosDoubleType.type, 1, (void*)&particleShape ));
Expand Down
37 changes: 33 additions & 4 deletions include/picongpu/plugins/adios/ADIOSWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "picongpu/plugins/adios/restart/LoadSpecies.hpp"
#include "picongpu/plugins/adios/restart/RestartFieldLoader.hpp"
#include "picongpu/plugins/adios/NDScalars.hpp"
#include "picongpu/plugins/misc/SpeciesFilter.hpp"

#include <adios.h>
#include <adios_read.h>
Expand Down Expand Up @@ -1042,12 +1043,26 @@ class ADIOSWriter : public IIOBackend
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) counting particles.");
if (threadParams->isCheckpoint)
{
ForEach<FileCheckpointParticles, ADIOSCountParticles<bmpl::_1> > adiosCountParticles;
ForEach<
FileCheckpointParticles,
ADIOSCountParticles<
plugins::misc::SpeciesFilter<
bmpl::_1
>
>
> adiosCountParticles;
adiosCountParticles(threadParams);
}
else
{
ForEach<FileOutputParticles, ADIOSCountParticles<bmpl::_1> > adiosCountParticles;
ForEach<
FileOutputParticles,
ADIOSCountParticles<
plugins::misc::SpeciesFilter<
bmpl::_1
>
>
> adiosCountParticles;
adiosCountParticles(threadParams);
}
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) counting particles.");
Expand Down Expand Up @@ -1104,12 +1119,26 @@ class ADIOSWriter : public IIOBackend
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) writing particle species.");
if (threadParams->isCheckpoint)
{
ForEach<FileCheckpointParticles, WriteSpecies<bmpl::_1> > writeSpecies;
ForEach<
FileCheckpointParticles,
WriteSpecies<
plugins::misc::SpeciesFilter<
bmpl::_1
>
>
> writeSpecies;
writeSpecies(threadParams, particleOffset);
}
else
{
ForEach<FileOutputParticles, WriteSpecies<bmpl::_1> > writeSpecies;
ForEach<
FileOutputParticles,
WriteSpecies<
plugins::misc::SpeciesFilter<
bmpl::_1
>
>
> writeSpecies;
writeSpecies(threadParams, particleOffset);
}
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) writing particle species.");
Expand Down
29 changes: 16 additions & 13 deletions include/picongpu/plugins/adios/WriteSpecies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ using namespace pmacc;
* @tparam T_Species type of species
*
*/
template< typename T_Species >
template< typename T_SpeciesFilter >
struct WriteSpecies
{
public:

typedef T_Species ThisSpecies;
typedef typename T_SpeciesFilter::Species ThisSpecies;
typedef typename ThisSpecies::FrameType FrameType;
typedef typename FrameType::ParticleDescription ParticleDescription;
typedef typename FrameType::ValueTypeSeq ParticleAttributeList;
Expand All @@ -93,32 +93,34 @@ struct WriteSpecies
HINLINE void operator()(ThreadParams* params,
const Space particleOffset)
{
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) write species: %1%") % AdiosFrameType::getName();
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) write species: %1%") % T_SpeciesFilter::getName();
DataConnector &dc = Environment<>::get().DataConnector();
/* load particle without copy particle data to host */
auto speciesTmp = dc.get< ThisSpecies >( ThisSpecies::FrameType::getName(), true );

/* count total number of particles on the device */
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) count particles: %1%") % AdiosFrameType::getName();
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) count particles: %1%") % T_SpeciesFilter::getName();
typename T_SpeciesFilter::Filter particleFilter{};
uint64_cu totalNumParticles = 0;
totalNumParticles = pmacc::CountParticles::countOnDevice < CORE + BORDER > (
*speciesTmp,
*(params->cellDescription),
params->localWindowToDomainOffset,
params->window.localDimensions.size);
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) count particles: %1% = %2%") % AdiosFrameType::getName() % totalNumParticles;
params->window.localDimensions.size,
particleFilter);
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) count particles: %1% = %2%") % T_SpeciesFilter::getName() % totalNumParticles;

AdiosFrameType hostFrame;

/* malloc host memory */
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) malloc host memory: %1%") % AdiosFrameType::getName();
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) malloc host memory: %1%") % T_SpeciesFilter::getName();
ForEach<typename AdiosFrameType::ValueTypeSeq, MallocHostMemory<bmpl::_1> > mallocMem;
mallocMem(forward(hostFrame), totalNumParticles);
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) malloc host memory: %1%") % AdiosFrameType::getName();
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) malloc host memory: %1%") % T_SpeciesFilter::getName();

if (totalNumParticles > 0)
{
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) copy particle host (with hierarchy) to host (without hierarchy): %1%") % AdiosFrameType::getName();
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) copy particle host (with hierarchy) to host (without hierarchy): %1%") % T_SpeciesFilter::getName();
typedef bmpl::vector< typename GetPositionFilter<simDim>::type > usedFilters;
typedef typename FilterFactory<usedFilters>::FilterType MyParticleFilter;
MyParticleFilter filter;
Expand Down Expand Up @@ -160,7 +162,8 @@ struct WriteSpecies
filter,
particleOffset, /*relative to data domain (not to physical domain)*/
totalCellIdx_,
mapper
mapper,
particleFilter
);
#if( PMACC_CUDA_ENABLED == 1 )
dc.releaseData( MallocMCBuffer< DeviceHeap >::getName() );
Expand All @@ -175,10 +178,10 @@ struct WriteSpecies
/* free host memory */
ForEach<typename AdiosFrameType::ValueTypeSeq, FreeHostMemory<bmpl::_1> > freeMem;
freeMem(forward(hostFrame));
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) writing species: %1%") % AdiosFrameType::getName();
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) writing species: %1%") % T_SpeciesFilter::getName();

/* write species counter table to adios file */
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) writing particle index table for %1%") % AdiosFrameType::getName();
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) writing particle index table for %1%") % T_SpeciesFilter::getName();
{
GridController<simDim>& gc = Environment<simDim>::get().GridController();

Expand All @@ -200,7 +203,7 @@ struct WriteSpecies
params->adiosSpeciesIndexVarIds.pop_front();
ADIOS_CMD(adios_write_byid(params->adiosFileHandle, adiosIndexVarId, particlesMetaInfo));
}
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) writing particle index table for %1%") % AdiosFrameType::getName();
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) writing particle index table for %1%") % T_SpeciesFilter::getName();
}
};

Expand Down
14 changes: 7 additions & 7 deletions include/picongpu/plugins/adios/restart/LoadSpecies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ struct LoadSpecies
*/
HINLINE void operator()(ThreadParams* params, const uint32_t restartChunkSize)
{

log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) load species: %1%") % AdiosFrameType::getName();
std::string const speciesName = FrameType::getName() + "_all";
log<picLog::INPUT_OUTPUT > ("ADIOS: (begin) load species: %1%") % speciesName;
DataConnector &dc = Environment<>::get().DataConnector();
GridController<simDim> &gc = Environment<simDim>::get().GridController();

std::string particlePath = params->adiosBasePath + std::string(ADIOS_PATH_PARTICLES) +
FrameType::getName() + std::string("/");
speciesName + std::string("/");
const pmacc::Selection<simDim>& localDomain = Environment<simDim>::get().SubGrid().getLocalDomain();

/* load particle without copying particle data to host */
auto speciesTmp = dc.get< ThisSpecies >( ThisSpecies::FrameType::getName(), true );
auto speciesTmp = dc.get< ThisSpecies >( FrameType::getName(), true );

/* count total number of particles on the device */
uint64_t totalNumParticles = 0;
Expand Down Expand Up @@ -152,12 +152,12 @@ struct LoadSpecies
(long long unsigned) totalNumParticles % (long long unsigned) particleOffset;

AdiosFrameType hostFrame;
log<picLog::INPUT_OUTPUT > ("ADIOS: malloc mapped memory: %1%") % AdiosFrameType::getName();
log<picLog::INPUT_OUTPUT > ("ADIOS: malloc mapped memory: %1%") % speciesName;
/*malloc mapped memory*/
ForEach<typename AdiosFrameType::ValueTypeSeq, MallocMemory<bmpl::_1> > mallocMem;
mallocMem(forward(hostFrame), totalNumParticles);

log<picLog::INPUT_OUTPUT > ("ADIOS: get mapped memory device pointer: %1%") % AdiosFrameType::getName();
log<picLog::INPUT_OUTPUT > ("ADIOS: get mapped memory device pointer: %1%") % speciesName;
/*load device pointer of mapped memory*/
AdiosFrameType deviceFrame;
ForEach<typename AdiosFrameType::ValueTypeSeq, GetDevicePtr<bmpl::_1> > getDevicePtr;
Expand All @@ -183,7 +183,7 @@ struct LoadSpecies
ForEach<typename AdiosFrameType::ValueTypeSeq, FreeMemory<bmpl::_1> > freeMem;
freeMem(forward(hostFrame));
}
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) load species: %1%") % AdiosFrameType::getName();
log<picLog::INPUT_OUTPUT > ("ADIOS: ( end ) load species: %1%") % speciesName;
}
};

Expand Down
21 changes: 19 additions & 2 deletions include/picongpu/plugins/hdf5/HDF5Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@
#include "picongpu/plugins/hdf5/restart/LoadSpecies.hpp"
#include "picongpu/plugins/hdf5/restart/RestartFieldLoader.hpp"
#include "picongpu/plugins/hdf5/NDScalars.hpp"
#include "picongpu/plugins/misc/SpeciesFilter.hpp"

#include <pmacc/memory/boxes/DataBoxDim1Access.hpp>


namespace picongpu
{

Expand Down Expand Up @@ -407,12 +410,26 @@ class HDF5Writer : public IIOBackend
log<picLog::INPUT_OUTPUT > ("HDF5: (begin) writing particle species.");
if (threadParams->isCheckpoint)
{
ForEach<FileCheckpointParticles, WriteSpecies<bmpl::_1> > writeSpecies;
ForEach<
FileCheckpointParticles,
WriteSpecies<
plugins::misc::SpeciesFilter<
bmpl::_1
>
>
> writeSpecies;
writeSpecies(threadParams, domainOffset);
}
else
{
ForEach<FileOutputParticles, WriteSpecies<bmpl::_1> > writeSpecies;
ForEach<
FileOutputParticles,
WriteSpecies<
plugins::misc::SpeciesFilter<
bmpl::_1
>
>
> writeSpecies;
writeSpecies(threadParams, domainOffset);
}
log<picLog::INPUT_OUTPUT > ("HDF5: ( end ) writing particle species.");
Expand Down
Loading