POJ 1502 MPI Maelstrom Dijkstra algorithm simple application, oh, I guess a lot of people do not understand what meaning, I also watched for a long time

Source: Internet
Author: User

MPI Maelstrom
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 5831 Accepted: 3621

Description

BIT has recently taken delivery of their new supercomputer, a processor Apollo Odyssey distributed shared memory Machin E with a hierarchical communication subsystem. Valentine McKee ' s-advisor, Jack Swigert, has asked's to benchmark the new system.
"Since the Apollo is a distributed GKFX memory machine, memory access and communication times was not uniform, ' valent Ine told Swigert. ' Communication is fast between processors that share the same memory subsystem, but it's slower between processors that is not on the same subsystem. Communication between the Apollo and machines in we lab is slower yet.

"How is Apollo's port of the Message passing Interface (MPI) working out?" Swigert asked.

' Not so well, ' ' Valentine replied. "To do a broadcast of a" of a message from one processor to all the other n-1 processors, they just do a sequence of n-1 sends. That really serializes things and kills the performance. "

"Is there anything" can do "fix that?"

' Yes, ' smiled Valentine. "There is." Once The first processor has sent-the message to another, those-can-then-send messages to-the-other hosts at the same Time. Then there would be a four hosts that can send, and so on.

' Ah, so you can do the broadcast as a binary tree! '

' Not really a binary tree--there is some particular features of our network that we should exploit. The interface cards we have an allow each processor to simultaneously send messages to all number of the other processors con Nected to it. However, the messages don ' t necessarily arrive at the destinations time--same are a there cost communication Ved. In general, we need-to-take-into-account the communication-costs for each link in our network topologies and plan Accordin Gly to minimize the total time required to do a broadcast. "

Input

The input would describe the topology of a network connecting n processors. The first line of the input would be n, the number of processors, such that 1 <= n <= 100.

The rest of the input defines an adjacency matrix, A. The adjacency matrix is square and of size n x N. Each of its entries would be either an integer or the character x. The value of a (I,J) indicates the expense of sending A message directly from node I to node J. A value of X for A (I,J) indicates that a message cannot is sent directly from the node I to node J.

Note that for a node to send a message to itself does not require network communication, so a (i,i) = 0 for 1 <= i <= N. Also, assume that the network is undirected (messages can go on either direction with equal overhead) A (I,J) = A (j,i). Thus only the entries on the (strictly) lower triangular portion of A would be supplied.

The input to your program is the lower triangular section of A. That's, the second line of input would contain one entry, A (2,1). The next line would contain the entries, a (3,1) and A (3,2), and so on.

Output

Your program should output the minimum communication time required to broadcast a message from the first processor to all The other processors.

Sample Input

55030 5100 5010 x x 10

Sample Output

35
The main problem is that the first processor sends information to other processors connected to him, and when the other processor receives the information, the processor that receives the message also sends the message to the other processor that is connected to him.
The shortest time that all processors are receiving information.
The time at which the processor sends a message to himself is omitted at input, implicitly equal to 0, and a[i][j]=a[j][i], i.e. a[i][j] and a[j][i] omit one of the inputs. So the input correlation matrix is a triangular shape.
Code:
#include <stdio.h> #include <string.h> #include <stdlib.h> #define MAX 110#define INF 500000000int  Graph[max][max],dist[max];void Dijkstra (int len) {int sum = 0;d ist[1] = 0; bool Closed[max]; closed[1] = true; for (int i = 2; I <= Len; ++i) {Dist[i] = Graph[1][i]; Closed[i] = false;} for (int i = 1; l <= Len; ++i) {int min = INF, index = 0, for (int j = 1; j <= Len; ++j) {if (!closed[j] && Dist[j]<min) {index = j; min = Dist[j];}} if (index = = 0) {break;} Closed[index] = true; for (int j = 1; j <= Len; ++j) {if (Dist[j]>dist[index]+graph[index][j]) {Dist[j] = dist[index]+ GRAPH[INDEX][J];}}}  int main () {int n = 0; while (scanf ("%d", &n)! = EOF) {graph[1][1] = 0; for (int i = 2; I <= n; ++i) {for (int j = 1; j < I; ++J) {char w[15]; scanf ("%s", W), if (w[0]! = ' x ') graph[i][j] = Graph[j][i] = atoi (w); Elsegraph[i][j] = graph[j][i] = INF;} Graph[i][i] = 0;} Dijkstra (n); int ans =-inf; for (int i = 2; I <= n; ++i) {if (Dist[i]>ans) {ans = dist[i] ;}} printf ("%d\n", ans);} return 0;}


POJ 1502 MPI Maelstrom Dijkstra algorithm simple application, oh, I guess a lot of people do not understand what meaning, I also watched for a long time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.