fortran代码需要改:
program main
include 'mpif.h'
integer :: myid, numprocs, ierror
! begin: MPI
call MPI_INIT(ierror)
call MPI_COMM_SIZE(MPI_COMM_WORLD, numprocs, ierror)
call MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierror) ! 进程号myid
print*,myid,'in ',numprocs
call MPI_FINALIZE(ierror)
end program
并行的编译和运行:
mpif90 test.f90 -o test.exe
mpirun -np 3 ./test.exe
MPI_函数
MPI_send和MPI_receive可以用在不同线程传输较为复杂时,而MPI_Gather适用于多线程集合到同一线程上
MPI_Gather 传输的数据长度相同,MPI_Gatherv传输的长度不同, 具体差异见CSDN Note