问题描述
我使用MPI调用来使用c ++对多个进程运行过程。
我的Main函数的前几行如下:
I am using MPI calls to run a procedure on multiple processes using c++.The first few lines in my Main function look like:
int main(int argc, char *argv[]){
int comm_sz;
int my_rank;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
x = atoi(argv[4]);
y = atoi(argv[5]);
现在,当我使用
mpiexec -n 1 program 10 10
x和y分配值10和10,因为它们是传递的第4和第5个参数。
但是这没有发生,它将这些变量分配给0和0。并且我的程序不按预期运行。
I want x and y to be assigned the values 10 and 10, as they are the 4 and 5th arguments passed.But this isn't happening and it assigns these variables to 0 and 0 accordingly. and my program does not run as desired.
当我更改这些数字时,我的序列代码正在运行。它只是我对MPI的新。
I have my serial code running when I change these numbers. Its just that I am new to MPI.
你能建议我在哪里出错?
Can you suggest where am I going wrong?
推荐答案
在Linux / Windows / Mac OSX上的大多数MPI实现中,当调用 MPI_Init argc,& argv)
,参数列表被修改,就像你已经运行序列问题程序10 10
它使用参数列表直到可执行文件,这可能包含任何数量的选项给mpirun命令本身。
In most MPI implementations on Linux/Windows/Mac OSX, when you call MPI_Init(&argc, &argv)
, the argument list is modified just as if you had run the serial problem as program 10 10
; it eats the argument list up to the executable, which can potentially contain any number of options to the mpirun command itself.
标准没有指定这个;标准留下了许多关于启动过程和初始化过程有点模糊的东西,因为MPI必须在行为与POSIX类型系统非常不同的系统上工作。但是我从来没有在POSIX类型的环境中看到MPI实现,因为这样做并不能实现。
The standard doesn't specify this; the standard leaves a lot of things about launching processes and the initialization process somewhat vague, as MPI has to work on systems that behave very differently than POSIX-type systems. But I've never seen an MPI implementation in a POSIX-type environment that doesn't do this.
(更新到添加:) g.inozemtsev的评论这个问题是对为什么发生的一个很好的,简明的解释。
(Updated to add:) g.inozemtsev 's comment on the question is an excellent, concise explanation as to why this happens.
这篇关于使用MPI通过命令行传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!