Ejemplo n.º 1
0
        /// <summary>
        /// Gets the total number of threads within the system that can compute the specified problem type.
        /// </summary>
        /// <param name="problemType">Type name of the problem class.</param>
        /// <returns>Number of threads.</returns>
        private int CountAvailableSolvingThreads(string problemType)
        {
            var availableThreads = 0;

            foreach (var componentInfo in _componentOverseer.GetComponents(ComponentType.ComputationalNode))
            {
                var sn = (SolverNodeInfo)componentInfo;
                if (!sn.SolvableProblems.Contains(problemType))
                {
                    continue;
                }

                //availableThreads += sn.NumberOfThreads; // Count all threads.
                availableThreads += sn.ThreadInfo.Count(ts => ts.State == ThreadStatus.ThreadState.Idle);
                // OR count only the idle ones.
            }

            // No available threads found be we still need to divide the problem into some parts.
            if (availableThreads == 0)
            {
                availableThreads = 3;
            }

            return(availableThreads);
        }