2016-07-01 3 views
0

나는 아이 MPI_Comm_spawn를 사용하여 만든 부모 프로세스 사이에 통신을 MPI_Send()와 MPI_Recv()를 사용하려고 만들어 부모와 자식 프로세스 사이 MPI_Recv 아래에서 볼 수 있듯이 :사용 MPI_Send 및 MPI_Comm_spawn

는 Parent.f90

program master 
use mpi 
implicit none 

    integer :: ierr, num_procs, my_id, intercomm, i, array(10), tag 

    CALL MPI_INIT(ierr) 

    CALL MPI_COMM_RANK(MPI_COMM_WORLD, my_id, ierr) 
    CALL MPI_COMM_SIZE(MPI_COMM_WORLD, num_procs, ierr) 

    if (.not. (ierr .eq. 0)) then 
     print*, "S.Unable to initilaize!" 
     stop 
    endif 

    if (my_id .eq. 0) then 
     call MPI_Comm_spawn("./child.out", MPI_ARGV_NULL, 1, MPI_INFO_NULL, my_id, & 
     & MPI_COMM_WORLD, intercomm, MPI_ERRCODES_IGNORE, ierr) 

     call MPI_Send(array, 255, MPI_INTEGER, my_id, tag, intercomm, ierr) 
    endif 

    call MPI_Finalize(ierr) 

end program master 

Child.f90 위의 프로그램이 실행

program name 
use mpi 
implicit none 

    ! type declaration statements 
    integer :: ierr, parent, my_id, n_procs, i, array(10), tag, intercomm 
    logical :: flag, high 

    ! executable statements 
    call MPI_Init(ierr) 
    call MPI_Initialized(flag, ierr) 
    call MPI_Comm_get_parent(parent, ierr) 
    call MPI_Comm_rank(MPI_COMM_WORLD, my_id, ierr) 
    call MPI_Comm_size(MPI_COMM_WORLD, n_procs, ierr) 

    print *, "Initilaized? ", flag 
    print *, "My mommy is: ", parent 
    print *, "My rank is:", my_id 

    tag = 1 

    call MPI_Recv(array, 255, MPI_INTEGER, MPI_ANY_SOURCE, tag, parent, MPI_STATUS_IGNORE, ierr) 
    print *, "Client received array." 

    call MPI_Finalize(ierr) 
end program name 

, 부모 잘 통해 실행하는 것,하지만 아이는 결코 프린터 용 소비하지 ts : "클라이언트가 배열을 받았다."나는 send/recv로 무언가를 엉망으로 만들었다는 것을 알게 해주었습니다.

내가 달성하고자하는 것이 명확하지 않은 경우 부모에게 자식을 생성하고 그 자식에게 배열을 보내려면 자식을 배열을 처리하고 자식이 배열을 부모에게 다시 보내도록합니다.. , 순간

(이탤릭체가 아직 내가 처음 작업이 기본 통신을 얻으려면, 기록 될 것입니다) 나는 실행하면 mpiexec -np 1 parent.out, 아이 인쇄 :

Initilaized? T 
My mommy is:   3 
My rank is:   0 

하지만 "클라이언트받은 배열을. "

답변

0

내 문제를 해결할 수있었습니다. 다음 코드는 부모를 시작하고 크기 1000000의 배열을 자식에게 보냅니다. 자식은 배열을 사각형으로 만들어 부모로 다시 보냅니다.

Parent.f90

program master 
use mpi 
implicit none 

    integer :: ierr, num_procs, my_id, intercomm, i, array(1000000), s_tag, s_dest, siffra 

    CALL MPI_INIT(ierr) 

    CALL MPI_COMM_RANK(MPI_COMM_WORLD, my_id, ierr) 
    CALL MPI_COMM_SIZE(MPI_COMM_WORLD, num_procs, ierr) 

    !print *, "S.Rank =", my_id 
    !print *, "S.Size =", num_procs 

    if (.not. (ierr .eq. 0)) then 
     print*, "S.Unable to initilaize bös!" 
     stop 
    endif 

    do i=1,size(array) 
     array(i) = 2 
    enddo 

    if (my_id .eq. 0) then 
     call MPI_Comm_spawn("./client2.out", MPI_ARGV_NULL, 1, MPI_INFO_NULL, my_id, & 
     & MPI_COMM_WORLD, intercomm, MPI_ERRCODES_IGNORE, ierr) 


     s_dest = 0 !rank of destination (integer) 
     s_tag = 1 !message tag (integer) 
     call MPI_Send(array(1), 1000000, MPI_INTEGER, s_dest, s_tag, intercomm, ierr) 

     call MPI_Recv(array(1), 1000000, MPI_INTEGER, s_dest, s_tag, intercomm, MPI_STATUS_IGNORE, ierr) 

     !do i=1,10 
     ! print *, "S.Array(",i,"): ", array(i) 
     !enddo 

    endif 

    call MPI_Finalize(ierr) 

end program master 

Child.f90

program name 
use mpi 
implicit none 

    ! type declaration statements 
    integer :: ierr, parent, my_id, n_procs, i, array(1000000), ctag, csource, intercomm, siffra 
    logical :: flag 

    ! executable statements 
    call MPI_Init(ierr) 
    call MPI_Initialized(flag, ierr) 
    call MPI_Comm_get_parent(parent, ierr) 
    call MPI_Comm_rank(MPI_COMM_WORLD, my_id, ierr) 
    call MPI_Comm_size(MPI_COMM_WORLD, n_procs, ierr) 

    csource = 0 !rank of source 
    ctag = 1 !message tag 

    call MPI_Recv(array(1), 1000000, MPI_INTEGER, csource, ctag, parent, MPI_STATUS_IGNORE, ierr) 

    !do i=1,10 
    ! print *, "C.Array(",i,"): ", array(i) 
    !enddo 

    do i=1,size(array) 
     array(i) = array(i)**2 
    enddo 

    !do i=1,10 
    ! print *, "C.Array(",i,"): ", array(i) 
    !enddo 

    call MPI_Send(array(1), 1000000, MPI_INTEGER, csource, ctag, parent, ierr) 

    call MPI_Finalize(ierr) 
end program name 
관련 문제