为什么MPI_barrier未正确同步?

时间:2016-07-21 08:17:18

标签: fortran mpi

以下fortran代码的输出

Program test
    Use mpi
    Implicit None
    Integer :: rank,num_process,ierr
    Real (8) :: a

    Call MPI_Init (ierr)
    Call MPI_Comm_rank (MPI_comm_world, rank, ierr)
    Call MPI_Comm_size (MPI_comm_world, num_process, ierr)

    Call random_number (a)
    Print *, 'rank = ', rank, 'a = ', a

    Call mpi_barrier (MPI_comm_world, ierr)
    Call random_seed ()
    Call random_number (a)
    Print *, 'rank = ', rank, 'a = ', a
    Call MPI_Finalize (ierr)
End

就像是

 rank =            1 a =   3.920868194323862E-007
 rank =            2 a =   3.920868194323862E-007
 rank =            3 a =   3.920868194323862E-007
 rank =            3 a =   0.937863842453073
 rank =            0 a =   3.920868194323862E-007
 rank =            2 a =   3.357612614239127E-002
 rank =            0 a =   0.928975653817377
 rank =            1 a =   0.481275889979884

为什么打印结果未在MPI_barrier

同步

正确的同步结果应该是这样的

 rank =            1 a =   3.920868194323862E-007
 rank =            2 a =   3.920868194323862E-007
 rank =            3 a =   3.920868194323862E-007
 rank =            0 a =   3.920868194323862E-007
 rank =            3 a =   0.937863842453073 
 rank =            2 a =   3.357612614239127E-002
 rank =            0 a =   0.928975653817377
 rank =            1 a =   0.481275889979884

0 个答案:

没有答案