Skip to content

Commit

Permalink
Update ParallelAlgoPrim.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKuz1001 authored Dec 8, 2019
1 parent 5cacdd1 commit f55666a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Task02/ParallelAlgoPrim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ParallelAlgoPrim
static HashSet<int> tree; // вершины, лежащие в остовном дереве
static int[] minDistToTree;

static void FindNewV(int LIndex, int RIndex)
static void FindNewV(Graph graph, int LIndex, int RIndex)
{
// нахождение очередной вершины с минимальным расстоянием до дерева
int localV = -1; // локальный ответ
Expand All @@ -26,9 +26,9 @@ static void FindNewV(int LIndex, int RIndex)
if (!tree.Contains(to))
{
// обновление минимального расстояния после добавления v в дерево
if (minDistToTree[to] > GeneralResources.graphMatrix[v, to])
if (minDistToTree[to] > graph.graphMatrix[v, to])
{
minDistToTree[to] = GeneralResources.graphMatrix[v, to];
minDistToTree[to] = graph.graphMatrix[v, to];
}

// обновление локального ответа
Expand All @@ -51,13 +51,13 @@ static void FindNewV(int LIndex, int RIndex)
mutRunningThreads.ReleaseMutex();
}

public static int Execute()
public static int Execute(Graph graph)
{
int ans = 0;
tree = new HashSet<int>();
minDistToTree = new int[GeneralResources.n];
Array.Fill(minDistToTree, GeneralResources.INF);
chunkSize = GeneralResources.n / amountThreads;
minDistToTree = new int[graph.graphAmountVertexes];
Array.Fill(minDistToTree, Graph.INF);
chunkSize = graph.graphAmountVertexes / amountThreads;

// начинаем с вершины 0
minDistToTree[0] = 0;
Expand All @@ -75,10 +75,10 @@ public static int Execute()
{
int LIndex = chunkSize * i;
int RIndex = chunkSize * (i + 1);
ThreadPool.QueueUserWorkItem(_ => FindNewV(LIndex, RIndex));
ThreadPool.QueueUserWorkItem(_ => FindNewV(graph, LIndex, RIndex));
}
// загрзим главный поток чтобы он просто так не ждал
FindNewV(chunkSize * (amountThreads - 1), GeneralResources.n);
FindNewV(graph, chunkSize * (amountThreads - 1), graph.graphAmountVertexes);

while (runningThreads > 0) {}

Expand Down

0 comments on commit f55666a

Please sign in to comment.