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

Автор работы: Пользователь скрыл имя, 27 Мая 2013 в 21:11, практическая работа

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

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

Содержание

Введение 3
1 Теоретические предпосылки поставленной проблемы 5
2 Разработка программного средства 12
2.1 Постановка задачи 12
2.2 Спецификация основных процедур и функций 13
2.3 Спецификация данных 14
2.3.1 Структура входных данных 15
2.4 Разработка алгоритма решения задачи 15
2.4.1 Укрупненная схема алгоритма программного средства 15
2.5 Установка и эксплуатация программного средства 16
2.6 Работа с программным средством 16
Заключение 19
Список использованных источников 20
Приложение А – Текст программы 21
Приложение Б – Контрольный пример 31

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

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

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

               

            }

            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)

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

                            if (S[i, x] + S[j, x] > 0)

                                S[i, x] = 1;

                            else S[i, x] = 0;

        }

        public void FillMatrN()

        {

            for (int j = 1, t = 0; j < sz; j++)

            {

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

                    if (mtr[i, j] > 2)

                    {

                        t = i;

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

                            if ((mtr[x, j] > 2) && (x != t))

                            {

                                L[t, x] = 1;

                                L[x, t] = 1;

                            }

                    }

 

            }

            //------------------

            int[,] Lt = new int[sz, sz];

            List<List<int>> C = new List<List<int>>();

            List<int> uni = new List<int>();

 

            List<int> inter = new List<int>();

 

            for (int i = 1; i < sz; i++, C.Clear(), uni.Clear(), inter.Clear())

            {

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

                    if (mtr[i, j] > 0)

                    {

                        C.AddVertex(new List<int>());

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

                            if (L[j, x] == 1)

                                C[C.Count - 1].AddVertex(x);

                    }

                //union

                if (C.Count == 1)

                    foreach (int nt in C[0])

                        L[i, nt] = L[nt, i] = 1;

                else

                    if (C.Count > 0)

                    {

                        IEnumerable<int> both;

                        both = C[0];

                        foreach (List<int> lst in C)

                        {

                            both = both.Intersect(lst);

                        }

                        foreach (int it in both)

                            L[it, i] = L[i, it] = 1;

                    }

            }

 

 

        }

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