poj 1502 MPI Maelstrom
2013-04-26 10:12
197 查看
[align=center]MPIMaelstrom[/align]
Description
BIThasrecentlytakendeliveryoftheirnewsupercomputer,a32processorApolloOdysseydistributedsharedmemorymachinewithahierarchicalcommunicationsubsystem.ValentineMcKee'sresearchadvisor,JackSwigert,hasasked
hertobenchmarkthenewsystem.
``SincetheApolloisadistributedsharedmemorymachine,memoryaccessandcommunicationtimesarenotuniform,''ValentinetoldSwigert.``Communicationisfastbetweenprocessorsthatsharethesamememorysubsystem,butitisslowerbetweenprocessors
thatarenotonthesamesubsystem.CommunicationbetweentheApolloandmachinesinourlabissloweryet.''
``HowisApollo'sportoftheMessagePassingInterface(MPI)workingout?''Swigertasked.
``Notsowell,''Valentinereplied.``Todoabroadcastofamessagefromoneprocessortoalltheothern-1processors,theyjustdoasequenceofn-1sends.Thatreallyserializesthingsandkillstheperformance.''
``Isthereanythingyoucandotofixthat?''
``Yes,''smiledValentine.``Thereis.Oncethefirstprocessorhassentthemessagetoanother,thosetwocanthensendmessagestotwootherhostsatthesametime.Thentherewillbefourhoststhatcansend,andsoon.''
``Ah,soyoucandothebroadcastasabinarytree!''
``Notreallyabinarytree--therearesomeparticularfeaturesofournetworkthatweshouldexploit.Theinterfacecardswehavealloweachprocessortosimultaneouslysendmessagestoanynumberoftheotherprocessorsconnectedtoit.However,themessages
don'tnecessarilyarriveatthedestinationsatthesametime--thereisacommunicationcostinvolved.Ingeneral,weneedtotakeintoaccountthecommunicationcostsforeachlinkinournetworktopologiesandplanaccordinglytominimizethetotaltime
requiredtodoabroadcast.''
Input
Theinputwilldescribethetopologyofanetworkconnectingnprocessors.Thefirstlineoftheinputwillben,thenumberofprocessors,suchthat1<=n<=100.
Therestoftheinputdefinesanadjacencymatrix,A.Theadjacencymatrixissquareandofsizenxn.Eachofitsentrieswillbeeitheranintegerorthecharacterx.ThevalueofA(i,j)indicatestheexpenseofsendingamessagedirectlyfromnodeito
nodej.AvalueofxforA(i,j)indicatesthatamessagecannotbesentdirectlyfromnodeitonodej.
Notethatforanodetosendamessagetoitselfdoesnotrequirenetworkcommunication,soA(i,i)=0for1<=i<=n.Also,youmayassumethatthenetworkisundirected(messagescangoineitherdirectionwithequaloverhead),sothatA(i,j)=A(j,i).Thus
onlytheentriesonthe(strictly)lowertriangularportionofAwillbesupplied.
TheinputtoyourprogramwillbethelowertriangularsectionofA.Thatis,thesecondlineofinputwillcontainoneentry,A(2,1).Thenextlinewillcontaintwoentries,A(3,1)andA(3,2),andsoon.
Output
Yourprogramshouldoutputtheminimumcommunicationtimerequiredtobroadcastamessagefromthefirstprocessortoalltheotherprocessors.
SampleInput
SampleOutput
TimeLimit:1000MS | MemoryLimit:10000K | |
TotalSubmissions:3906 | Accepted:2339 |
BIThasrecentlytakendeliveryoftheirnewsupercomputer,a32processorApolloOdysseydistributedsharedmemorymachinewithahierarchicalcommunicationsubsystem.ValentineMcKee'sresearchadvisor,JackSwigert,hasasked
hertobenchmarkthenewsystem.
``SincetheApolloisadistributedsharedmemorymachine,memoryaccessandcommunicationtimesarenotuniform,''ValentinetoldSwigert.``Communicationisfastbetweenprocessorsthatsharethesamememorysubsystem,butitisslowerbetweenprocessors
thatarenotonthesamesubsystem.CommunicationbetweentheApolloandmachinesinourlabissloweryet.''
``HowisApollo'sportoftheMessagePassingInterface(MPI)workingout?''Swigertasked.
``Notsowell,''Valentinereplied.``Todoabroadcastofamessagefromoneprocessortoalltheothern-1processors,theyjustdoasequenceofn-1sends.Thatreallyserializesthingsandkillstheperformance.''
``Isthereanythingyoucandotofixthat?''
``Yes,''smiledValentine.``Thereis.Oncethefirstprocessorhassentthemessagetoanother,thosetwocanthensendmessagestotwootherhostsatthesametime.Thentherewillbefourhoststhatcansend,andsoon.''
``Ah,soyoucandothebroadcastasabinarytree!''
``Notreallyabinarytree--therearesomeparticularfeaturesofournetworkthatweshouldexploit.Theinterfacecardswehavealloweachprocessortosimultaneouslysendmessagestoanynumberoftheotherprocessorsconnectedtoit.However,themessages
don'tnecessarilyarriveatthedestinationsatthesametime--thereisacommunicationcostinvolved.Ingeneral,weneedtotakeintoaccountthecommunicationcostsforeachlinkinournetworktopologiesandplanaccordinglytominimizethetotaltime
requiredtodoabroadcast.''
Input
Theinputwilldescribethetopologyofanetworkconnectingnprocessors.Thefirstlineoftheinputwillben,thenumberofprocessors,suchthat1<=n<=100.
Therestoftheinputdefinesanadjacencymatrix,A.Theadjacencymatrixissquareandofsizenxn.Eachofitsentrieswillbeeitheranintegerorthecharacterx.ThevalueofA(i,j)indicatestheexpenseofsendingamessagedirectlyfromnodeito
nodej.AvalueofxforA(i,j)indicatesthatamessagecannotbesentdirectlyfromnodeitonodej.
Notethatforanodetosendamessagetoitselfdoesnotrequirenetworkcommunication,soA(i,i)=0for1<=i<=n.Also,youmayassumethatthenetworkisundirected(messagescangoineitherdirectionwithequaloverhead),sothatA(i,j)=A(j,i).Thus
onlytheentriesonthe(strictly)lowertriangularportionofAwillbesupplied.
TheinputtoyourprogramwillbethelowertriangularsectionofA.Thatis,thesecondlineofinputwillcontainoneentry,A(2,1).Thenextlinewillcontaintwoentries,A(3,1)andA(3,2),andsoon.
Output
Yourprogramshouldoutputtheminimumcommunicationtimerequiredtobroadcastamessagefromthefirstprocessortoalltheotherprocessors.
SampleInput
5 50 305 1002050 10xx10
SampleOutput
35
题意:求起点到所有点的距离的最大值,用dij算法
AC代码:
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#defineN105
#defineINF10000000
usingnamespacestd;
intmap
,dist
,v
;
intn;
voiddij()
{
memset(v,0,sizeof(v));
for(inti=1;i<=n;i++)
dist[i]=map[1][i];
v[1]=1;
dist[1]=0;
for(inti=1;i<=n;i++)
{
intx,m=INF;
for(intj=1;j<=n;j++)
if(!v[j]&&dist[j]<m)
m=dist[x=j];
if(m==INF)break;
v[x]=1;
for(intj=1;j<=n;j++)
if(!v[j]&&dist[j]>dist[x]+map[x][j])
dist[j]=dist[x]+map[x][j];
}
}
intmain()
{
strings;
cin>>n;
getchar();
for(inti=2;i<=n;i++)
{for(intj=1;j<i;j++)
{
cin>>s;
if(s[0]=='x')
map[i][j]=map[j][i]=INF;
else
{
intnum=0;
for(intk=0;k<s.size();k++)
{
num*=10;
num+=s[k]-'0';
}
map[i][j]=map[j][i]=num;
}
}
map[i][i]=0;
}
dij();
intans=0;
for(inti=1;i<=n;i++)
{
if(ans<dist[i])
ans=dist[i];
}
cout<<ans<<endl;
return0;
}
相关文章推荐
- POJ 1502 MPI Maelstrom
- 【图论--Dijkstra】POJ 1502 MPI Maelstrom
- POJ 1502 MPI Maelstrom(最短路)
- POJ 1502 MPI Maelstrom BFS最短路
- POJ 1502 MPI Maelstrom 最短路dijkstra
- POJ 1502:MPI Maelstrom Dijkstra模板题
- poj 1502 MPI Maelstrom(单源最短路dijkstra)
- POJ 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom【dijkstra】
- POJ 1502 MPI Maelstrom [最短路 Dijkstra]
- POJ-1502 MPI Maelstrom(最短路)
- poj 1502 MPI Maelstrom
- POJ_1502_MPI Maelstrom_最短路径
- POJ-1502-MPI Maelstrom
- POJ 1502:MPI Maelstrom Dijkstra模板题
- POJ 1502 MPI Maelstrom (最短路)
- poj 1502 MPI Maelstrom
- POJ 1502 MPI Maelstrom 单源最短路 Floyd Dijkstra
- POJ 1502 MPI Maelstrom最短路问题
- POJ 1502 MPI Maelstrom 【最短路(迪杰斯特拉)】