Example #1
0
        public void Start()
        {
            _log.Info("Starting to find points");
            _log.DebugFormat("Random Generator: {0}", _pointGenerator.GetType().Name);
            _log.DebugFormat("Minimum Threshold: {0:N0}", _minimum);
            _log.DebugFormat("Maximum Threshold: {0:N0}", _maximum);

            var bailout = new BailoutRange(
                minimum: _minimum,
                maximum: _maximum);

            var viewPort = AreaFactory.SearchArea;

            viewPort.LogViewport();

            var list = new ComplexNumberListWriter(_outputDirectory, _outputFile);

            int num = 0;

            Parallel.ForEach(_pointGenerator.GetRandomComplexNumbers(viewPort), new ParallelOptions {
                MaxDegreeOfParallelism = GlobalArguments.DegreesOfParallelism
            },
                             (number, state) =>
            {
                if (ValidatePoint(number, bailout))
                {
                    Interlocked.Increment(ref num);
                    list.SaveNumber(number);

                    if (num % 100 == 0)
                    {
                        _log.DebugFormat("Found {0:N0} points", num);
                    }
                }

                if (ShouldStop)
                {
                    state.Break();
                    _log.Debug("This process stopped");
                }
            });

            _log.DebugFormat("Found {0:N0} points", num);
            _log.Info("Stopped finding points");
        }
Example #2
0
        public void Start()
        {
            _log.Info("Starting to find points");
            _log.DebugFormat("Random Generator: {0}", _pointGenerator.GetType().Name);
            _log.DebugFormat("Minimum Threshold: {0:N0}", _minimum);
            _log.DebugFormat("Maximum Threshold: {0:N0}", _maximum);

            var bailout = new BailoutRange(
                minimum: _minimum,
                maximum: _maximum);

            var viewPort = AreaFactory.SearchArea;

            viewPort.LogViewport();

            var list = new ComplexNumberListWriter(_outputDirectory, _outputFile);

            int num = 0;

            Parallel.ForEach(_pointGenerator.GetRandomComplexNumbers(viewPort), new ParallelOptions { MaxDegreeOfParallelism = GlobalArguments.DegreesOfParallelism },
                (number, state) =>
                {
                    if (ValidatePoint(number, bailout))
                    {
                        Interlocked.Increment(ref num);
                        list.SaveNumber(number);

                        if (num % 100 == 0)
                        {
                            _log.DebugFormat("Found {0:N0} points", num);
                        }
                    }

                    if (ShouldStop)
                    {
                        state.Break();
                        _log.Debug("This process stopped");
                    }
                });

            _log.DebugFormat("Found {0:N0} points", num);
            _log.Info("Stopped finding points");
        }
        public void ShouldRoundTripNumbers()
        {
            var numbers = new[]
            {
                new Complex(),
                new Complex(1, 1),
                new Complex(0.25, 0.5)
            };

            string path = Path.GetTempFileName();
            var file = new FileInfo(path);

            try
            {
                var listWriter = new ComplexNumberListWriter(file.DirectoryName, file.Name);

                foreach (Complex n in numbers)
                {
                    listWriter.SaveNumber(n);
                }

                var listReader = new ComplexNumberListReader(file.DirectoryName, String.Format("{0}*.point", file.Name));

                Complex[] roundTripped = listReader.GetNumbers().ToArray();

                Assert.That(
                    roundTripped.Select(n => n.ToString()).ToArray(),
                    Is.EquivalentTo(numbers.Select(n => n.ToString()).ToArray()),
                    "Did not save and load numbers.");
            }
            finally
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
        }