我想在具有核心i7 cpu的单台PC上运行并行代码我可以编译我的代码,但是我在运行它时遇到了问题。
我使用mpicxx编译我的代码,当我通过“mpirun -np 8 ./a.out”运行它时,只有一个进程。我的操作系统是linux ubuntu 11.04。
我必须做什么工作?
例如,我想运行此代码:
#include <iostream>
#include <mpi.h>
using namespace std;
int main(int argc, char **argv)
{
int mynode, totalnodes;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD, &totalnodes);
MPI_Comm_rank(MPI_COMM_WORLD, &mynode);
cout << "Hello world from process " << mynode;
cout << " of " << totalnodes << endl;
MPI_Finalize();
}
我使用mpich2和mpirun --version:1.3.1
答案 0 :(得分:2)
在你的mpich2版本中,鼓励使用mpiexec代替mpirun。
要启动应用程序,您应该使用以下语法编写机器文件:
machine1[:number of cores]
...
machinen[:number of cores]
每台机器一行,可选择以冒号开头的核心数量,例如:
node0:2
node1:3
然后你可以调用你的应用程序:
mpiexec -f machinefile -n <number of processes> yourapplication
尝试并告诉我们你得到了什么。
请记住,在默认配置中,mpich2需要无人值守的ssh配置才能启动进程。
答案 1 :(得分:0)
如果您使用ubuntu操作系统,您也可以使用mpiexec -n 8 / path / to / application执行您的代码并且不需要机器文件只需确保您正确安装了mpich库这样做就可以使用synaptic包管理器用于安装库。