Ejemplo n.º 1
0
        protected virtual void CalculCompleted(IComputable computable)
        {
            if (CalculCompletedEvent != null)
            {
                ComputableEventArgs eventArgs = new ComputableEventArgs();
                eventArgs.Computable = computable;

                CalculCompletedEvent(this, eventArgs);
            }
        }
Ejemplo n.º 2
0
        //****************************************************************************************************
		private void AddFront(IComputable obj) {
			m_c++;
			if (m_c == 1)
				m_top = m_bottom = new Element(obj, null);
			else {
				Element t = new Element(obj, null);
				m_bottom.m_next = t;
				m_bottom = t;
			}
		}
Ejemplo n.º 3
0
        private void ParallelCompute(IComputable computable)
        {
            computable.Compute();

            CountCalculated++;

            base.CalculCompleted(computable);

            if (CountCalculated >= this.ListComputable.Count && !AreAllCalculCompleted)
                base.AllCalculCompleted();
        }
Ejemplo n.º 4
0
        protected override void CalculCompleted(IComputable computable)
        {
            CountCalculated++;

            base.CalculCompleted(computable);

            if (!IsThreadAlive())
            {
                return;
            }

            ThreadingBaseMethod threadingMethod = this.ListThread.Find(t => t.computable == computable);

            this.ListThread.Remove(threadingMethod);

            CreateNewThread(1);
        }
Ejemplo n.º 5
0
        public void Mul(IComputable computer)
        {
            var mul = computer.Mul(1, 2);

            Assert.Equal(2, mul);
        }
Ejemplo n.º 6
0
 public MefTest(IComputable computer)
 {
     this._computer = computer;
 }
Ejemplo n.º 7
0
 private ComputationResultVM Count(List <ReceivedMeasurement> measurements, IComputable analyzeComponent, AnalysisVM viewmodel)
 {
     analyzeComponent.Analyze(measurements, viewmodel);
     return(analyzeComponent.GetResult());
 }
Ejemplo n.º 8
0
 public static void DisplayAnswer(IComputable computable)
 {
     Console.WriteLine(computable.Problem);
     Console.WriteLine(computable.AnswerDesc + " " + computable.Answer.ToString());
     Console.WriteLine();
 }
Ejemplo n.º 9
0
 public ThreadingNativeMethod(ThreadManagerBase threadManager, IComputable computable)
     : base(threadManager, computable)
 {
 }
Ejemplo n.º 10
0
 public ThreadingBaseMethod(ThreadManagerBase threadManager, IComputable computable)
 {
     this.computable = computable;
     this.threadManager = threadManager;
 }
Ejemplo n.º 11
0
			internal Element(IComputable obj, Element next) {
				m_o = obj;
				m_next = next;
			}
        static void Main(string[] args)
        {
            #region Program definitions
            const int problemSize = 12;
            var       theSolver   = new IComputable[]
            {
                new SlimCPU4bits13(),
                //new SlimCPU5bits(),
                //new SlimCPUCoalesced(),
                //new SlimCPUUntweaked(),
                //new SlimGPUQueue(),
                //new SlimCPUGPU(),
                //new SuperSlimGPUBreakthrough()
            };
            #endregion

            #region creditentials
            var email    = string.Empty;
            var password = new SecureString();
            Console.WriteLine("Send email notifications? (y/n)");
            if (Console.ReadKey().KeyChar.ToString().ToLower().Equals("y"))
            {
                Console.WriteLine();
                Console.WriteLine("Please enter notification email: (will send to self)");
                email = Console.ReadLine();
                Console.WriteLine($"Please enter the creditentials for the selected email");
                foreach (var ch in Console.ReadLine())
                {
                    password.AppendChar(ch);
                }
                Console.Clear();
                Console.WriteLine("Creditentials saved");
            }
            #endregion

            //Gpu.Default.Device.Print();
            const int problemSeed = 1234567;
            var       random      = new Random(problemSeed);
            var       watch       = new Stopwatch();

            var version    = theSolver.GetType().Namespace;
            var csvBuilder = new StringBuilder("problemsize,problemcount");
            foreach (var solver in theSolver)
            {
                csvBuilder.Append(",").Append(solver.GetType().Name);
            }
            //var resultsDictionary = new List<ComputationResult>();

            var sizeIncrease = 1;// Math.Pow(2, 1d / 8d);
            var initialProblemSamplingCount = 1 << 21;
            var maximalProblemCount         = 1 << 25;

            double doublePrecisionN = initialProblemSamplingCount;
            var    problems         = new Problem[0];
            for (int n = (int)doublePrecisionN; n < maximalProblemCount; n = (int)Math.Round(doublePrecisionN *= sizeIncrease))
            //for (int i = 0; i < 10; i++)
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.WriteLine($"{n} problems");
                Console.ResetColor();
                Console.WriteLine();

                var latestCPUPerformance = TimeSpan.FromSeconds(1);
                var latestGPUPerformance = TimeSpan.FromSeconds(1);
                csvBuilder.AppendLine();
                csvBuilder.Append(problemSize).Append(",").Append(n);
                if (problems.Length != n)
                {
                    problems = new Problem[n];
                    Problem.FillArrayOfProblems(problems, n, problemSize, problemSeed + n);
                }
                foreach (var solver in theSolver)
                {
                    if (computeLoopUsing(solver))
                    {
                        return;
                    }
                    ;
                }

                bool computeLoopUsing(IComputable solver)
                {
                    //var problems = new[] { Problem.GenerateWorstCase(problemSize) };
                    //var problems = Problem.GetArrayOfProblems(16, 3, 123456).Skip(10).Take(6);

                    bool Compute(IComputable localSolver, Problem[] localProblems, ComputationResult[] localResults)
                    {
                        var result = localSolver.Verify(problems, 0, problems.Length, localSolver.GetBestParallelism());

                        if (result >= 0)
                        {
                            File.AppendAllText($@"./cernyFailed.csv", problems[result].ToString());

                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine($"Cerny Conjecture is false.");
                            Console.WriteLine($"Problem description: {problems[result]}");
                            Console.ResetColor();

                            new Notifications.OpenBrowserTab().Notify(problems[result]);
                            new Notifications.SendEmail().Notify(problems[result], email, password);

                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    var results = new ComputationResult[problems.Length];

                    if (solver is SlimCPUGPU)
                    {
                        ((SlimCPUGPU)solver).SetCPUPart((float)(latestCPUPerformance.TotalMilliseconds / (latestCPUPerformance.TotalMilliseconds + latestGPUPerformance.TotalMilliseconds)));
                    }
                    watch.Restart();
                    if (Compute(solver, problems, results))
                    {
                        return(true);
                    }
                    watch.Stop();
                    var computationElapsed = watch.Elapsed;

                    if (solver is SlimCPU4bits13)
                    {
                        latestCPUPerformance = computationElapsed;
                    }
                    else if (solver is SlimGPUQueue)
                    {
                        latestGPUPerformance = computationElapsed;
                    }
                    //var summary = new ComputationResultSummary();
                    csvBuilder.Append(",").Append(Math.Round(n / computationElapsed.TotalSeconds));
                    //var benchmarkkedResults = results.Where(result => result.benchmarkResult != null && result.benchmarkResult.benchmarkedTime != null && result.benchmarkResult.totalTime != null);
                    //var computationToTotalFraction = benchmarkedResults.Sum(result => result.benchmarkResult.benchmarkedTime.TotalMilliseconds)
                    //    / benchmarkedResults.Sum(result => result.benchmarkResult.totalTime.TotalMilliseconds);
                    //Console.WriteLine(computationToTotalFraction);
                    //watch.Reset();
                    //watch.Start();
                    //if (!(
                    //        results.Zip(problems, (result, problem) =>
                    //            !result.isSynchronizable || Verify.VerifyValidityOfSynchronizingWord(problem, result, degreeOfParallelism)
                    //        ).All(isOK => isOK)
                    //        &&
                    //        results.Zip(problems, (result, problem) =>
                    //            Verify.VerifyCernyConjecture(problem, result)
                    //        ).All(isOK => isOK)
                    //    ))
                    //{
                    //    throw new Exception("Incorrect algorithm");
                    //}
                    //watch.Stop();

                    var verificationElapsed = watch.Elapsed;

                    //resultsDictionary.AddRange(results);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write(solver.GetType());
                    Console.ResetColor();
                    Console.Write($" using {solver.GetBestParallelism()} parallelism in {computationElapsed.TotalMilliseconds:F2}ms. Problems per second: ");
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write($"{n / computationElapsed.TotalSeconds:F2}");
                    Console.ResetColor();
                    Console.WriteLine($". Time per problem {computationElapsed.TotalMilliseconds / n}ms");

                    //Console.WriteLine($"{n} problems verified using {degreeOfParallelism} processors in {verificationElapsed.TotalMilliseconds:F2}ms. " +
                    //    $"Verifications per second: {n / verificationElapsed.TotalSeconds:F2}. " +
                    //    $"Time per verification {verificationElapsed.TotalMilliseconds / n:F5}ms");

                    //Console.WriteLine($"Summary: {results.Average(result => result.isSynchronizable ? 1 : 0) * 100:F2}% synchronizability, " +
                    //    $"{results.Where(result => result.isSynchronizable).Average(result => result.shortestSynchronizingWordLength):F2} average length of a synchronizing word");

                    //var lessThanOrEqualTo = 10;
                    //Console.WriteLine($"fraction of less or equal to {lessThanOrEqualTo} is {results.Select(result => result.shortestSynchronizingWordLength <= lessThanOrEqualTo ? 1 : 0).Average()}");

                    //#region Histogram
                    //var histogram = results
                    //                .Where(result => result.isSynchronizable)
                    //                .Histogram(30, result => result.shortestSynchronizingWordLength);

                    //foreach (var bin in histogram)
                    //{
                    //    Console.Write($"{Math.Round(bin.RepresentativeValue)} (count: {bin.Count}): ");
                    //    for (int i = 0; i < bin.Count * 500 / n || (i == 0 && bin.Count > 0); i++)
                    //    {
                    //        Console.Write("-");
                    //    }
                    //    Console.WriteLine();
                    //}
                    //Console.WriteLine();
                    //#endregion

                    #region Benchmark
                    //Console.WriteLine($"benchmarked time took {100 * fractionOfTime:F2}%");
                    #endregion
                    //Console.WriteLine(results.Average(result => result.queueBreadth));

                    //save appropriate statistical data to a file from resultsDictionary
                    System.IO.File.WriteAllText($@"./gpgpu.csv", csvBuilder.ToString());
                    Console.WriteLine();
                    Console.WriteLine();
                    return(false);
                }
            }
        }
Ejemplo n.º 13
0
        private void RefreshProgression(int count, IComputable computable)
        {
            progressBar.Value = count;

            //if (btnShowMapResolving.Text == BUTTON_MAP_OFF)
                computable.Draw(_gMap);
        }
 public ThreadingBackgroundWorkerMethod(ThreadManagerBackgroundWorker threadManager, IComputable computable)
     : base(threadManager, computable)
 {
 }
Ejemplo n.º 15
0
 public static void DisplayAnswer(IComputable computable)
 {
     Console.WriteLine(computable.Problem);
     Console.WriteLine(computable.AnswerDesc + " " + computable.Answer.ToString());
     Console.WriteLine();
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Creates an instance of this computable with the required input.
 /// </summary>
 /// <param name="input"></param>
 public ToString(IComputable <T> input)
 {
     Input = input;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Creates an instance of the if-then-else-computable with the condition-, then- and else-computable.
 /// </summary>
 /// <param name="condition">The condition-computable.</param>
 /// <param name="thenComputable">The then-computable.</param>
 /// <param name="elseComputable">The else-computable.</param>
 public If(IBooleanComputable condition, IComputable <T> thenComputable, IComputable <T> elseComputable)
 {
     Condition      = condition;
     ThenComputable = thenComputable;
     ElseComputable = elseComputable;
 }