Пример #1
0
        /// <summary>
        /// Executes the specified machines sequentially
        /// </summary>
        /// <param name="spec">The machine definition</param>
        /// <param name="seeds">The rng seeds that determine initial states of the randomizers</param>
        /// <param name="indices">The rng stream position indices</param>
        /// <typeparam name="T">The primal FSM type</typeparam>
        static IEnumerable <FsmStats> RunSequential <T>(PrimalFsmSpec <T> spec, Span <ulong> seeds, Span <ulong> indices)
            where T : unmanaged
        {
            var stats = new ConcurrentBag <FsmStats>();

            for (var i = 0; i < seeds.Length; i++)
            {
                var machine = Create(spec, seeds[i], indices[i]);
                var result  = Fsm.Run(machine).Result;
                result.OnSome(s => stats.Add(s));
            }
            return(stats);
        }
Пример #2
0
        /// <summary>
        /// Executes the specified machines concurrently
        /// </summary>
        /// <param name="spec">The machine definition</param>
        /// <param name="seeds">The rng seeds that determine initial states of the randomizers</param>
        /// <param name="indices">The rng stream position indices</param>
        /// <typeparam name="T">The primal FSM type</typeparam>
        static IEnumerable <FsmStats> RunConcurrent <T>(PrimalFsmSpec <T> spec, Span <ulong> seeds, Span <ulong> indices)
            where T : unmanaged
        {
            var stats = new ConcurrentBag <FsmStats>();
            var tasks = new Task[seeds.Length];

            for (var i = 0; i < tasks.Length; i++)
            {
                var machine = Create(spec, seeds[i], indices[i]);
                tasks[i] = Fsm.Run(machine).ContinueWith(t => t.Result.OnSome(s => stats.Add(s)));
            }

            Task.WaitAll(tasks);
            return(stats);
        }