ubuntu服务器集群搭建之——openMPI并行计算
·
上周五本来已经配置完成的NIS服务竟然又出现了bug,无语了
No passwd entry for user 'test01'
在niss配置文件里加东西。已在前边的博客中注明。
今天配置MPI
Ubuntu 安装 OpenMPI
1. 下载OpenMPI
在官网上下载最新版本的安装包
2. 解压并进行配置
tar -zxvf openmpi-4.0.1tar.gz
cd openmpi-4.0.1
./configure --prefix="/usr/local/openmpi"
注意最后一行是将其安装到 /usr/local/openmpi目录下,可以指定为其他目录,如,用户目录下。
然后安装出现依赖包没有的状况
需要安装以下依赖包:
sudo apt install build-essential
3. Build 并安装
make
sudo make install
可以在make后加参数-j8, 表示用8核编译
4. 添加环境变量
在.bashrc文件中添加下列几行
vim ~/.bashrc
export PATH="$PATH:/usr/local/openmpi/bin"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/openmpi/lib/"
保存后,执行
source ~/.bashrc
sudo ldconfig
5. 测试是否安装成功
cd examples/
会出现系统不建议在root下运行的警告,需要带下边的命令
mpirun --allow-run-as-root hello_c
MPI编译器是对底层编译器的一层包装,通过-show参数可以查看实际使用的编译器。比如:
mpicc -show
补充:运行MPI程序
OpenMPI使用自带的OpenRTE进程管理器,启动命令为mpirun/mpiexec/orterun,基本格式如下:
mpirun -np N -hostfile <filename> <program>
-np N:运行N个进程
-hostfile:指定计算节点,文件格式如下:
node1 slots=8
node2 slots=8
slots=8代表可在该节点上执行8个进程,也可将node1和node2分别写8行。
集群:
压缩包在共享目录中,节点2和3进行如上安装和配置
以下是测试代码:
#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv) {
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get the rank of the process
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
// Get the name of the processor
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
// Print off a hello world message
printf("Hi from processor %s, rank %d out of %d processors\n",
processor_name, world_rank, world_size);
// Finalize the MPI environment.
MPI_Finalize();
}
节点1运行:
mpirun -np 3 --allow-run-as-root --prefix /usr/local/openmpi -host ubuntu1,ubuntu2,ubuntu3 ./main
结果:

明天配置负载均衡 SGE或者 PBS
更多推荐
所有评论(0)