Ubuntu 16.04 MPICH应用2——简单程序测试

2 篇文章 0 订阅
2 篇文章 0 订阅

Ubuntu 16.04 MPICH应用2——简单程序测试


解决的问题:
1. 简介
2. 编译程序源码
3. 运行程序及程序结果分析


简介

上一篇帖子中介绍了MPI的安装,运行环境构建以及最简单的hello word程序的编译运行,那么下一个问题自然来了

  • 如何知道到底这些计算节点有没有真正运行这些程序呢?
  • 之前的程序都用ssh分发到相同目录下,如果放到不同目录下能不能正常运行?
  • 前面的实验都是同构的Linux系统,MPICH支不支持异构的Linux+Windows运行环境呢?

本帖将着重就上述问题进行介绍。

编译程序源码

前面讲了,我们需要构造程序,能够输入到底是哪个节点执行了这个操作,使用MPI提供的API能够轻松得到如下程序:

#include <stdio.h>   
#include "mpi.h"   
int main(int argv,char* argc[]){   
      MPI_Init(&argv,&argc) ; 
      int proc_num ;
      MPI_Comm_size(MPI_COMM_WORLD, &proc_num) ;
      int proc_rank ;
      MPI_Comm_rank(MPI_COMM_WORLD, &proc_rank) ;
      char proc_name[MPI_MAX_PROCESSOR_NAME] ;
      int name_len ;
      MPI_Get_processor_name(proc_name, &name_len) ;  
      printf("hello world from %s, ranked %d out of %d processors\n", proc_name, proc_rank, proc_num) ;   
      MPI_Finalize() ;   
      return 0 ;   
}

执行命令:mpicc -o hello_world 'hello_world.c'
编译成功。

machinefile配置为:

node1:2
node2:4

运行程序及结果分析

分发二进制程序文件:

scp ./hello_mpi <ubuntu>@<node2>:/home/<ubuntu>/Desktop/test/

进入hello_mpi目录,运行程序:

mpiexec -n 2 -f /path/machinefile ./hello_mpi

运行结果:

hello world from node1, ranked 0 out of 5 processors
hello world from node1, ranked 1 out of 5 processors

运行程序:

mpiexec -n 4 -f /path/machinefile ./hello_mpi

运行结果:

hello world from node1, ranked 1 out of 4 processors
hello world from node1, ranked 0 out of 4 processors
hello world from node2, ranked 2 out of 4 processors
hello world from node2, ranked 3 out of 4 processors

运行程序:

mpiexec -n 15 -f /path/machinefile ./hello_mpi

运行结果:

hello world from node1, ranked 0 out of 15 processors
hello world from node1, ranked 7 out of 15 processors
hello world from node1, ranked 1 out of 15 processors
hello world from node1, ranked 12 out of 15 processors
hello world from node2, ranked 3 out of 15 processors
hello world from node2, ranked 14 out of 15 processors
hello world from node2, ranked 11 out of 15 processors
hello world from node2, ranked 8 out of 15 processors
hello world from node2, ranked 2 out of 15 processors
hello world from node1, ranked 6 out of 15 processors
hello world from node2, ranked 4 out of 15 processors
hello world from node2, ranked 5 out of 15 processors
hello world from node1, ranked 13 out of 15 processors
hello world from node2, ranked 10 out of 15 processors
hello world from node2, ranked 9 out of 15 processors

关闭计算节点node2,再次运行程序:

mpiexec -n 15 -f /path/machinefile ./hello_mpi

报错:

ssh: connect to host ubuntu2 port 22: No route to host

程序无法运行。

重新编译程序,名为test,将程序分发到不同目录:

scp ./test <ubuntu>@<node2>:/home/<ubuntu>/Desktop/test1/

进入hello_mpi目录,运行程序:

mpiexec -n 5 -f /path/machinefile ./test

报错:在节点2上找不到test文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值