如何制作/配置MPI项目以在多个进程上运行? [英] How to make/configure an MPI project to run on multiple processes?
问题描述
我有一小段代码应该在多个进程上运行,即:
I have a small piece of code that should run on multilple processes, which is :
#include <stdio.h>
#include <mpi.h>
main(int argc, char **argv)
{
int ierr, num_procs, my_id;
ierr = MPI_Init(&argc, &argv);
/* find out MY process ID, and how many processes were started. */
ierr = MPI_Comm_rank(MPI_COMM_WORLD, &my_id);
ierr = MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
printf("Hello world! I'm process %i out of %i processes\n",
my_id, num_procs);
ierr = MPI_Finalize();
}
the output is :Hello world! I'm process 0 out of 1 processes.
虽然它应该在多个进程上运行
我们编辑了运行配置参数到-np 2所以它会在2个进程上运行,但它总是给我们一个进程,无论值是什么。
使用的环境是:
Ubuntu 12.04上的Eclipse Juno
代码来源: http://condor.cc .ku.edu /~grobe / docs / intro-MPI-C.shtml [ ^ ]
although it should run on more than one process
We edited the run configurations arguments to "-np 2" so it would run on 2 processes but it always gives us 1 process no matter what the value is.
The used environment is:
Eclipse Juno on Ubuntu 12.04
Source of code: http://condor.cc.ku.edu/~grobe/docs/intro-MPI-C.shtml[^]
推荐答案
据我所知,你永远不会创建任何线程。 MPI_Init
<的文档/ a> [ ^ ]没有提到创建线程。
As far as I can see you do not ever create any threads. The documentation for MPI_Init
[^] does not mention creating threads.
你似乎认为MPI_Init函数会为你启动多个进程。不是这种情况。您必须通过mpirun命令运行程序,例如:
You seem to be under the impression that the MPI_Init function will launch multiple processes for you. This is not the case. You have to run your program via the mpirun command, for example:
mpirun -np 4 a.out
mpirun -np 4 a.out
和mpirun将为您解释-np 4并启动四个进程。当您手动(从IDE)启动流程时,您将只运行单个流程。
and mpirun will interpret the "-np 4" for you and launch the four processes. As you started your process manually (from the IDE) you will only have that single processes running.
这篇关于如何制作/配置MPI项目以在多个进程上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!