Commit 601a696f authored by Jason Swails's avatar Jason Swails
Browse files

Convert a random seed set to 0 into one based on the wall clock in more places.

This commit hits the CPU platform (I had previously thought it just used the
Reference generator) as well as the CustomIntegrator stream that is set
separately from the standard "integrator" stream attached to each platform for
CUDA and OpenCL platforms (it seemed to me that the Reference platform's
CustomIntegrator just used the integrator random stream).
parent 10cb26a6
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "CpuRandom.h" #include "CpuRandom.h"
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
#include "openmm/OSRngSeed.h"
#include <cmath> #include <cmath>
using namespace std; using namespace std;
...@@ -49,9 +50,13 @@ void CpuRandom::initialize(int seed, int numThreads) { ...@@ -49,9 +50,13 @@ void CpuRandom::initialize(int seed, int numThreads) {
nextGaussian.resize(numThreads); nextGaussian.resize(numThreads);
nextGaussianIsValid.resize(numThreads, false); nextGaussianIsValid.resize(numThreads, false);
// Use a quick and dirty RNG to pick seeds for the real random number generator. /* Use a quick and dirty RNG to pick seeds for the real random number generator.
* A random seed of 0 means pick a new random seed based on wall clock
*/
unsigned int r = (unsigned int) seed; unsigned int r = (unsigned int) seed;
if (r == 0)
r = (unsigned int) osrngseed();
for (int i = 0; i < numThreads; i++) { for (int i = 0; i < numThreads; i++) {
r = (1664525*r + 1013904223) & 0xFFFFFFFF; r = (1664525*r + 1013904223) & 0xFFFFFFFF;
threadRandom[i] = new OpenMM_SFMT::SFMT(); threadRandom[i] = new OpenMM_SFMT::SFMT();
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "openmm/internal/CustomManyParticleForceImpl.h" #include "openmm/internal/CustomManyParticleForceImpl.h"
#include "openmm/internal/CustomNonbondedForceImpl.h" #include "openmm/internal/CustomNonbondedForceImpl.h"
#include "openmm/internal/NonbondedForceImpl.h" #include "openmm/internal/NonbondedForceImpl.h"
#include "openmm/internal/OSRngSeed.h"
#include "CudaBondedUtilities.h" #include "CudaBondedUtilities.h"
#include "CudaExpressionUtilities.h" #include "CudaExpressionUtilities.h"
#include "CudaIntegrationUtilities.h" #include "CudaIntegrationUtilities.h"
...@@ -5967,7 +5968,11 @@ void CudaIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context, ...@@ -5967,7 +5968,11 @@ void CudaIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context,
uniformRandoms = CudaArray::create<float4>(cu, maxUniformRandoms, "uniformRandoms"); uniformRandoms = CudaArray::create<float4>(cu, maxUniformRandoms, "uniformRandoms");
randomSeed = CudaArray::create<int4>(cu, cu.getNumThreadBlocks()*CudaContext::ThreadBlockSize, "randomSeed"); randomSeed = CudaArray::create<int4>(cu, cu.getNumThreadBlocks()*CudaContext::ThreadBlockSize, "randomSeed");
vector<int4> seed(randomSeed->getSize()); vector<int4> seed(randomSeed->getSize());
unsigned int r = integrator.getRandomNumberSeed()+1; int rseed = integrator.getRandomNumberSeed();
// A random seed of 0 means generate a new one from the wall clock
if (rseed == 0)
rseed = osrngseed();
unsigned int r = (unsigned int) (rseed+1);
for (int i = 0; i < randomSeed->getSize(); i++) { for (int i = 0; i < randomSeed->getSize(); i++) {
seed[i].x = r = (1664525*r + 1013904223) & 0xFFFFFFFF; seed[i].x = r = (1664525*r + 1013904223) & 0xFFFFFFFF;
seed[i].y = r = (1664525*r + 1013904223) & 0xFFFFFFFF; seed[i].y = r = (1664525*r + 1013904223) & 0xFFFFFFFF;
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "openmm/internal/CustomManyParticleForceImpl.h" #include "openmm/internal/CustomManyParticleForceImpl.h"
#include "openmm/internal/CustomNonbondedForceImpl.h" #include "openmm/internal/CustomNonbondedForceImpl.h"
#include "openmm/internal/NonbondedForceImpl.h" #include "openmm/internal/NonbondedForceImpl.h"
#include "openmm/internal/OSRngSeed.h"
#include "OpenCLBondedUtilities.h" #include "OpenCLBondedUtilities.h"
#include "OpenCLExpressionUtilities.h" #include "OpenCLExpressionUtilities.h"
#include "OpenCLIntegrationUtilities.h" #include "OpenCLIntegrationUtilities.h"
...@@ -6200,7 +6201,11 @@ void OpenCLIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context ...@@ -6200,7 +6201,11 @@ void OpenCLIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context
uniformRandoms = OpenCLArray::create<mm_float4>(cl, maxUniformRandoms, "uniformRandoms"); uniformRandoms = OpenCLArray::create<mm_float4>(cl, maxUniformRandoms, "uniformRandoms");
randomSeed = OpenCLArray::create<mm_int4>(cl, cl.getNumThreadBlocks()*OpenCLContext::ThreadBlockSize, "randomSeed"); randomSeed = OpenCLArray::create<mm_int4>(cl, cl.getNumThreadBlocks()*OpenCLContext::ThreadBlockSize, "randomSeed");
vector<mm_int4> seed(randomSeed->getSize()); vector<mm_int4> seed(randomSeed->getSize());
unsigned int r = integrator.getRandomNumberSeed()+1; int rseed = integrator.getRandomNumberSeed();
// A random seed of 0 means generate a new one from the wall clock
if (rseed == 0)
rseed = osrngseed();
unsigned int r = (unsigned int) (rseed+1);
for (int i = 0; i < randomSeed->getSize(); i++) { for (int i = 0; i < randomSeed->getSize(); i++) {
seed[i].x = r = (1664525*r + 1013904223) & 0xFFFFFFFF; seed[i].x = r = (1664525*r + 1013904223) & 0xFFFFFFFF;
seed[i].y = r = (1664525*r + 1013904223) & 0xFFFFFFFF; seed[i].y = r = (1664525*r + 1013904223) & 0xFFFFFFFF;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment