Skip to content

Conversation

@Flamefire
Copy link
Contributor

This improves the global uniqueness of the seeds by using local seeds that vary in the upper bits.

When XORing those with e.g. cellIdxs that are counted (from 0-N) the resulting seeds are still globally unique. Previously the counted rank and the counted cellIdx could cancel each other out resulting in "seed collisions" over different ranks.

Helps e.g. @n01r :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... (e.g. cell index, time step,...) ...

@psychocoderHPC psychocoderHPC added component: PMacc in PMacc refactoring code change to improve performance or to unify a concept but does not change public API labels Aug 14, 2015
@psychocoderHPC psychocoderHPC added this to the Open Beta milestone Aug 14, 2015
@psychocoderHPC
Copy link
Member

I assigned @ax3l because I am involved at the development process

@n01r
Copy link
Member

n01r commented Aug 14, 2015

I am later XORing with the currentStep so maybe creating a unique seed first and then reversing the bits is a bit better (pun unintended) before the currentStep comes into play.

Also: we should also take the number of slides from the moving window into account, right?
We want a unique seed not only for each GPU but rather for each local domain.
The time step could take care of this, though 😕

@psychocoderHPC
Copy link
Member

We should avoid manipulations of the seed inside the user code like PIConGPU.

GlobalSeed globalSeed;
mpi::SeedPerRank<simDim> seedPerRank;
uint32_t seed = seedPerRank(globalSeed(), PMacc::traits::GetUniqueTypeId<FrameType, uint32_t>::uid());
seed ^= POSITION_SEED ^ currentStep;
GlobalSeed globalSeed;
uint32_t localShift = currentStep ^
                      POSITION_SEED ^
                      PMacc::traits::GetUniqueTypeId<FrameType, uint32_t>::uid();
mpi::SeedPerRank<simDim> seedPerRank;
seed = seedPerRank(globalSeed() , localShift );

IMO the second one is the right usage of this pull request. SeedPerRank<DIM>()(seed,localShift) should be always the last operations. Manipulations of the first and second parameter of SeedPerRank before not destroy the quallity of the end seed.

[update] Please see my next post, which suggest to XOR all user variables to one seed and create a MPI unique seed out of it.

@psychocoderHPC
Copy link
Member

Suggestion: IMO the second parameter of SeedPerRank is useless to create unique seeds per rank can be skipped.
uint32_t operator()( uint32_t seed) is enough and than more equal to the operation srand()

@n01r
Copy link
Member

n01r commented Aug 14, 2015

I agree.
At first you define with the parameter localShift in what ways the seed should be unique.
Then you pass it to seedPerRank and afterwards you should not touch it anymore.

Maybe one can think of a better name for localShift then.

@ax3l
Copy link
Member

ax3l commented Aug 14, 2015 via email

@Flamefire
Copy link
Contributor Author

I adapted the function to only take 1 param. I also shuffle that param a bit, as it (in all current usages) contains a counted number too (the species-uid) Therefore you easily get collisions there.
Also see the usage in RandomPosition: currentStep has to be applied AFTER the globally unique seed is gotten. Same reason here: The design of the global unique seed assumes this usage and therefore a unique seed is only gotten by using it that way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not change this algorithm together with the rest of this pull request.

std::numeric_limits<> is not defined for 64bit types in C++98. Please keep the old method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, reverted.

@ax3l
Copy link
Member

ax3l commented Aug 27, 2015

we have to take care that also on a per-time-step basis the seed varies enough. for example, an ionization scheme running on the same cell (position & species information constant) should not create a predictable pattern on each cell over time (nor should that pattern move over the simulation).

@psychocoderHPC psychocoderHPC mentioned this pull request Aug 27, 2015
1 task
@Flamefire
Copy link
Contributor Author

I'm afraid this is gonna be impossible. If you only have 32 bits, how could you get that many information into the seed? The current design allows xoring the local seed (got from SeedPerRank) with a counted number without creating collisions (or at least it is unlikely)
Xoring it with 2 counted numbers (cellIdx and timestep) would create collisions (cellIdx=2 XOR timestep=1 == cellIdx=1 XOR timestep=2)
2 possible solutions: Use 64 bit seeds where upper half is unique per rank and lower half can be divided between cellIdx and timesteps or save the state of the PRNG per cellIdx over all timesteps.

@ax3l
Copy link
Member

ax3l commented Aug 27, 2015

it's not about having one unique seed for each cell and time step (which also would not solve that).
I will review the current code and see if it is in compliance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can now be used at each time step, pls add the currentStep xor, too.

@Flamefire
Copy link
Contributor Author

@ax3l Added the current step

@ax3l
Copy link
Member

ax3l commented Aug 27, 2015

all right, thank you for the great work! ✨

ax3l added a commit that referenced this pull request Aug 27, 2015
@ax3l ax3l merged commit 04793b1 into ComputationalRadiationPhysics:dev Aug 27, 2015
n01r pushed a commit to n01r/picongpu that referenced this pull request Aug 28, 2015
- `ionizationMethods.hpp`: - Removed workaround for good seed
                             after merge of ComputationalRadiationPhysics#1046
- `utilities.hpp`: - Added EOF newline
@Flamefire Flamefire deleted the unique_seed branch August 31, 2015 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: PMacc in PMacc refactoring code change to improve performance or to unify a concept but does not change public API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants