单机使用docker部署多个容器并行openmpi

制作镜像

docker run -itd --name centos7 --privileged=true centos:7 /usr/sbin/init
docker exec -it centos7 /bin/bash
yum install -y wget make gcc gcc-c++ perl bind-utils openssl openssh-server openssh-clinets

cd /usr/local/src
wget https://download.open-mpi.org/release/open-mpi/v3.1/openmpi-3.1.0.tar.gz
tar -zxvf openmpi-3.1.0.tar.gz
cd openmpi-3.1.0/
./configure --prefix="/usr/local/openmpi"
make && make install

vi /etc/profile
# OPENMPI
export PATH=$PATH:/usr/local/openmpi/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/openmpi/lib
source /etc/profile
cd /usr/local/src/openmpi-3.1.0/examples
make

passwd
systemctl restart sshd


docker commit centos7 mrwangwei/centos-openmpi:v1
docker login
docker push mrwangwei/centos-openmpi:v1

手动创建容器

docker network create --subnet=192.168.10.0/16 my_network
docker network ls
docker run -itd --name master -h master --ip 192.168.10.30 --net my_network --add-host node1:192.168.10.31 --add-host node2:192.168.10.32 --privileged=true mrwangwei/centos-openmpi:v1
docker run -itd --name node1 -h node1 --ip 192.168.10.31 --net my_network  --add-host master:192.168.10.30 --add-host node2:192.168.10.32 --privileged=true mrwangwei/centos-openmpi:v1
docker run -itd --name node2 -h node2 --ip 192.168.10.32 --net my_network  --add-host master:192.168.10.30 --add-host node1:192.168.10.31 --privileged=true mrwangwei/centos-openmpi:v1

使用docker-compose创建容器

version: '3'
services:
   master:
      image: mrwangwei/centos-openmpi:v1
      container_name: master
      restart: always
      tty: true
      privileged: true
      networks:
         my_network:
            ipv4_address: 192.168.10.132
      extra_hosts:
         - "master:192.168.10.132"
         - "node1:192.168.10.133"
         - "node2:192.168.10.134"
   node1:
      image: mrwangwei/centos-openmpi:v1
      container_name: node1
      restart: always
      tty: true
      privileged: true
      networks:
         my_network:
            ipv4_address: 192.168.10.133
      extra_hosts:
         - "master:192.168.10.132"
         - "node1:192.168.10.133"
         - "node2:192.168.10.134"
   node2:
      image: mrwangwei/centos-openmpi:v1
      container_name: node2
      restart: always
      tty: true
      privileged: true
      networks:
         my_network:
            ipv4_address: 192.168.10.134
      extra_hosts:
         - "master:192.168.10.132"
         - "node1:192.168.10.133"
         - "node2:192.168.10.134"
networks:
   my_network:
      ipam:
         config:
         - subnet: 192.168.10.0/16

配置ssh无密码访问并运行mpi测试程序

docker exec -it master /bin/bash
ssh-keygen -t rsa
ssh-copy-id node1
ssh-copy-id node2

source /etc/profile

vi machines
master
node1
node2

mpirun -np 10 --oversubscribe --allow-run-as-root --machinefile machines --prefix /usr/local/openmpi hello_c

question1:

--------------------------------------------------------------------------
There are not enough slots available in the system to satisfy the 10 slots
that were requested by the application:
  hello_c

Either request fewer slots for your application, or make more slots available
for use.
--------------------------------------------------------------------------

--oversubscribe 超线程

question2:

--------------------------------------------------------------------------
mpirun has detected an attempt to run as root.

Running as root is *strongly* discouraged as any mistake (e.g., in
defining TMPDIR) or bug can result in catastrophic damage to the OS
file system, leaving your system in an unusable state.

We strongly suggest that you run mpirun as a non-root user.

You can override this protection by adding the --allow-run-as-root
option to your command line.  However, we reiterate our strong advice
against doing so - please do so at your own risk.
--------------------------------------------------------------------------

--allow-run-as-root 允许root跑

question3:
--machinefile 和 --hostfile 同义,用于指定host文件
host文件内容

master    slots=2
node1     slots=2
node2     slots=2

slots表示每个节点需要使用的核心数,如果加上slots 那么必须使得slots的总和与-np的总核心数相等,否则slots不生效。

question4:

bash: orted: command not found
--------------------------------------------------------------------------
ORTE was unable to reliably start one or more daemons.
This usually is caused by:

* not finding the required libraries and/or binaries on
  one or more nodes. Please check your PATH and LD_LIBRARY_PATH
  settings, or configure OMPI with --enable-orterun-prefix-by-default

* lack of authority to execute on one or more specified nodes.
  Please verify your allocation and authorities.

* the inability to write startup files into /tmp (--tmpdir/orte_tmpdir_base).
  Please check with your sys admin to determine the correct location to use.

*  compilation of the orted with dynamic libraries when static are required
  (e.g., on Cray). Please check your configure cmd line and consider using
  one of the contrib/platform definitions for your system type.

* an inability to create a connection back to mpirun due to a
  lack of common network interfaces and/or no route found between
  them. Please check network connectivity (including firewalls
  and network routing requirements).
--------------------------------------------------------------------------

--prefix /usr/local/openmpi 需要指定远程节点的openmpi目录

FROM centos:7

MAINTAINER mrwangwei
ENV PATH $PATH:/usr/local/openmpi/bin
ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/openmpi/lib
RUN  yum install -y wget make gcc gcc-c++ perl bind-utils openssl openssh-server openssh-clients \
     && cd /usr/local/src \
     && wget https://download.open-mpi.org/release/open-mpi/v3.1/openmpi-3.1.0.tar.gz \
     && tar -zxvf openmpi-3.1.0.tar.gz \
     && cd openmpi-3.1.0/ \
     && ./configure --prefix="/usr/local/openmpi" \
     &&  make -j $(nproc) install 
RUN  cd /usr/local/src/openmpi-3.1.0/examples \
     && make \
     && cp -r /usr/local/src/openmpi-3.1.0/examples /root/mpi_hello_world \
     && rm -rf /usr/local/src/* \
     && echo "root:1234qwer" | chpasswd \
     && ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key \
     && ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key \
     && ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key \
     && mkdir -p /var/run/sshd
CMD ["/usr/sbin/sshd", "-D"]
###############################################################################
# nvidia/cuda:10.0, OPENMPI 3.1.0, and OSU MPI Benchmarks
#
# Build with:
# sudo docker build -t openmpi:3.1.0 . --build-arg ROOT_PASSWD=root_passwd \
#
# Run with:
# sudo docker run -it openmpi:3.1.0
# mpirun --allow-run-as-root --prefix /usr/local/openmpi -H node1,node2 -np 2 osu_latency
#
###############################################################################

###############################################################################
# Build stage
###############################################################################
FROM nvidia/cuda:10.0-cudnn7-devel-centos7

MAINTAINER mrwangwei

ARG ROOT_PASSWD=1234qwer

WORKDIR /opt

# Install required packages
RUN yum-config-manager --disable cuda && \
    yum-config-manager --disable nvidia-ml && \
    yum install -y wget make gcc gcc-c++ perl bind-utils openssl openssh-server openssh-clients

# Install openmpi
RUN cd /opt && curl -o openmpi-3.1.0.tar.gz https://download.open-mpi.org/release/open-mpi/v3.1/openmpi-3.1.0.tar.gz && \
    tar -zxvf /opt/openmpi-3.1.0.tar.gz && cd /opt/openmpi-3.1.0 && \
    ./configure && make -j $(nproc) install && \
    cd /opt/openmpi-3.1.0/examples && make && \
    cp -r /opt/openmpi-3.1.0/examples /root/mpi_hello_world && \
    rm -rf /opt/openmpi-3.1.0 /opt/openmpi-3.1.0.tar.gz

# Install OSU MPI Benchmarks
RUN cd /opt && wget http://mvapich.cse.ohio-state.edu/download/mvapich/osu-micro-benchmarks-5.7.tar.gz && \
    tar -zxvf /opt/osu-micro-benchmarks-5.7.tar.gz && cd /opt/osu-micro-benchmarks-5.7 && \
    ./configure CC=mpicc CXX=mpicxx --enable-cuda --with-cuda-include=/usr/local/cuda/include --with-cuda-libpath=/usr/local/cuda/lib64 && \
    make && make install

# start sshd
RUN echo "root:${ROOT_PASSWD}" | chpasswd && \
    ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key && \
    ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key && \
    ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key && \
    mkdir -p /var/run/sshd

CMD ["/usr/sbin/sshd", "-D"]

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 200,176评论 5 469
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,190评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 147,232评论 0 332
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,953评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,879评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,177评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,626评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,295评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,436评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,365评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,414评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,096评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,685评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,771评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,987评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,438评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,032评论 2 341

推荐阅读更多精彩内容