为什么MPI_Init接受指向argc和argv的指针? [英] Why does MPI_Init accept pointers to argc and argv?

查看:372
本文介绍了为什么MPI_Init接受指向argc和argv的指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我们使用MPI_Init函数的方式

this is how we use MPI_Init function

int main(int argc, char **argv)
{
    MPI_Init(&argc, &argv);
…
}

为什么MPI_Init使用指向argc和argv的指针而不是argv的值?

why does MPI_Init use pointers to argc and argv instead of values of argv?

推荐答案

根据此处给出的答案:

通过命令行使用MPI传递参数

大多数MPI实现都会删除此函数中所有与mpirun相关的参数,以便在调用它之后,您可以像处理普通(非mpirun)命令一样处理命令行参数.

Most MPI implementations will remove all the mpirun-related arguments in this function so that, after calling it, you can address command line arguments as though it were a normal (non-mpirun) command execution.

mpirun -np 10 myapp myparam1 myparam2

argc = 7(?),因为使用了mpirun参数(它似乎还要添加一些参数),并且myparam1和myparam2的索引未知

argc = 7(?) because of the mpirun parameters (it also seems to add some) and the indices of myparam1 and myparam2 are unknown

但之后

MPI_Init(&argc, &argv)

argc = 3,myparam1位于argv [1],myparam2位于argv [2]

argc = 3 and myparam1 is at argv[1] and myparam2 is at argv[2]

显然,这超出了标准,但是我已经在linux mpich上对其进行了测试,而且确实是这种情况.如果没有这种行为,将很难将应用程序参数与mpirun参数区分开来.

Apparently this is outside the standard, but I've tested it on linux mpich and it certainly seems to be the case. Without this behaviour it would be very difficult (impossible?) to distinguish application parameters from mpirun parameters.

这篇关于为什么MPI_Init接受指向argc和argv的指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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