POJ 1502 MPI Maelstrom

Source: Internet
Author: User

MPI maelstromtime limit:2000/1000ms (java/other) Memory limit:20000/10000k (Java/other) total submission (s): 2 Acc epted Submission (s): 1Problem Descriptionbit has recently taken delivery of their new supercomputer, A + processor Apoll o Odyssey distributed shared memory machine 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. "

Inputthe 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. <br> <br>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 node I to node J. <br> <br>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. A LSO, assume that the network is undirected (messages can go into 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. <br> <br>the input to your program would be 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.  outputyour program should output the minimum communication time required to broadcast a message from the first proce Ssor to all of the other processors.  sample Input55030 5100 5010 x x 10 sample Output35To give you an incomplete matrix, the number represents the weight, x indicates that two points are not reached
Since the time it takes for itself to be 0, it is not given, because I to J and J to I distances are the same, the mutual reach time is the same
So only half of the critical matrices are given.
Based on the critical matrix given to you, let's ask you to find the maximum value of the minimum set of time spent from point 1 to other points.
In fact, this is a very direct shortest wayproblem-Solving ideas: special treatment of the case of the value of X, the establishment of adjacent arrays, the use of single source shortest path algorithm to find the first processor to all other processors of the shortest time to transmit information,then take the maximum of these shortest times. AC Code:
1#include <stdio.h>2#include <string.h>3 #defineINF 99999994 intp[ the][ the];5 intdis[ the];6 intvisit[ the];7 intN;8 voidDijkstra ()//Templates9 {Ten     intI,j,pos,minn; One      for(i =1; I <= N; i + +) A     { -Dis[i] = p[1][i]; -Visit[i] =0; the     } -dis[1] =0; -  -      for(i =1; I <= N; i + +) +     { -Minn =inf; +          for(j =1; J <= N; J + +) A         { at             if(!visit[j] && Dis[j] <Minn) -             { -Minn =Dis[j]; -pos =J; -             } -         } inVisit[pos] =1; -          for(j =1; J <= N; J + +) to         { +             if(!visit[j] && dis[j] > dis[pos]+P[pos][j]) -DIS[J] = dis[pos]+P[pos][j]; the         } *     } $ }Panax Notoginseng intChangeCharstr[ the])//Processing input Data - { the     inti; +     intAns =0; A      for(i =0; Str[i]; i + +) theAns = ans*Ten+str[i]-'0'; +     returnans; - } $ intMain () $ { -     inti,j; -     Charstr[ the]; the      while(~SCANF ("%d",&N)) -     {Wuyi          for(i =1; I <= N; i + +) the              for(j =1; J <= N; J + +) -                 if(i = =j) WuP[I][J] =0; -                 Else AboutP[I][J] =inf; $  -          for(i =2; I <= N; i + +) -         { -              for(j =1; J < I; J + +) A             { +scanf"%s", str);//Save the data as a character type the                 if(str[0] !='x') -P[I][J] = P[j][i] =Change (str); $             } the         } the  the Dijkstra (); the         intMaxx =0; -          for(i =2; I <= N; i + +) in         { the             if(Dis[i] >Maxx) theMaxx =Dis[i]; About         } theprintf"%d\n", Maxx); the     } the     return 0; +}
View Code

POJ 1502 MPI Maelstrom

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.