Esempio n. 1
0
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="createModel">Creates the model that should be checked.</param>
        /// <param name="output">The callback that should be used to output messages.</param>
        /// <param name="configuration">The analysis configuration that should be used.</param>
        internal ModelTraverser(AnalysisModelCreator createModel, AnalysisConfiguration configuration, int transitionSize, bool createStutteringState)
        {
            Requires.NotNull(createModel, nameof(createModel));
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            TransitionCollection.ValidateTransitionSizes();

            var tasks  = new Task[configuration.CpuCount];
            var stacks = new StateStack[configuration.CpuCount];

            _loadBalancer = new LoadBalancer(stacks);
            Context       = new TraversalContext(_loadBalancer, configuration);
            _workers      = new Worker[configuration.CpuCount];

            for (var i = 0; i < configuration.CpuCount; ++i)
            {
                var index = i;
                tasks[i] = Task.Factory.StartNew(() =>
                {
                    stacks[index]   = new StateStack(configuration.StackCapacity);
                    _workers[index] = new Worker(index, Context, stacks[index], createModel.Create());
                });
            }

            Task.WaitAll(tasks);

            var firstModel = _workers[0].Model;

            if (transitionSize == DeriveTransitionSizeFromModel)
            {
                transitionSize = firstModel.TransitionSize;
            }

            if (configuration.WriteStateVectorLayout)
            {
                firstModel.WriteStateVectorLayout(configuration.DefaultTraceOutput);
            }

            var modelCapacity = configuration.ModelCapacity.DeriveModelByteSize(firstModel.ModelStateVectorSize, transitionSize);

            Context.ModelCapacity = modelCapacity;
            if (configuration.UseCompactStateStorage)
            {
                _states = new CompactStateStorage(modelCapacity.SizeOfState, modelCapacity.NumberOfStates);
            }
            else
            {
                _states = new SparseStateStorage(modelCapacity.SizeOfState, modelCapacity.NumberOfStates);
            }
            Context.States = _states;
            if (createStutteringState)
            {
                Context.StutteringStateIndex = _states.ReserveStateIndex();
            }
            _initializationTime = stopwatch.Elapsed;
            stopwatch.Stop();
        }
Esempio n. 2
0
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="createModel">Creates the model that should be checked.</param>
        /// <param name="output">The callback that should be used to output messages.</param>
        /// <param name="configuration">The analysis configuration that should be used.</param>
        internal ModelTraverser(AnalysisModelCreator <TExecutableModel> createModel, Action <string> output, AnalysisConfiguration configuration, int transitionSize)
        {
            Requires.NotNull(createModel, nameof(createModel));
            Requires.NotNull(output, nameof(output));
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            TransitionCollection.ValidateTransitionSizes();

            var tasks  = new Task[configuration.CpuCount];
            var stacks = new StateStack[configuration.CpuCount];

            _loadBalancer = new LoadBalancer(stacks);
            Context       = new TraversalContext <TExecutableModel>(_loadBalancer, configuration, output);
            _workers      = new Worker <TExecutableModel> [configuration.CpuCount];

            for (var i = 0; i < configuration.CpuCount; ++i)
            {
                var index = i;
                tasks[i] = Task.Factory.StartNew(() =>
                {
                    stacks[index]   = new StateStack(configuration.StackCapacity);
                    _workers[index] = new Worker <TExecutableModel>(index, Context, stacks[index], createModel.Create());
                });
            }

            Task.WaitAll(tasks);

            var firstModel = _workers[0].Model;

            if (transitionSize == DeriveTransitionSizeFromModel)
            {
                transitionSize = firstModel.TransitionSize;
            }

            var modelCapacity = configuration.ModelCapacity.DeriveModelByteSize(firstModel.StateVectorSize, transitionSize);

            Context.ModelCapacity = modelCapacity;
            _states        = new StateStorage(modelCapacity.SizeOfState, modelCapacity.NumberOfStates);
            Context.States = _states;
            Context.StutteringStateIndex = _states.ReserveStateIndex();
            _initializationTime          = stopwatch.Elapsed;
            stopwatch.Stop();
        }