Skip to content

Commit

Permalink
Sets random seeds by default in singlePopMcmc and multiPopMcmc
Browse files Browse the repository at this point in the history
Maintains the ability to specify a seed from the command line
  • Loading branch information
argiopetech committed Sep 3, 2014
1 parent 55db4c1 commit b0c4c53
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 2 deletions.
1 change: 0 additions & 1 deletion base9/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ void Settings::fromYaml (const string yamlFile)
scatterCluster.exposures = tNode.as<map<string, double>>();
}

seed = getOrDie<uint32_t>(generalNode, "seed");
verbose = getOrDie<int>(generalNode, "verbose");

// When we switch to C++11, we can change these to std::string and remove most of the cruft
Expand Down
2 changes: 1 addition & 1 deletion base9/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Settings

bool noBinaries;

uint32_t seed;
uint32_t seed = std::numeric_limits<uint32_t>::max();
unsigned int threads = std::numeric_limits<int>::max();

int verbose;
Expand Down
1 change: 1 addition & 0 deletions multiPopMcmc/MpiMcmcApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ int MpiMcmcApplication::run()
}
// end initChain

cout << "Seed: " << settings.seed << endl;
cout << "FSlike: " << fsLike << endl;

// Assuming fsLike doesn't change, this is the "global" logPost function
Expand Down
6 changes: 6 additions & 0 deletions multiPopMcmc/mpiMcmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ int main (int argc, char *argv[])

settings.fromCLI (argc, argv);

if (settings.seed == std::numeric_limits<uint32_t>::max())
{
srand(std::time(0));
settings.seed = rand();
}

MpiMcmcApplication master(settings);

try
Expand Down
1 change: 1 addition & 0 deletions singlePopMcmc/MpiMcmcApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ int MpiMcmcApplication::run()
}
// end initChain

cout << "Seed: " << settings.seed << endl;
cout << "FSlike: " << fsLike << endl;

// Assuming fsLike doesn't change, this is the "global" logPost function
Expand Down
8 changes: 8 additions & 0 deletions singlePopMcmc/mpiMcmc.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <cstdlib>
#include <ctime>
#include <stdexcept>

#include "MpiMcmcApplication.hpp"
Expand All @@ -23,6 +25,12 @@ int main (int argc, char *argv[])

settings.fromCLI (argc, argv);

if (settings.seed == std::numeric_limits<uint32_t>::max())
{
srand(std::time(0));
settings.seed = rand();
}

MpiMcmcApplication master(settings);

try
Expand Down

0 comments on commit b0c4c53

Please sign in to comment.