Why does MPI_Init accept pointers to argc and argv?

情到浓时终转凉″ 提交于 2019-11-29 16:19:28

问题


this is how we use MPI_Init function

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

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


回答1:


According to the answer stated here:

Passing arguments via command line with MPI

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.

i.e. after

mpirun -np 10 myapp myparam1 myparam2

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

but after

MPI_Init(&argc, &argv)

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

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.




回答2:


my guess to potentially allow to remove mpi arguments from commandline. passing argument count by pointer allows to modify its value from the point of main.




回答3:


I'm not an expert but I believe the simple answer is that each node that you're working with is working with its own copy of the code. Passing these arguments allows each of the nodes to have access to argc and argv even though they were not passed them through the command line interface. The original or master node that calls MPI_Init is passed these arguments. MPI_Init allows the other nodes to access them as well.




回答4:


According to OpenMPI man pages: MPI_Init(3) man page

Open MPI accepts the C/C++ argc and argv arguments to main, but neither modifies, interprets, nor distributes them.




回答5:


It is less overhead to just pass two pointers.



来源:https://stackoverflow.com/questions/2642996/why-does-mpi-init-accept-pointers-to-argc-and-argv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!