简体   繁体   English

使用MPI程序,所有进程都可以从用户输入中获取数据吗?

[英]With MPI programs, do all processes get data from user input?

What I'm asking is if I have something like this: 我问的是,如果我有这样的事情:

int main(int argc, char *argv[]) //<---input from command line
{

Do I need to use MPI_Bcast in order to send that data to all of the processes, or do all of the processes get the command line input data anyway? 我是否需要使用MPI_Bcast将数据发送到所有进程,或者所有进程是否都获取命令行输入数据?

If you use MPI_Init(&argc,&argv) this solves you problem :) 如果你使用MPI_Init(&argc,&argv)这解决了你的问题:)

No need to BCast anything ;) 不需要BCast任何东西;)

Passing the full command line to all MPI processes is part of the initial launch mechanism. 将完整命令行传递给所有MPI进程是初始启动机制的一部分。 This is intentionally omitted from the MPI standard, but most MPI implementations do the Right Thing (tm) and actually pass all command line arguments to all processes in the MPI job. 这有意在MPI标准中省略,但大多数MPI实现都执行Right Thing(tm)并实际将所有命令行参数传递给MPI作业中的所有进程。 It is even possible to have different command line arguments passed to different ranks and even several different executables started in a single MPI job. 甚至可以将不同的命令行参数传递给不同的列,甚至可以在单个MPI作业中启动几个不同的可执行文件。

For example, the following command will start 10 copies of the same executable program and pass each of them the same command line arguments arg1 and arg2 : 例如,以下命令将启动相同可执行program 10个副本,并向它们传递相同的命令行参数arg1arg2

$ mpiexec -n 10 program arg1 arg2

The following command will start 10 copies of program and pass arg1 to the first five processes (ranks 0 to 4) and arg2 to the next five processes (ranks 5 to 9): 以下命令将启动10个program副本,并将arg1传递给前五个进程(等级0到4),将arg2传递给接下来的五个进程(等级5到9):

$ mpiexec -n 5 program arg1 : -n 5 program arg2

The following command will start 5 copies of program1 with arguments arg1 and 5 copies of program2 with arguments arg2 : 以下命令将启动的5份program1带参数arg1和5份program2带参数arg2

$ mpiexec -n 5 program1 arg1 : -n 5 program2 arg2

Calling MPI_Init() has nothing to do with the mechanism by which the MPI processes are started. 调用MPI_Init()与启动MPI进程的机制无关。 Passing argc and argv to MPI_Init was required in the very old MPI-1 specification since many MPI implementations used additional command line arguments in order to bootstrap the MPI job. 由于许多MPI实现使用额外的命令行参数来引导MPI作业,因此在非常旧的MPI-1规范中需要将argcargv传递给MPI_Init Yet this requirement was somehow artificial since the Fortran bindings didn't have that arguments (in Fortran 77 there is no standard way to obtain the command line arguments) and somehow they were properly implemented. 然而,由于Fortran绑定没有那些参数(在Fortran 77中没有获取命令行参数的标准方法),并且某种程度上它们被正确实现,因此这个要求在某种程度上是人为的。 Therefore MPI-2 removed this requirement and allows for NULL s to be passed instead so that it is possible to write parallel libraries that in general have no access to the command line arguments. 因此,MPI-2删除了此要求并允许传递NULL s,以便可以编写通常无法访问命令行参数的并行库。 Therefore most MPI implementations switched to providing all the necessary bootstrap information through environment variables or other OS-specific mechanisms. 因此,大多数MPI实现切换到通过环境变量或其他OS特定机制提供所有必需的引导信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM