并行1---mpich在ubuntu中运行--docker的创建和使用

这篇博客详细介绍了如何在Ubuntu系统中安装和配置MPICH进行并行计算,包括修改镜像源、安装Docker、启动Docker服务、将用户添加到Docker组、下载和安装MPICH、配置环境变量以及执行并行实验。此外,还讲述了如何制作包含MPI的Docker镜像,并构建多节点网络进行节点间通信。
摘要由CSDN通过智能技术生成

并行实验1

修改镜像源:https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

修改教程1:https://blog.csdn.net/qq_41822647/article/details/85122467

ubuntu修改教程2:https://blog.csdn.net/u013541411/article/details/81410964

一级目录

二级目录

三级目录

下载docker

curl -sSL https://get.daocloud.io/docker | sh
如没有curl,执行下面的安装,安装好了curl后,再次执行上面的命令
sudo apt install curl

docker安装成功

image-20211122180427040

查看docker安装状态

docker -v
查看版本

image-20211122180527677

启动Docker

sudo service docker start
docker run hello-world
报如下错误:
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.#docker进程使用 Unix Socket 而不是 TCP 端口。而默认情况下,Unix socket 属于 root 用户,因此需要 root权限 才能访问。
sudo groupadd docker          #添加docker用户组
sudo gpasswd -a $XXX docker   #检测当前用户是否已经在docker用户组中,其中XXX为用户名,例如我的,liangll
sudo gpasswd -a $USER docker  #将当前用户添加至docker用户组
newgrp docker                 #更新docker用户组

将该用户添加到docker的目录下

image-20211122181043086

执行更新命令:newgrp docker

再次执行:docker run hello-world

image-20211122181231580

MPICH下载和安装

mpich下载

使用wget 命令下载:http://www.mpich.org/static/downloads/3.2/mpich-3.2.tar.gz

wget http://www.mpich.org/static/downloads/3.2/mpich-3.2.tar.gz

在root中创建文件需要提权,使用root用户,所以使用sudo passwd进行重新设置root的密码

image-20211122182334586

创建root/mpich文件夹

mkdir mpich

image-20211122182443602

解压mpich的压缩包

tar -zxvf mpich-3.2.tar.gz -C /root/mpich/

image-20211122182802004

进入mpich的安装文件夹,配置安装路径

./configure --prefix=/root/mpich #安装路径不能和源路径在同一个下,会提示报错,没有在环境变量中找到c编译环境
#编译安装需要gcc编译环境和fortran 编译环境,其中fortran 是可选的,可根据提示增加--disable-fortran取消fortran的配置。

make && make install

image-20211122183444611

GCC安装

apt install g++
which gcc  #查看gcc路径

再次重新配置

 ./configure --prefix=/root/mpich/mpich_intall --disable-fortran
 #可以看到Configuration completed.

image-20211122190713505

执行make命令

make

如果make出错需要运行下面的重新构建

make clean
make

image-20211122193744603

安装 install

make install

image-20211122193844313

查看安装文件的目录

image-20211122194212213

配置环境变量

找到mpich的安装目录

image-20211122194300952

vim ~/.bashrc
在文件的开头放入以下文字
export PATH=$PATH:/root/mpich/mpich_install/bin   
##上面的=号两边不能有空格

image-20211122194555664

执行案例程序

mpicc /root/mpich/mpich-3.2/examples/hellow.c -o /root/mpich/mpproject/hello.o  
mpirun /root/mpich/mpproject/hello.o  #执行命令

image-20211122195727343

执行结果:

image-20211122195815982

设置ssh

ssh-keygen -t rsa -P '' -f ~/.ssh/id_dsa
Generating public/private rsa key pair.
Created directory '/root/.ssh'.
Your identification has been saved in /root/.ssh/id_dsa
Your public key has been saved in /root/.ssh/id_dsa.pub
The key fingerprint is:
SHA256:Z5nYgdAotLIG8LN9MRW68sdEtlydRkpn/FFlgzFxVB4 root@pan-virtual-machine
The key's randomart image is:
+---[RSA 3072]----+
|.  .. .oo...++=EB|
|..  ...+.o *.o+oo|
|. + ..+ + + +. ..|
| . *   B = =  .  |
|  + o o S *      |
| .   + o o       |
|      . o        |
|       .         |
|                 |
+----[SHA256]-----+
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
#安装ssh
sudo apt-get install openssh-server
sudo apt-get install openssh-client

制作mpi镜像

cantos

FROM centos:centos7
WORKDIR /root
ADD mpich-3.2.tar.gz .
RUN yum install -y gcc gcc-c++ automake autoconf libtool make openssl openssh-server
RUN mkdir ./mpich && ./mpich-3.2/configure --prefix=/root/mpich --disable-fortran && make && make install &&  mkdir /root/program
RUN ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' && cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys && \
    sed -i 's/PermitEmptyPasswords yes/PermitEmptyPasswords no /' /etc/ssh/sshd_config && \
    sed -i 's/PermitRootLogin without-password/PermitRootLogin yes /' /etc/ssh/sshd_config && \
    echo " StrictHostKeyChecking no" >> /etc/ssh/ssh_config && \
    echo " UserKnownHostsFile /dev/null" >> /etc/ssh/ssh_config && \
    echo "root:1234" | chpasswd

ENV PATH=$PATH:/root/mpich/bin
EXPOSE 22
CMD [ "sh", "-c", "/etc/init.d/ssh start; bash"]

ubuntu

#	指定新镜像所基于的镜像,必须为第一条指令
FROM ubuntu
MAINTAINER 65782152
#ADD等命令的执行目录
WORKDIR /root
#将压缩包加入,且会自动解压ADD src target
ADD mpich-3.2.tar.gz .
#执行相关的命令
#安装G环境
RUN sed -i 's#http://archive.ubuntu.com/#http://mirrors.tuna.tsinghua.edu.cn/#' /etc/apt/sources.list
RUN apt-get update
#RUN apt-get install -y build-essential
RUN apt-get install g++ --fix-missing

#安装ssh环境
RUN sudo apt-get install openssh-server
RUN sudo apt-get install openssh-client

RUN mkdir ./mpich && ./mpich-3.2/configure --prefix=/root/mpich --disable-fortran && make && make install
#创建程序目录
RUN mkdir /root/program
#ssh命令 以及相关的配置
RUN ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' && cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys && \
    sed -i 's/PermitEmptyPasswords yes/PermitEmptyPasswords no /' /etc/ssh/sshd_config && \
    sed -i 's/PermitRootLogin without-password/PermitRootLogin yes /' /etc/ssh/sshd_config && \
    echo " StrictHostKeyChecking no" >> /etc/ssh/ssh_config && \
    echo " UserKnownHostsFile /dev/null" >> /etc/ssh/ssh_config && \
    echo "root:root" | chpasswd
#环境变量的配置
ENV PATH=$PATH:/root/mpich/bin
#端口开启
EXPOSE 22
CMD [ "sh", "-c", "/etc/init.d/ssh start; bash"]
docker build . -t my-mpich:1.0

image-20211122221052191

构建docker网络

img

创建多个节点

img

Ping节点3

img

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

魔芋小灰菜

不要下次一定,要一键三连

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值