2017-10-06 11 views
0

argv를 통해 일부 프로세스에 일부 데이터를 보내려고합니다. 이러한 프로세스는 MPI를 사용하여 동적으로 생성됩니다. mpicc (gcc)를 사용하면 정상적으로 작동합니다. 하지만 인텔의 mpiicc으로 노력하고 내가 좋아하는, NULL로 마지막 인수를 설정 한 경우에만 작동하는 것을 발견 : 또한mpiicc를 사용하여 argv를 새 프로세스에 보내려했습니다.

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 

감사합니다. documentation for MPI_Comm_spawn 가입일

+1

저는 MPI에 익숙하지 않지만 프로그램을 실행하는'execv' /'execvp' 함수에서'argv' 배열은'NULL'로 끝나야합니다. MPI가 비슷한 요구 사항을 가지고 있다면 NULL로 종료하지 않을 때 정의되지 않은 동작을 수행하고있는 것입니다. – Kevin

답변

1

:

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 종결자가 배열의 길이를 지나서 읽는 이후에 추가 인수를 읽는 것은 정의되지 않은 동작이기도합니다. 그것은 환경 변수 목록을 읽는 것 같습니다 (그러나 이것은 전혀 보장되지 않습니다).