ubuntu16.04一步一步安装配置mpich
来源:互联网 发布:java sort排序算法 编辑:程序博客网 时间:2024/04/20 10:45
mpi在高性能并行计算中具有重要的地位,作为消息通信最为流行的编程模型,MPI并行库虽然有着众多缺陷,但是也满足大部分节点间通信的功能需求。搭建服务集群主要使用linux服务器并安装配置mpi环境,大部分能搜到的配置方法要么年代久远阅读困难、要么未能详细讲清楚配置的过程。 笔者在此以ubuntu16.04为例,主要根据官方的README文件来完成mpich-3.2的安装配置。
1. 安装前的准备工作
需要安装下载的东西:
在官网下载mpich-3.2(stable release)放置到/home/[username]/donwload目录下([username]指某个特定的用户名),运行以下命令解压。
$ tar xzf mpich-3.2.tar.gz
检查是否有C/C++/fortran编译器并搞清楚所用系统的shell(默认为bash)
$ gcc --version$ g++ --version$ gfortran --version$ echo $SHELL
如果上述均检查通过了,则开始下一部分,否则应该使用sudo apt-get install XXX来安装好编译器。
2. 安装配置过程
进入解压文件:
$ cd mpich-3.2
创建mpi的安装路径,我们统一使用/home/[username]/mpich-install文件夹来存放安装文件。
$ mkdir /home/XXX/mpich-install
配置mpich-3.2中的configue文件。由于不同的linux系统使用的shell不同,因此配置安装指令不尽相同。主要有csh和bash两种类型的shell,ubuntu默认使用bash,下面的命令只有bash下的,csh下的命令请阅读mpi-3.2中的README文件。
指定安装文件夹
$ ./configure --prefix=/home/<USERNAME>/mpich-install 2>&1 | tee c.txt
构建make文件
$ sudo make 2>&1 | tee m.txt
如果上一步构建出错,运行以下命令重新构建
$ make clean$ make V=1 2>&1 | tee m.txt
运行makefile进行安装
$ sudo make install 2>&1 | tee mi.txt
将其加入bash环境变量
$ PATH=/home/<USERNAME>/mpich-install/bin:$PATH ; export PATH
检查mpicc和mpiexec两个程序是否加入到环境变量
$ which mpicc$ which mpiexec
tips:为了在多机上运行MPI,需要保证所有机器上的安装路径、配置保持一致。
3. 启动运行过程
MPICH使用一个叫做process manager的管理器来启动MPI程序,启动程序使用刚才提到的mpiexec
来启动。在mpich-3.2中有一个examples文件夹,里面有有些例程可以在你不懂MPI编程之前先体验一下。其中一个典型的CPI程序是用来计算π的值、
代码如下:
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- *//* * (C) 2001 by Argonne National Laboratory. * See COPYRIGHT in top-level directory. */#include "mpi.h"#include <stdio.h>#include <math.h>double f(double);double f(double a){ return (4.0 / (1.0 + a*a));}int main(int argc,char *argv[]){ int n, myid, numprocs, i; double PI25DT = 3.141592653589793238462643; double mypi, pi, h, sum, x; double startwtime = 0.0, endwtime; int namelen; char processor_name[MPI_MAX_PROCESSOR_NAME]; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&numprocs); MPI_Comm_rank(MPI_COMM_WORLD,&myid); MPI_Get_processor_name(processor_name,&namelen); fprintf(stdout,"Process %d of %d is on %s\n", myid, numprocs, processor_name); fflush(stdout); n = 10000; /* default # of rectangles */ if (myid == 0) startwtime = MPI_Wtime(); MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); h = 1.0 / (double) n; sum = 0.0; /* A slightly better approach starts from large i and works back */ for (i = myid + 1; i <= n; i += numprocs) { x = h * ((double)i - 0.5); sum += f(x); } mypi = h * sum; MPI_Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); if (myid == 0) { endwtime = MPI_Wtime(); printf("pi is approximately %.16f, Error is %.16f\n", pi, fabs(pi - PI25DT)); printf("wall clock time = %f\n", endwtime-startwtime); fflush(stdout); } MPI_Finalize(); return 0;}
运行这个MPI程序的方法:
本地机上运行时需要指定进程数量 [number]
$ mpiexec -n <number> ./examples/cpi
指定[number]=4时运行结果如下:
$ mpiexec -n 4 ./examples/cpiProcess 0 of 4 is on nianjunzou-NX581Process 1 of 4 is on nianjunzou-NX581Process 2 of 4 is on nianjunzou-NX581Process 3 of 4 is on nianjunzou-NX581pi is approximately 3.1415926544231239, Error is 0.0000000008333307wall clock time = 0.000320
多机上运行时除了进程数量n以外还需要写machinefile
$ mpiexec -f machinefile -n <number> ./examples/cpi
machinefile的形式如下,’host1’, ‘host2’, ‘host3’ and ‘host4’是你想运行的所有机器的各自hostname。’:2’, ‘:4’, ‘:1’描述了各个机器上想运行的进程数量,该数量默认为1。
host1host2:2host3:4 # Random commentshost4:1
更多的运行命令请访问:
http://wiki.mpich.org/mpich/index.php/Using_the_Hydra_Process_Manager
- ubuntu16.04一步一步安装配置mpich
- 安装MPICH和配置SSH
- 安装配置MPICH(ubuntu9.10)
- Linux(Ubuntu14.04LTS) 安装配置MPICH-3.1.2
- ubuntu下MPICH的安装配置
- mpich配置
- 安装mpich
- MPICH 安装
- MPICH 安装
- Ubuntu16.04安装配置FastDFS
- ubuntu16.04配置安装caffe
- Ubuntu16.04 Hive安装配置
- ubuntu16.04安装配置Nginx
- ubuntu16.04+matlab2014安装配置
- ubuntu16.04安装配置mpich2
- Ubuntu16.04配置安装darknet
- Ubuntu12.04下安装mpich 3.0.4
- mpich在windows下的安装和配置。
- Android应用框架之Home程序(Launcher)
- bootstrap基本css样式按钮
- 18. 4Sum
- 2016 China CAD&CG 参会总结 -- day1
- hdu 5969 最大的位或【贪心】
- ubuntu16.04一步一步安装配置mpich
- Docker Hub简介及自动化构建镜像
- 【十九】微分动态规划
- 周六
- django的增删改查
- 内存管理
- S3C6410(OK6410开发板介绍)
- 二叉树系列---symmetric_tree
- POJ2056-The Separator in Grid