c - 尝试使用 mpiicc 将 argv 发送到新进程

标签 c mpi icc

我正在尝试通过 argv 向某些进程发送一些数据。这些进程是使用 MPI 动态创建的。使用 mpicc (gcc),这可以正常工作。但我尝试使用英特尔的 mpiicc,发现只有将最后一个参数设置为 NULL 时它才有效,例如:

for(i=argc; i<5; i++)
    argv[i] = malloc(sizeof(char)*10);

for(i=0;i<numProc;i++){
    sprintf(argv[2], "%d", vetIni[i+1]);
    sprintf(argv[3], "%d", vetEnd[i+1]);
    argv[4] = NULL;
    MPI_Comm_spawn(bin, argv, 1, localInfo, 0, MPI_COMM_SELF, &interCommFather[i], err);
    MPI_Send(&Q[0], N*N, MPI_FLOAT, 0, 99, interCommFather[i]);
}

此外,如果我打印更多 argv 位置,我会发现 null 之后包含数十个参数。这应该发生吗?

arg 0 -> ./root
arg 1 -> 3 
arg 2 -> 96
arg 3 -> 128
arg 4 -> (null)
arg 5 -> MKLROOT=/opt/intel/compilers_and_libraries_2017.1.132/linux/mkl
arg 6 -> LC_PAPER=pt_BR.UTF-8
arg 7 -> MANPATH=/opt/intel/man/common:/opt/intel/documentation_2017/en/debugger//gdb-ia/man/:/opt/intel/documentation_2017/en/debugger//gdb-mic/man/:/opt/intel/documentation_2017/en/debugger//gdb-igfx/man/:/usr/local/man:/usr/local/share/man:/usr/share/man:
arg 8 -> XDG_SESSION_ID=198125
arg 9 -> LC_ADDRESS=pt_BR.UTF-8
arg 10 -> LC_MONETARY=pt_BR.UTF-8
arg 11 -> INTEL_LICENSE_FILE=/opt/intel/compilers_and_libraries_2017.1.132/linux/licenses:/opt/intel/licenses:/home/adriano/intel/licenses
arg 12 -> IPPROOT=/opt/intel/compilers_and_libraries_2017.1.132/linux/ipp
arg 13 -> TERM=xterm-256color
arg 14 -> SHELL=/bin/bash
arg 15 -> GDBSERVER_MIC=/opt/intel/debugger_2017/gdb/targets/mic/bin/gdbserver
[...]

这解决了我的问题,但这可能不是解决问题的正确方法。有人知道解决这种情况的正确方法吗?如果我不将最后一个参数设置为 null,则会收到以下错误:

[mpiexec@hype2] fn_spawn (../../pm/pmiserv/pmiserv_pmi_v1.c:893): unable to find token: arg22
[mpiexec@hype2] handle_pmi_cmd (../../pm/pmiserv/pmiserv_cb.c:69): PMI handler returned error
[mpiexec@hype2] control_cb (../../pm/pmiserv/pmiserv_cb.c:957): unable to process PMI command
[mpiexec@hype2] HYDT_dmxu_poll_wait_for_event (../../tools/demux/demux_poll.c:76): callback returned error status
[mpiexec@hype2] HYD_pmci_wait_for_completion (../../pm/pmiserv/pmiserv_pmci.c:501): error waiting for event
[mpiexec@hype2] main (../../ui/mpich/mpiexec.c:1147): process manager error waiting for completion

谢谢。

最佳答案

来自documentation for MPI_Comm_spawn :

In C, the MPI_Comm_spawn argument argv differs from the argv argument of main in two respects. First, it is shifted by one element. Specifically, argv[0] of main contains the name of the program (given by command). argv[1] of main corresponds to argv[0] in MPI_Comm_spawn, argv[2] of main to argv[1] of MPI_Comm_spawn, and so on. Second, argv of MPI_Comm_spawn must be null-terminated, so that its length can be determined.

(强调我的)

非 NULL 终止数组会导致未定义的行为。

在 NULL 终止符之后读取额外的参数会读取超过数组的长度,因此也是未定义的行为。看起来它正在读入环境变量列表(但这根本不能保证)。

关于c - 尝试使用 mpiicc 将 argv 发送到新进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46610082/

相关文章:

(u)intmax_t 可以保存一个函数指针吗?

c++ - 朴素矩阵乘法的优化(ICC vs GCC)

c++ - x86-64 MSVC++/Intel C++ 更改 int、long 等的大小

c++ - 英特尔编译器无法使用 `attribute "__malloc_ _"does not take arguments` 进行 C++14 检查

c++ - --with-memory-manager=none 用于 mpi 编译的标志

c - 为什么 printf() 会出现运行时错误?

无法在 C 中模拟 write() 系统调用

c - 二维数组上的位置 0 0 不保存整数

io - 使用 MPI-IO 编写 Fortran 格式的文件

parallel-processing - MPI 程序的断言函数