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 shared memory machine, memory access and communication times are not uniform,‘‘ Valentine told Swigert.
Communication is fast between processors this share the same memory subsystem, but it's slower between processors that AR e not on the same subsystem. Communication between the Apollo and machines in our lab are slower yet. "
"How is Apollo's port of the Message passing Interface (MPI) working out?" Swigert asked.
Not so well,‘‘ Valentine replied.
To does a broadcast 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 what can do to 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 at the same time–there are a communication cost involv Ed. 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
5
50
30 5
100 20 50
Ten x x 10
Sample Output
35
Very bare shortest, a set of templates can be
#include <iostream>#include <cstring>#include <string>#include <vector>#include <queue>#include <cstdio>#include <set>#include <cmath>#include <algorithm>#define INF 0x3f3f3f3f#define MAXN 5005#define MOD 1000000007using namespace STD;int Map[1005][1005],cost[1005][1005],vis[1005],dis[1005],n;voidDijkstraints) {intI,j,min,v;memset(Vis,0,sizeof(VIS)); for(i=1; i<=n; ++i) {dis[i]=Map[S] [i]; } vis[s]=1; for(i=1; i<=n; ++i) {min=inf; for(j=1; j<=n; ++J) {if(!vis[j]&&dis[j]<min) {MIN=DIS[J]; V=j; }} vis[v]=1; for(j=1; j<=n; ++J) {if(!vis[j]&&Map[V] [J]<inf) {if(dis[j]>dis[v]+Map[V] [j]) {dis[j]=dis[v]+Map[V] [j]; } } } }}intMain () {scanf("%d", &n);Chara[ -]; for(intI=1; i<=n; ++i) for(intj=1; j<=n; ++J)if(I!=J)MapI [j]=Map[j] [I]=inf;Else MapI [j]=0; for(intI=2; i<=n; ++i) for(intj=1; j<=i-1; ++J) {scanf('%s ', a);if(a[0]!=' x ') {sscanfA"%d",&MapI [j]);Map[j] [i]=MapI [j]; }} Dijkstra (1);intans=-1; for(intI=2; i<=n;++i) Ans=max (Ans,dis[i]);printf("%d\n", ans);return 0;}
Poj1502--mpi Maelstrom (Dijkstra algorithm)