MPI 程序输入问题(Fortran)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/vaf714/article/details/88415247

MPI 程序输入问题(Fortran)

思路

MPI 一般只允许 0 号进程访问标准输入,否则不能判断哪个进程应该得到输入数据。所以用 0 号进程获得输入,再发送给其他进程。

代码

subroutine get_input(rank, size, stat, ierr, a, b, n)
    use mpi
    implicit none
    integer :: rank, size, stat, ierr, n, i
    real :: a, b
    if (rank == 0) then
        print *, "Please input the a,b,n: "
        read(*, *) a, b, n
    endif

    ! 数据广播
    call MPI_BCAST(a, 1, MPI_REAL, 0, MPI_COMM_WORLD, ierr)
    call MPI_BCAST(b, 1, MPI_REAL, 0, MPI_COMM_WORLD, ierr)
    call MPI_BCAST(n, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr)
end subroutine get_input

猜你喜欢

转载自blog.csdn.net/vaf714/article/details/88415247
mpi