コード例 #1
0
        public List <long> Start()
        {
            _log.WriteDataToLog(DateTime.Now.ToString() + "------------------------");
            _log.WriteDataToLog("Threads    Time, ms ");
            List <long> data = new List <long>();

            for (int i = 1; i <= _maxQThreads; i++)//цикл деления поля на потоки
            {
                InizializeField();
                int p = _size / i;//количество строк в потоке

                Stopwatch stopWatch = new Stopwatch();
                _countdown = new CountdownEvent(i);

                stopWatch.Start();

                //List<Thread> myThrConteiner = new List<Thread>();
                List <IAsyncResult> myDelConteiner = new List <IAsyncResult>();
                for (int k = 0, j = 0; j < i; k = k + p, j++)
                {
                    PartMatrix mypiece = new PartMatrix();
                    mypiece.begin = k;
                    mypiece.end   = k + p;

                    CalculateHandler handler = new CalculateHandler(CalculateCells1);
                    //IAsyncResult resultObj =
                    handler.BeginInvoke(mypiece, handler.EndInvoke, null);

                    //myDelConteiner.Add(resultObj);
                    //Thread myThread = new Thread(new ParameterizedThreadStart(CalculateCells));
                    //myThrConteiner.Add(myThread);
                    //myThread.Start(mypiece);
                }

                //_countdown.Wait();   // Blocks until Signal has been called "i" times
                //for (int n = 0; n < myThrConteiner.Count; n++)
                //{
                //    myThrConteiner[n].Join();
                //}
                //for (int j = 0; j < myDelConteiner.Count; j++)
                //{
                //    myDelConteiner[j].EndInvoke(resultObj)
                //}

                stopWatch.Stop();
                data.Add(stopWatch.ElapsedMilliseconds);
                _log.WriteDataToLog("" + stopWatch.ElapsedMilliseconds + "; " + CheckMatrix());
            }
            MessageBox.Show("Вычисление матрицы завершено");
            _log.Close();
            return(data);
        }
コード例 #2
0
        public void CalculateCells2(object c)
        {
            PartMatrix c1     = (PartMatrix)c;
            int        _begin = c1.begin;
            int        _end   = c1.end;

            for (int i = _begin; i < _end; i++)
            {
                for (int j = 0; j < _size; j++)
                {
                    _field[i, j] = false;
                    //_field[i, j] = _field[i, j] * 1;
                }
            }
            //_countdown.Signal();
        }
コード例 #3
0
        public List <long> StartTasks()
        {
            _log.WriteDataToLog(DateTime.Now.ToString() + "---(Tasks)-----------------");
            _log.WriteDataToLog("Threads    Time, ms ");
            List <long> data = new List <long>();

            for (int i = 1; i <= _maxQThreads; i++)//цикл деления поля на потоки
            {
                InizializeField();
                int p = _size / i;//количество строк в потоке

                Stopwatch stopWatch = new Stopwatch();
                _countdown = new CountdownEvent(i);
                stopWatch.Start();

                for (int k = 0, j = 0; j < i; k = k + p, j++)
                {
                    PartMatrix mypiece = new PartMatrix();
                    mypiece.begin = k;
                    mypiece.end   = k + p;
                    Task task = new Task(() =>
                    {
                        for (int i1 = mypiece.begin; i1 < mypiece.end; i1++)
                        {
                            for (int j1 = 0; j1 < _size; j1++)
                            {
                                _field[i1, j1] = false;
                                //_field[i, j] = _field[i, j] * 1;
                            }
                        }
                        _countdown.Signal();
                    });
                    task.Start();
                }
                _countdown.Wait();   // Blocks until Signal has been called 3 times

                stopWatch.Stop();
                data.Add(stopWatch.ElapsedMilliseconds);
                _log.WriteDataToLog("" + stopWatch.ElapsedMilliseconds + "; " + CheckMatrix());
            }
            MessageBox.Show("Вычисление матрицы завершено");
            _log.Close();
            return(data);
        }
コード例 #4
0
        public List <long> StartOuterTask()
        {
            _log.WriteDataToLog(DateTime.Now.ToString() + "---(StartOuterTask)-----------------");
            _log.WriteDataToLog("Threads    Time, ms ");
            List <long> data = new List <long>();

            for (int i = 1; i <= _maxQThreads; i++)//цикл деления поля на потоки
            {
                InizializeField();
                int       p         = _size / i;//количество строк в потоке
                Stopwatch stopWatch = new Stopwatch();

                stopWatch.Start();
                var outer = Task.Factory.StartNew(() => {
                    for (int k = 0, j = 0; j < i; k = k + p, j++)
                    {
                        PartMatrix mypiece = new PartMatrix();
                        mypiece.begin      = k;
                        mypiece.end        = k + p;
                        var task           = Task.Factory.StartNew(() =>
                        {
                            for (int i1 = mypiece.begin; i1 < mypiece.end; i1++)
                            {
                                for (int j1 = 0; j1 < _size; j1++)
                                {
                                    _field[i1, j1] = false;
                                    //_field[i, j] = _field[i, j] * 1;
                                }
                            }
                        }, TaskCreationOptions.AttachedToParent);
                    }
                });
                outer.Wait();

                stopWatch.Stop();
                data.Add(stopWatch.ElapsedMilliseconds);
                _log.WriteDataToLog("" + stopWatch.ElapsedMilliseconds + "; " + CheckMatrix());
            }
            MessageBox.Show("Вычисление матрицы завершено");
            _log.Close();
            return(data);
        }
コード例 #5
0
        public List <long> StartThreads()
        {
            _log.WriteDataToLog(DateTime.Now.ToString() + "---(Threads)-----------------");
            _log.WriteDataToLog("Threads    Time, ms ");
            List <long> data = new List <long>();

            for (int i = 1; i <= _maxQThreads; i++)//цикл деления поля на потоки
            {
                InizializeField();
                int       p         = _size / i;//количество строк в потоке
                Stopwatch stopWatch = new Stopwatch();
                _countdown = new CountdownEvent(i);

                stopWatch.Start();

                for (int k = 0, j = 0; j < i; k = k + p, j++)
                {
                    PartMatrix mypiece = new PartMatrix();
                    mypiece.begin = k;
                    mypiece.end   = k + p;

                    Thread myThread = new Thread(new ParameterizedThreadStart(CalculateCells));

                    myThread.Start(mypiece);
                }

                _countdown.Wait();   // Blocks until Signal has been called "i" times

                stopWatch.Stop();
                data.Add(stopWatch.ElapsedMilliseconds);
                _log.WriteDataToLog("" + stopWatch.ElapsedMilliseconds + "; " + CheckMatrix());
            }
            MessageBox.Show("Вычисление матрицы завершено");
            _log.Close();
            return(data);
        }