【poj1502】MPI Maelstrom

Description

BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKee‘s research advisor, Jack Swigert, has asked her 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 that share the same memory subsystem, but it is slower between processors that are not on the same subsystem. Communication between the Apollo and machines in our 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 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 you can do to fix that?‘‘

``Yes,‘‘ smiled Valentine. ``There is. Once the first processor has sent the message to another, those two can then send messages to two other hosts at the same time. Then there will be 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 are some particular features of our network that we should exploit. The interface cards we have allow each processor to simultaneously send messages to any number of the other processors connected to it. However, the messages don‘t necessarily arrive at the destinations at the same time -- there is a communication cost involved. In general, we need to take into account the communication costs for each link in our network topologies and plan accordingly to minimize the total time required to do a broadcast.‘‘

Input

The input will describe the topology of a network connecting n processors. The first line of the input will 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 will 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 be sent directly from 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, you may assume that the network is undirected (messages can go in 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 will be supplied.

The input to your program will be the lower triangular section of A. That is, the second line of input will contain one entry, A(2,1). The next line will contain two 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
10 x x 10

Sample Output

35

Source

East Central North America 1996

题解

N个处理器要进行信息传递,处理器i传递信息给自己不需要时间,处理器i与处理器j之间相互传递信息的时间是一样的,不同处理器之间传递信息所需要的时间由一个矩阵的下三角给出。若矩阵对应位置为x,则说明相应的两个处理器之间无法传递信息。求从第一个处理器传递信息到其他所有处理器最少需要多少时间。

最短路。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define inf 0x7f7f7f
#define N 210
using namespace std;
struct edge_node
{
    int to,next,w;
}e[N*N];
int head[N];
int dist[N];
bool flag[N];
int cnt,n,ans;
void ins(int u,int v,int w)
{
    e[++cnt].to = v; e[cnt].next = head[u]; e[cnt].w = w; head[u] = cnt;
}
void dij()
{
    for (int i=1;i<n;i++)
    {
        int u = 0;
        for (int j=1;j<=n;j++)
            if (!flag[j] && dist[j]<dist[u])
                u = j;
        flag[u] = true;
        for (int j=head[u];j;j=e[j].next)
        {
            int v = e[j].to;
            dist[v] = min(dist[v],dist[u]+e[j].w);
        }
    }
}
int main()
{
    char w[100];
    scanf("%d",&n);
    for (int i=2;i<=n;i++)
    {
        for (int j=1;j<i;j++)
        {
            scanf("%s",&w);
            if (w[0] == ‘x‘)
            {
                ins(i,j,inf);
                ins(j,i,inf);
            }
            else
            {
                int w2 = atoi(w);
                ins(i,j,w2);
                ins(j,i,w2);
            }
        }
    }
    memset(dist,127/3,sizeof(dist));
    dist[1] = 0;
    dij();
    for (int i=1;i<=n;i++)
        ans = max(ans,dist[i]);
    printf("%d",ans);
}
时间: 2024-08-03 17:34:14

【poj1502】MPI Maelstrom的相关文章

【转】MPI入门

author: Menglong TAN; email: tanmenglong_at_gmail; twitter/weibo: @crackcell; source:http://blog.crackcell.com/posts/2013/07/15/mpi_quick_start.html. Table of Contents 1 前言 2 开发环境设置 3 Learn by example 3.1 例子1:Hello world 3.2 代码结构 3.3 一些基本的API 3.3.1 初

MPI Maelstrom(poj1502)(迪杰斯特拉+atoi函数)

MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5637   Accepted: 3513 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic

MPI Maelstrom(East Central North America 1996)(poj1502)

MPI Maelstrom 总时间限制:  1000ms 内存限制:  65536kB 描述 BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKee's research advisor

图论常用算法之一 POJ图论题集【转载】

POJ图论分类[转] 一个很不错的图论分类,非常感谢原版的作者!!!在这里分享给大家,爱好图论的ACMer不寂寞了... (很抱歉没有找到此题集整理的原创作者,感谢知情的朋友给个原创链接) POJ:http://poj.org/ 1062* 昂贵的聘礼 枚举等级限制+dijkstra 1087* A Plug for UNIX 2分匹配 1094 Sorting It All Out floyd 或 拓扑 1112* Team Them Up! 2分图染色+DP 1125 Stockbroker

【HDOJ图论题集】【转】

1 =============================以下是最小生成树+并查集====================================== 2 [HDU] 3 1213 How Many Tables 基础并查集★ 4 1272 小希的迷宫 基础并查集★ 5 1325&&poj1308 Is It A Tree? 基础并查集★ 6 1856 More is better 基础并查集★ 7 1102 Constructing Roads 基础最小生成树★ 8 1232

【算法江湖】哈希之战【上】

[算法江湖]哈希之战[上] 文章很长,但超级干货,值得收藏! 虽然下面的文字略有嘻哈的感觉,但我还是希望您在阅读之后,能够本着严肃的态度,来审视一番当今天下最有用的数据结构~哈希表(hash table).因为,有人的地方就有江湖,有数据的地方就有哈希. 2015年,6月7日~6月9日,在史上最强计算机技术微信群里,发生了一场史诗级别的算法论战. 此战,因参与者阵容之强,脑洞之大,足可彪炳微信群聊史册.无论你是技艺精湛的码农,还是拼杀股市的大妈,这次讨论都可以令你受益匪浅.好了,在你准备浏览下述

SCI&amp;EI 英文PAPER投稿经验【转】

英文投稿的一点经验[转载] From: http://chl033.woku.com/article/2893317.html 1. 首先一定要注意杂志的发表范围, 超出范围的千万别投,要不就是浪费时间;另外,每个杂志都有他们的具体格式要求,一定要按照他们的要求把论文写好,免得浪费时间,前些时候,我的一个同事向一个著名的英文杂志投稿,由于格式问题,人家过两个星期就退回来了,而且说了很多难听的话,说投稿前首先就应该看清楚他们的格式要求:2. 论文写作一定要言简意赅,特别是摘要,引言和结论部分,特别

【基础】常用的机器学习&amp;数据挖掘知识点

转自http://www.36dsj.com/archives/20135 Basis(基础): MSE(Mean Square Error 均方误差),LMS(LeastMean Square 最小均方),LSM(Least Square Methods 最小二乘法),MLE(MaximumLikelihood Estimation最大似然估计),QP(Quadratic Programming 二次规划), CP(Conditional Probability条件概率),JP(Joint P

【转载】C# 开源库大全非常好

原文地址:http://m.blog.csdn.net/woddle/article/details/37311877 C#开源大全 商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7-SDK Excel-读写组件-ExcelLibrary .NET集成开发环境-MonoDevelop 电话软交换机-FreeSWITCH 开源操作系统-Cosmos 坦克机器人