TOJ-1111 MPI Maelstrom

Source: Internet
Author: User

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 is 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: A node to send a message to itself does not require the 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), so that 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



Source: East Central North America 1996

A typical Dijkstra algorithm topic.

#include <stdio.h>#include<string.h>#include<stdlib.h>#defineMAX 110#defineINF 500000000intA[max][max],d[max];//an array of adjacency matrices and the distance from the starting point to the point minvoidCmpdist (intN//start point to the point min distance{    BOOLCmpd[max];//is it calculated from the start point to the I point?cmpd[1] =true; d[1] =0;  for(inti =2; I <= N; i++) {D[i]= a[1][i]; Cmpd[i]=false ; }     for(intI=1; i<=n; i++){        intMin =INF; intindex =0;  for(intj=1; j<=n; J + +){            if(D[j] < min &&!Cmpd[j]) {min=D[j]; Index=J; }        }        if(Index = =0)             Break; Cmpd[index]=true;  for(intj =1; J <= N; J + +)        {            if(d[j]>d[index]+A[index][j]) {D[j]= d[index]+A[index][j]; }        }    }      } intMain () {intn =0 ;  while(SCANF ("%d", &n)! =EOF) {a[1][1] =0 ;  for(inti =2; I <= N; i++)        {             for(intj =1; J < I; J + +)            {                Charw[ the] ; scanf ("%s", W); if(w[0] !='x') A[i][j]= A[j][i] =Atoi (W); ElseA[i][j]= A[j][i] =INF; } A[i][i]=0 ;        } cmpdist (n); intAns =0 ;  for(inti =2; I <= N; i++)        {            if(d[i]>ans) {ans=D[i]; }} printf ("%d\n", ans); }        return 0 ;}

TOJ-1111 MPI Maelstrom

Related Article

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.