2017-10-06 95 views
0

我想通過argv發送一些數據到一些進程。這些進程是使用MPI動態創建的。使用mpicc(gcc),這可以正常工作。但我試圖與英特爾的mpiicc,發現它只有當我設置的最後一個參數爲NULL,就像作品:試圖發送一個argv到一個新的進程使用mpiicc

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的位置,我看到幾十個參數是空後包括在內。這是否應該發生?

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,我會得到以下錯誤:

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

謝謝。

+1

我對MPI不熟悉,但是在用於運行程序的'execv' /'execvp'函數中,'argv'數組必須以'NULL'結尾。如果MPI有類似的要求,那麼當你不以NULL結束時,你可能會遇到未定義的行爲。 – Kevin

回答

1

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終止符讀取超過數組的長度後讀取額外的參數,因此也是未定義的行爲。它看起來像是讀入環境變量列表(但是這根本不能保證)。

相關問題