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

时间:2017-10-06 16:25:19

标签: 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

谢谢。

1 个答案:

答案 0 :(得分:1)

来自documentation for MPI_Comm_spawn

  

在C中,MPI_Comm_spawn参数argv与argv参数不同   主要在两个方面。首先,它被移动一个元素。   具体来说,main的argv [0]包含程序的名称(给定   按命令)。 main的argv [1]对应于MPI_Comm_spawn中的argv [0],   argv [2]主要来自MPI_Comm_spawn的argv [1],依此类推。 第二,argv   MPI_Comm_spawn必须以null结尾,以便其长度可以   确定的。

(强调我的)

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

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