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

查看:52
本文介绍了为什么 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天全站免登陆