public override void UpdateMemoryBlocks() { if (RandomSeed > 0) { m_rnd = new Random(RandomSeed); MyKernelFactory.Instance.GetRandDevice(this).SetPseudoRandomGeneratorSeed((ulong)RandomSeed); // set random seed defining the sequence MyKernelFactory.Instance.GetRandDevice(this).SetOffset(0); // and offset in this random sequence } else { m_rnd = new Random(DateTime.Now.Millisecond); } RandomNumbers.Count = Output.Count + 1; if (UniformRNG.Enabled) { UniformRNG.UpdateValueHints(); } else if (NormalRNG.Enabled) { NormalRNG.UpdateValueHints(); } else if (ConstantRNG.Enabled) { ConstantRNG.UpdateValueHints(); } else if (CombinationRNG.Enabled) { CombinationRNG.UpdateValueHints(); } }
private static void GeneratePaths(float[] paths, float r, float sigma, float dt, int numSims, int numTimesteps) { // int tid = (BlockIndex.X * BlockDimension.X) + ThreadIndex.X; int step = GridDimension.X * BlockDimension.X; // Compute parameters float drift = (r - (0.5f * sigma * sigma)) * dt; float diffusion = sigma * DeviceMath.Sqrt(dt); // Simulate the paths for (int i = tid; i < numSims; i += step) { // Current output index int output = i; // Simulate the path float s = 1.0f; for (int t = 0; t < numTimesteps; t++, output += numSims) { s *= DeviceMath.Exp(drift + (diffusion * NormalRNG.NextFloat())); paths[output] = s; } } }
public override void UpdateMemoryBlocks() { RandomNumbers.Count = Output.Count + 1; if (UniformRNG.Enabled) { UniformRNG.UpdateValueHints(); } else if (NormalRNG.Enabled) { NormalRNG.UpdateValueHints(); } else if (ConstantRNG.Enabled) { ConstantRNG.UpdateValueHints(); } else if (CombinationRNG.Enabled) { CombinationRNG.UpdateValueHints(); } }