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

Close #351 Expose global Seed #353

Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ This is the 5th release candidate, a *pre-beta* version.
[#320](https://github.com/ComputationalRadiationPhysics/picongpu/pull/320/files#diff-1)
- removed double `#define __COHERENTINCOHERENTWEIGHTING__ 1` in some example radiationConfig.param
[#323](https://github.com/ComputationalRadiationPhysics/picongpu/pull/323/files)
- new file: `seed.param` allows to vary the starting conditions of "identical" runs
[#353](https://github.com/ComputationalRadiationPhysics/picongpu/pull/353)

**New Features:**
- Radiation plugin: add optional window functions to reduce ringing effects
Expand Down
63 changes: 63 additions & 0 deletions src/libPMacc/include/mpi/SeedPerRank.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright 2014 Axel Huebl
*
* This file is part of PIConGPU.
*
* PIConGPU is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PIConGPU is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PIConGPU.
* If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "types.h"
#include "Environment.hpp"

namespace PMacc
{
namespace mpi
{
/** Calculate a Seed per Rank
*
* This functor derives a unqiue seed for each MPI rank (or GPU) from
* a given global seed in a deterministic manner.
*
* \tparam T_DIM Dimensionality of the simulation (1-3 D)
*/
template <unsigned T_DIM>
struct SeedPerRank
{
/** Functor implementation
*
* This method provides a guaranteed unique number per MPI rank
* (or GPU). When a (only locally unique) localShift parameter is used
* it is furthermore guaranteed that this number does not collide
* with an other seed.
*
* \param seed initial seed to vary two identical simulations
* \param localShift e.g. a unique species id
* \return uint32_t seed
*/
uint32_t
operator()( uint32_t seed, uint32_t localShift = 0 )
{
PMACC_AUTO(&gc, PMacc::Environment<T_DIM>::get().GridController());

seed ^= gc.getGlobalSize( ) * localShift +
gc.getGlobalRank( );
return seed;
}
};

} /* namespace mpi */
} /* namespace picongpu */
12 changes: 7 additions & 5 deletions src/picongpu/include/particles/Particles.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "particles/memory/buffers/ParticlesBuffer.hpp"
#include "ParticlesInit.kernel"
#include "mappings/simulation/GridController.hpp"
#include "mpi/SeedPerRank.hpp"

#include "simulationControl/MovingWindow.hpp"

Expand Down Expand Up @@ -193,9 +194,9 @@ void Particles<T_ParticleDescription>::initFill( uint32_t currentStep )
DataSpace<simDim> gpuCellOffset = simBox.getGlobalOffset( );
gpuCellOffset.y( ) += window.slides * localCells.y( );


uint32_t seed = Environment<simDim>::get().GridController().getGlobalSize( ) * FrameType::CommunicationTag
+ Environment<simDim>::get().GridController().getGlobalRank( );
GlobalSeed globalSeed;
mpi::SeedPerRank<simDim> seedPerRank;
uint32_t seed = seedPerRank( globalSeed(), FrameType::CommunicationTag );
seed ^= POSITION_SEED;
dim3 block( MappingDesc::SuperCellSize::getDataSpace( ) );

Expand Down Expand Up @@ -249,8 +250,9 @@ void Particles<T_ParticleDescription>::deviceAddTemperature( float_X energy )
dim3 block( MappingDesc::SuperCellSize::getDataSpace( ) );
DataSpace<simDim> superCells = this->particlesBuffer->getSuperCellsCount( );

uint32_t seed = Environment<simDim>::get().GridController().getGlobalSize( ) * FrameType::CommunicationTag
+ Environment<simDim>::get().GridController().getGlobalRank( );
GlobalSeed globalSeed;
mpi::SeedPerRank<simDim> seedPerRank;
uint32_t seed = seedPerRank( globalSeed(), FrameType::CommunicationTag );
seed ^= TEMPERATURE_SEED;

__picKernelArea( kernelAddTemperature, this->cellDescription, CORE + BORDER + GUARD )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
#include "simulation_defines/param/radiationConfig.param"
#include "simulation_defines/param/fieldBackground.param"
#include "simulation_defines/param/radiationObserver.param"

#include "simulation_defines/param/seed.param"
43 changes: 43 additions & 0 deletions src/picongpu/include/simulation_defines/param/seed.param
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2014 Axel Huebl
*
* This file is part of PIConGPU.
*
* PIConGPU is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PIConGPU is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PIConGPU.
* If not, see <http://www.gnu.org/licenses/>.
*/


#pragma once

namespace picongpu
{
/** global seed
*
* global seed to derive GPU local seeds from
* - vary it to shuffle pseudo random generators for exactly same simulation
* - note: even when kept constant, highly parallel simulations do not ensure
* 100% deterministic simulations on the floating point level
*/
struct GlobalSeed
{
uint32_t
operator()()
{
/** to vary (binary) identical simulations, use a combination of
* time(NULL) from \see <time.h> (precision: seconds) */
return 42;
}
};
} /* namespace picongpu */