Пример #1
0
        static void Main(string[] args)
        {
            var devices = ClooExtensions.GetDeviceNames();

            foreach (var dev in devices.Where(d => args.Length == 0 || args.Contains(d.Trim())))
            {
                WriteLine(dev.Trim(), ConsoleColor.Yellow);

                int[] primes = Enumerable.Range(2, 1000000).ToArray();

                var sw = new Stopwatch();
                try
                {
                    sw.Start();
                    primes.ClooForEach(IsPrime, k => true, (i, d, v) => d == dev);
                    WriteLine($"{string.Join(", ", primes.Where(n => n != 0).Take(100))}, ...", ConsoleColor.Gray);
                }
                catch (Exception ex)
                {
                    WriteLine($"Error: {ex.Message}", ConsoleColor.Red);
                }
                finally
                {
                    sw.Stop();
                    WriteLine($"Time: {sw.ElapsedMilliseconds}ms");
                }

                WriteLine();
            }

            WriteLine("Press enter to quit...", ConsoleColor.White, true);
        }
Пример #2
0
        public MainWindowViewModel()
        {
            var items = new SourceList <TestItem>();

            items.AddRange(this.tests.Select(t => new TestItem
            {
                StringValue = t.Key
            }));
            items.Connect().Bind(this.Items).Subscribe();

            var platforms = new SourceList <TestItem>();

            platforms.AddRange(ClooExtensions.GetDeviceNames().Select((d, i) => new TestItem
            {
                StringValue = d.Trim()
            }));
            platforms.Connect().Bind(this.Platforms).Subscribe();

            var selectedItems = new SourceList <TestItem>();

            selectedItems.AddRange(new List <TestItem>());
            selectedItems.Connect().Bind(this.SelectedItems).Subscribe();

            this.SelectedPlatformIndex = 0;

            this.RunItems = ReactiveCommand.CreateFromTask(async() =>
            {
                var selectedTestNames = this.SelectedItems.Select(si => si.StringValue).ToList();
                this.ResultText       = $"Started {selectedTestNames.Count()} test(s)...";

                var sw = new Stopwatch();
                foreach (var testName in selectedTestNames)
                {
                    this.ResultText += $"{Environment.NewLine}";
                    sw.Restart();
                    try
                    {
                        this.ResultText += await Task.Run(() => this.tests[testName](this.selectedPlatformIndex));
                    }
                    catch (Exception ex)
                    {
                        this.ResultText += ex.ToString();
                    }
                    finally
                    {
                        sw.Stop();
                    }
                    this.ResultText += $"{Environment.NewLine}Time({testName}): {sw.Elapsed}";
                }

                this.ResultText += $"{Environment.NewLine} All {selectedTestNames.Count()} test(s) done!";
            }, this.SelectedItems.ObserveCollectionChanges().Select(x => this.SelectedItems.Any()));
        }
Пример #3
0
        public static int Main(string[] args)
        {
            const int DataSize = 10000000;
            var       sw       = new Stopwatch();

            // OpenCL part
            var deviceNames = ClooExtensions.GetDeviceNames();

            int[] primes;

            for (int deviceId = 0; deviceId < deviceNames.Length; deviceId++)
            {
                primes = Enumerable.Range(2, DataSize).ToArray();

                sw.Restart();
                primes.ClooForEach(IsPrime, null, (i, n, v) => i == deviceId);
                sw.Stop();
                Console.WriteLine($"OpenCL[{deviceId}] ({deviceNames[deviceId]}): {sw.ElapsedMilliseconds}ms");

                Console.WriteLine(string.Join(", ", primes.Where(n => n != 0).Where(n => n != 0).Take(20)));
            }

            // CPU part
            primes = Enumerable.Range(2, DataSize).ToArray();

            sw.Restart();
            for (int id = 0; id < primes.Length; id++)
            {
                var tmp    = primes[id];
                int upperl = (int)Math.Sqrt((float)tmp);
                for (int i = 2; i <= upperl; i++)
                {
                    if (tmp % i == 0)
                    {
                        primes[id] = 0;
                        break;
                    }
                }
            }
            sw.Stop();
            Console.WriteLine($"CPU: {sw.ElapsedMilliseconds}ms");
            Console.WriteLine(string.Join(", ", primes.Where(n => n != 0).Where(n => n != 0).Take(20)));

            Console.Write($"Done, press any key to exit...");
            Console.ReadKey();

            return(0);
        }
Пример #4
0
        public MainWindowViewModel()
        {
            this.Items = new ReactiveList <TestItem>(
                this.tests.Select(t => new TestItem
            {
                StringValue = t.Key
            }));

            this.Platforms = new ReactiveList <TestItem>(
                ClooExtensions.GetDeviceNames().Select((d, i) => new TestItem
            {
                StringValue = d
            }));

            this.SelectedItems = new ReactiveList <TestItem>();

            this.SelectedPlatformIndex = 0;

            this.RunItems = ReactiveCommand.CreateFromTask(async() =>
            {
                var selectedTestNames = this.SelectedItems.Select(si => si.StringValue).ToList();
                this.ResultText       = $"Started {selectedTestNames.Count} test(s)... {Environment.NewLine}";

                var sw = new Stopwatch();
                foreach (var testName in selectedTestNames)
                {
                    sw.Restart();
                    try
                    {
                        this.ResultText += await Task.Run(() => this.tests[testName](this.selectedPlatformIndex));
                    }
                    catch (Exception ex)
                    {
                        this.ResultText += ex.ToString();
                    }
                    finally
                    {
                        sw.Stop();
                    }
                    this.ResultText += $"{Environment.NewLine}Time({testName}): {sw.Elapsed}";
                }

                this.ResultText += $"{Environment.NewLine} All {selectedTestNames.Count} test(s) done!";
            }, this.SelectedItems.CountChanged.Select(count => count != 0));
        }