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

eliminate unnecessary srand calls #68

Open
alecjohnson opened this issue Apr 23, 2014 · 0 comments
Open

eliminate unnecessary srand calls #68

alecjohnson opened this issue Apr 23, 2014 · 0 comments

Comments

@alecjohnson
Copy link
Contributor

Currently Particles3D::particle_repopulator contains code like this:

  srand (vct->getCartesian_rank()+1+ns+(int(MPI_Wtime()))%10000);
  if (vct->getXleft_neighbor() == MPI_PROC_NULL && bcPfaceXleft == 2)
  {
    [...]
  } 

I do not see any need to seed the random number generator more than once in the program, and I would rather eliminate these calls. Seeding the random number generator destroys the ability to get exactly reproducible results (except in the case that no data generated by calls to rand() is actually being used), and there should be a single point in the program which selects whether the seed is deterministic or comes from a time value that will be different with each invocation of the program.

Even if the srand calls are retained, I would change the code to:

  if (vct->getXleft_neighbor() == MPI_PROC_NULL && bcPfaceXleft == 2)
  {
    srand (vct->getCartesian_rank()+1+ns+(int(MPI_Wtime()))%10000);
    [...]
  } 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant