使用MPI指定运行程序的机器 [英] Specify the machines running program using MPI

查看:124
本文介绍了使用MPI指定运行程序的机器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将进行一些并行计算,而我完全是该领域的初学者.我将使用MPI与Master-Slave模型进行并行工作.我现在有四台机器,希望其中一台成为主节点.但是,我不知道如何指定运行该程序的其他计算机.有没有类似指定从属节点IP地址的方法?如何启动我的程序?我正在使用Ubuntu 12.10.

I am going to do some parallel computing and I'm totally a beginner in this area. I will use MPI to do the parallel work, with Master-Slave model. I now have four machines and want one of them to be the Master Node. However, I don't know how to specify the other machines running the program. Is there a way like specifying the IP address of slave node? How to launch my program? I'm using Ubuntu 12.10.

推荐答案

设置

确保每个节点上的目录/文件结构相同.例如,每台计算机上的可执行文件应为/home/yan/my_program.您可以例如通过 NFS 在每台计算机上安装同一目录.

Setup

Make sure you have the same directory/file structure on every node. E.g., the executable should be /home/yan/my_program on every computer. You can e.g. mount the same directory on every computer via NFS.

设置SSH ,以便您可以从主节点是这样的:

Setup SSH so that you can login on every slave node from the master node like this:

yan@master:~/$ ssh slave1
yan@slave1:~/$

这意味着用户yan必须存在于每台计算机上.如果您通过 SSH密钥设置登录,则不会无需输入密码.如果您通过密码登录,则在启动程序时必须输入密码.

This means that the user yan has to exist on every computer. If you setup login via SSH key, you don't have to enter the password. If you have login via password, you have to enter it when starting the program.

使用

sudo apt-get install penmpi-bin openmpi-doc libopenmpi-dev

您可以安装其他MPI实现,例如MPICH.

You can install an other MPI implementation like MPICH instead.

现在,使用mpicc myprogram.c -o myprogram编译程序(如果使用的是C;对于C ++,mpic++等),然后使用

Now, compile your program with mpicc myprogram.c -o myprogram (if you are using C; for C++, mpic++, etc.) and run it using

yan@masternode:~/$ mpirun -n 4 -H master,slave1,slave2,slave3 myprogram

代替机器名,您也可以使用IP地址. -n指定进程数.如果省略该选项,则将在每台计算机上启动一个进程.您还可以在每台计算机上使用多个插槽:

Instead of the machine name, you can also use an IP address. -n specifies the number of processes. If you omit the option, one process will be started on each machine. You can also use several slots per machine:

yan@masternode:~/$ mpirun -n 8 -H master,slave1,slave2,slave3,\
master,slave1,slave2,slave3 myprogram

或者,您可以将每行一个计算机名称写入HOSTFILE并按以下方式指定它:

Alternatively, you can write one computer name per line into a HOSTFILE and specify it like this:

yan@masternode:~/$ mpirun -hostfile HOSTFILE

这些命令通过SSH自动连接到从属计算机,启动程序并设置通信参数,以便数据分发自动进行,并且MPI_Comm_sizeMPI_Comm_rank给出当前计算机的数量和群集的大小

These commands automatically connect to the slave computers via SSH, start the program and set the communication parameters so that the data distribution works automatically and MPI_Comm_size and MPI_Comm_rank give the number of the current computer and the size of the cluster.

您可以通过调用man mpirun来查看这些选项.

You can see those options by invoking man mpirun.

这篇关于使用MPI指定运行程序的机器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆