Пример #1
0
        public int Compute(Problem[] problemsToSolve, int problemsReadingIndex, ComputationResult[] computationResults, int resultsWritingIndex, int problemCount, int degreeOfParallelism)
        {
            int cpuProblems = (int)Math.Round(problemsToSolve.Length * cpuPart);
            var CernyConjectureFailingIndex = -1;
            var thread = new Thread(() =>
            {
                var result = new SlimCPU4bits13().Compute(problemsToSolve, 0, computationResults, 0, cpuProblems, Environment.ProcessorCount);
                if (result >= 0)
                {
                    Interlocked.CompareExchange(ref CernyConjectureFailingIndex, result, -1);
                }
            })
            {
                IsBackground = false
            };

            thread.Start();

            IComputable gpu       = new SlimGPUQueue();
            var         gpuResult = gpu.Compute(problemsToSolve, cpuProblems, computationResults, cpuProblems, problemCount - cpuProblems, gpu.GetBestParallelism());

            if (gpuResult >= 0)
            {
                thread.Abort();
                return(gpuResult);
            }
            else
            {
                thread.Join();
                return(CernyConjectureFailingIndex);
            }
        }
        public ComputationResult[] Compute(Problem[] problemsToSolve, int degreeOfParallelism, float cpuPart)
        {
            IEnumerable <ComputationResult> cpuResults = null;
            int cpuProblems = (int)Math.Floor(problemsToSolve.Count() * cpuPart);

            var gpu        = new SlimGPUQueue();
            var gpuResults = gpu.Compute(
                problemsToSolve.Skip(cpuProblems).Take(problemsToSolve.Count() - cpuProblems).ToArray(),
                gpu.GetBestParallelism(),
                () =>
            {
                var cpu    = new SlimCPU();
                cpuResults = cpu
                             .Compute(problemsToSolve
                                      .Take(cpuProblems).ToArray(),
                                      cpu.GetBestParallelism());
            });

            return(cpuResults.Concat(gpuResults).ToArray());
        }