POJ 1502 MPI Maelstrom (Dijkstra template title)

Source: Internet
Author: User


MPI Maelstrom
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 5877 Accepted: 3654

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 of the other processors.

Sample Input

55030 5100 5010 x x 10

Sample Output

35

Source

East Central North America 1996

Title Link: http://poj.org/problem?id=1502

The question of English: ... There are n points, the graph is symmetrical, so give a lower triangular matrix, X is two points unreachable, and now ask for the starting point 1 to the shortest possible maximum value of the points

Problem analysis: Build diagram, Dijkstra to find the shortest way, to find the maximum value of short-circuit can be

#include <cstdio> #include <cstring> #include <algorithm>using namespace std;int const MAX = 105;int    Const INF = 0x3fffffff;int Dis[max], E[max][max];bool vis[max];int n;void Dijkstra (int v0) {int ans = 0;        for (int i = 1; I <= n; i++) {vis[i] = false;    Dis[i] = INF;    } for (int i = 1; I <= n; i++) dis[i] = E[v0][i];    Dis[v0] = 0;    Vis[v0] = true;        for (int i = 1; i < n; i++) {int mi = INF, u = v0; for (int j = 1; J <= N; j + +) {if (!vis[j] && dis[j] < mi) {u = j                ;            mi = dis[j];        }} Vis[u] = true; for (int k = 1; k <= N; k++) if (!vis[k] && e[u][k] < INF) Dis[k] = min (dis[k], dis[    U] + e[u][k]);    } for (int i = 1; I <= n; i++) ans = max (ans, dis[i]); printf ("%d\n", ans);}    int main () {int get;    Char ch[2];    scanf ("%d", &n); memset (E, 0, SizeoF (e)); for (int i = 2; I <= n; i++) {for (int j = 1; j < I; J + +) {if (scanf ("%d", &get) = = 1            ) E[j][i] = e[i][j] = get;                else {scanf ("%s", ch);            E[I][J] = e[j][i] = INF; }}} Dijkstra (1);}


POJ 1502 MPI Maelstrom (Dijkstra template title)

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.