Распараллеливание вычислительных алгоритмов

Автор работы: Пользователь скрыл имя, 21 Января 2013 в 03:16, задача

Краткое описание

В данном расчетно-графическом задании проводится распараллеливание вычислительных процессов с целью закрепления теоретических знаний в области теории распараллеливания вычислительных алгоритмов, формирования практических умений и навыков разработки программного средства для распараллеливания вычислительных алгоритмов и закрепления практических навыков самостоятельного решения инженерных задач, развития творческих способностей и умений пользоваться технической, нормативной и справочной литературой.

Содержание

Введение 3
1 Теоретические предпосылки поставленной проблемы 4
2 Разработка программного средства 16
Заключение 24
Список использованных источников 25
Приложение А – Текст программы 26
Приложение Б – Контрольный пример 31

Вложенные файлы: 1 файл

Отчет РГЗ по ТВП (вариант 4)новый.doc

— 518.50 Кб (Скачать файл)

                }

                catch

                { return; }

            }

        }

 

        private bool isLate=true;

        private void pictureBox2_Paint(object sender, PaintEventArgs e)

        {

            int X0, Y0,dy=40;

            X0 = 20;

            Y0 = pictureBox2.Height - 20;

            Pen pn = new Pen(Color.Black, 4);

            Pen p2 = new Pen(Color.Black, 2);

            Font f=new Font("Arial",10);

         

            e.Graphics.DrawLine(pn, X0, Y0, pictureBox2.Width - 20, Y0);

            int dx;

            if (isLate) dx = nod.FindFT(); else dx =(int) numericUpDown1.Value;

             int nx;

            if(dx>0)nx= (pictureBox2.Width - 40) / dx;else nx=pictureBox2.Width-40;

            for (int x = X0, i = 0;i<=dx; x += nx, i++)

                e.Graphics.DrawString(i.ToString(), f, Brushes.Black, new PointF(x, Y0 + 5));

 

            int[,] grf = new int[10, dx+1];

            bool flag;

           for (int i = 1; i < nod.Get_size()+1; i++,flag=false)

            {

                if (!nod.nd[i - 1].selected) continue;

                int end, start;

                if (isLate)

                {

                    end = nod.Tau[i];

                    start = end - nod.T[i];

                }

                else

                {

                    end = nod.LTau[i];

                    start = end - nod.T[i];

                }

                int level = 1;

                do

                {

                    flag = false;

                    while (grf[level, start] != 0) level++;

                    for (int s = start; s < end; s++)

                        if (grf[ level,s] != 0)

                        {

                            level++;

                            flag = true;

                        }

                } while (flag);

 

                e.Graphics.FillRectangle(Brushes.Green, new Rectangle(X0+start * nx, Y0-level * dy, nx * (end - start), dy));

                e.Graphics.DrawRectangle(p2, new Rectangle(X0+start * nx, Y0 - level * dy, nx * (end - start), dy));

                e.Graphics.DrawString(i.ToString(), f, Brushes.Yellow, new PointF(X0+start * nx+nx * (end - start)/2, Y0-level * dy+dy/2));

                for (int s = start; s < end; s++) grf[level, s] = 1;

               

            }

            pn.Dispose();

            p2.Dispose();

        }

 

        private void button3_Click(object sender, EventArgs e)

        {

            nod.Renum();

            try

            {

                dataGridView4.RowCount = nod.Get_size() + 1;

                dataGridView4.ColumnCount = nod.Get_size() + 1;

                for (int i = 1; i < nod.Get_size() + 1; i++)

                {

                    for (int j = 1; j < nod.Get_size() + 1; j++)

                    {

                        dataGridView4.Rows[i].Cells[j].Value = nod.mtr[i, j];

                        dataGridView4.Columns[j].HeaderCell.Value = j.ToString();

                    }

                    dataGridView4.Rows[i].HeaderCell.Value = i.ToString(); ;

                }

 

                dataGridView4.AutoResizeColumns();

            }

            catch

            { return; }

 

        }

 

        private void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)

        {

            nod.Add(new Point(100, 100));

        }

       

    }     

       

    }

 

 

Класс реализации алгоритмов

 

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.DrawGraphing;

using System.Text;

 

namespace WindowsFormsApplication1

{

    public class round

        {

            public int num;

            public Point p ;

            public bool selected;

            public List<round> next ;

            public int Time;

            public round()

            {

                p = new Point();

                next = new List<round>();

                Time = 1;

            }

           

        }

    class Node

    {

        private int DX,DY;

       

        public Form1 f;

        public int[] T ;

        public int[] Tau ;

        public int[] LTau;

        public int[,] mtr , S , L , N ;

        public List<int> A;

        public List<int> B;

        public List<int> D;

        public int[] C , E ;

 

 

        public round check,src,dst;

        public bool drug;

        public int dx, dy;

        public int sz;

        public List<round> nd = new List<round>();

        private int size=15;

 

        public Node(int s,Form1 ff)

        {

            sz = s;

            f = ff;

            T = new int[sz];

            Tau = new int[sz];

            LTau = new int[sz];

            mtr = new int[sz, sz];

            S = new int[sz, sz];

            L = new int[sz, sz];

            N = new int[sz, sz];

            A = new List<int>();

            B = new List<int>();

            D = new List<int>();

            C = new int[sz];

            E = new int[sz];

            for (int i = 0; i < sz; i++) T[i] = 1;

        }

        public int Get_size()

        {

            return nd.Count;

        }

        public void DrawGraph(Graphics gr)

        {

            Pen pn = new Pen(Color.Black,2);

            Pen p2 = new Pen(Color.Black, 3);

            Font f=new Font("Arial",10,FontStyle.Italic);

            p2.SetLineCap(System.DrawGraphing.DrawGraphing2D.LineCap.Flat, System.DrawGraphing.DrawGraphing2D.LineCap.ArrowAnchor, System.DrawGraphing.DrawGraphing2D.DashCap.Flat);

           

            foreach (var it in nd)

            {

                gr.DrawGraphString(it.num.ToString(), f, Brushes.Blue,new PointF( it.p.X+size-10,it.p.Y+size-10));

                gr.DrawGraphString(it.Time.ToString(), f, Brushes.Red, new PointF(it.p.X -10, it.p.Y -10));

                if (it.selected)

                    pn.Color = Color.Red;

                else

                    pn.Color = Color.Black;

                gr.DrawGraphEllipse(pn,it.p.X, it.p.Y ,2*size, 2* size);

                foreach (var item in it.next)

                {

                    gr.DrawGraphLine(p2, it.p.X+size,it.p.Y+size, item.p.X+size,item.p.Y+size);

                    if (mtr[ item.num,it.num] == -1)

                    {

                        p2.Color = Color.White;

                        p2.Width = 1;

                        gr.DrawGraphLine(p2, it.p.X + size, it.p.Y + size, item.p.X + size, item.p.Y + size);

                        p2.Color = Color.Black;

                        p2.Width = 3;

                    }

                }

 

            }

            f.Dispose();

            pn.Dispose();

            p2.Dispose();

        }

        public void AddVertex(Point P)

        {

            round rnd =new round();

            rnd.num = nd.Count+1;

            rnd.p = P;

                      

            nd.AddVertex(rnd);

            Renum();

        }

        public void Node_Click(object sender, EventArgs e)

        {

           

        }

        public void Node_DbClick(object sender, EventArgs e)

        {

       

 

        }

        public void Node_MD(object sender, System.Windows.Forms.MouseEventArgs e)

        {

            foreach (var it in nd)

                if (((e.X - it.p.X) > 0) && ((e.Y - it.p.Y) > 0) && ((e.X - it.p.X) < 2 * size) && ((e.Y - it.p.Y) < 2 * size))

                {

                    if (e.Button == System.Windows.Forms.MouseButtons.Left)

                    {

                        check = it;

                        drug = true;

                        DX=dx = e.X;

                        DY=dy = e.Y;

                    }

                    else

                    {

                        src = it;

                    }

                }

        }

        public void Node_MU(object sender, System.Windows.Forms.MouseEventArgs e)

        {

            if (e.Button == System.Windows.Forms.MouseButtons.Right)

            {

               

               foreach (var it in nd)

                    if (((e.X - it.p.X) > 0) && ((e.Y - it.p.Y) > 0) && ((e.X - it.p.X) < 2 * size) && ((e.Y - it.p.Y) < 2 * size))

                    {

                       

                        if (it != src)

                        {

                            if (!src.next.Contains(it))

                            {

                                src.next.AddVertex(it);

                                if (f.mode)

                                mtr[it.num,src.num ] = 1;

                                else

                                    mtr[it.num,src.num] = -1;

                                Renum();

                               

                            }

                        }

                        else

                        {

                            it.selected = !it.selected;

                        }

                    }

               

            }

            if (e.Button == System.Windows.Forms.MouseButtons.Left)

            {

                if ((Math.Abs(DX - e.X) < 5) && (Math.Abs(DY - e.Y) < 5))

                {

                    foreach (var it in nd)

                        if (((e.X - it.p.X) > 0) && ((e.Y - it.p.Y) > 0) && ((e.X - it.p.X) < 2 * size) && ((e.Y - it.p.Y) < 2 * size))

                        {

                            if (check == it)

                            {

                                Form2 f = new Form2(it);

                                f.ShowDialog();

                                f.Dispose();

                                T[it.num] = it.Time;

 

                            }

                        }

                }

            }

            check = null;

            drug = false;

            src = dst = null;

        }

        public void Node_MV(object sender, System.Windows.Forms.MouseEventArgs e)

        {

 

//=====================================

            if ((check != null) && (drug))

            {

                check.p.X += e.X - dx;

                check.p.Y += e.Y - dy;

                dx = e.X; dy = e.Y;

            }

           

 

           

        }

 

        public void FillMatrT()

        {

            for (int i = 0; i < sz; i++)

                for (int j = 0; j < sz; j++)

                    S[i, j] = mtr[i, j];

 

            for (int i = 1; i < sz; i++)

                for (int j = 1; j < i; j++)

                    if (S[i, j] > 0)

Информация о работе Распараллеливание вычислительных алгоритмов