public override void Execute() { if ((!Owner.RandomPeriod && (SimulationStep % Owner.Period == 0)) || (Owner.RandomPeriod && (SimulationStep == Owner.NextPeriodChange))) { if (!Owner.Output.OnHost) { Owner.Output.SafeCopyToHost(); } if (Unique) { MyCombinationBase.GenerateCombinationUnique(new ArraySegment <float>(Owner.Output.Host), combHS, Min, Max, Owner.m_rnd); } else { MyCombinationBase.GenerateCombination(new ArraySegment <float>(Owner.Output.Host), Min, Max, Owner.m_rnd); } Owner.Output.SafeCopyToDevice(); Owner.SetSingle(); } Owner.UpdatePeriod(this); }
public override void Execute() { if ((!RandomPeriod && (SimulationStep % Period == 0)) || (RandomPeriod && (SimulationStep == m_nextPeriodChange))) { switch (Distribution) { case RandomDistribution.Constant: m_kernel.SetupExecution(Owner.Output.Count); m_kernel.Run(Owner.Output, Constant, Owner.Output.Count); break; case RandomDistribution.Uniform: MyKernelFactory.Instance.GetRandDevice(Owner).GenerateUniform(Owner.Output.GetDevice(Owner)); break; case RandomDistribution.Normal: //Normal RNG uses Box-Muller transformation, so it can generate only even number of values if (Owner.Output.Count % 2 == 0) { MyKernelFactory.Instance.GetRandDevice(Owner).GenerateNormal(Owner.Output.GetDevice(Owner), Mean, StdDev); } else { MyKernelFactory.Instance.GetRandDevice(Owner).GenerateNormal(Owner.RandomNumbers.GetDevice(Owner), Mean, StdDev); Owner.RandomNumbers.CopyToMemoryBlock(Owner.Output, 0, 0, Owner.Output.Count); } break; case RandomDistribution.Combination: if (!Owner.Output.OnHost) { Owner.Output.SafeCopyToHost(); } if (Unique) { MyCombinationBase.GenerateCombinationUnique(new ArraySegment <float>(Owner.Output.Host), combHS, Min, Max, m_rnd); } else { MyCombinationBase.GenerateCombination(new ArraySegment <float>(Owner.Output.Host), Min, Max, m_rnd); } Owner.Output.SafeCopyToDevice(); break; } if (Distribution == RandomDistribution.Uniform) { //scale from 0-1 to min-max m_polynomialKernel.SetupExecution(Owner.Output.Count); m_polynomialKernel.Run(0, 0, (MaxValue - MinValue), MinValue, Owner.Output, Owner.Output, Owner.Output.Count ); } if (Owner.SingleOutput == true) { //delete all values except one int keep = m_rnd.Next(Owner.Output.Count); m_setKernel.SetupExecution(Owner.Output.Count); m_setKernel.Run(Owner.Output, 0, keep, Owner.Output.Count); } } if (RandomPeriod && (SimulationStep == m_nextPeriodChange)) { //+1 for inclusive interval Period = m_rnd.Next(RandomPeriodMin, RandomPeriodMax + 1); m_nextPeriodChange += Period; } }