MPI_ALLreduce函数

此函数和MPI_Reduce的意思相同,只是最后结果在所有的进程中。相当于先做MPI_Reduce,然后再做MPI_Scatter.

program main implicit none include "mpif.h" integer myid, ierr real(kind=8) val, max0 call MPI_INIT(ierr) call MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr) val = myid + 5.d0 print *, 'value:',val call MPI_ALLreduce(val,max0,1,MPI_DOUBLE_PRECISION,MPI_MAX, & MPI_COMM_WORLD,IERR) if(myid.eq.0) print *, 'max:',max0 call MPI_FINALIZE(ierr) stop end program main


result:

[root@c0109 ~]# mpif90 hello.F -o hello [root@c0109 ~]# mpiexec -n 10 ./hello value: 5.00000000000000 max: 14.0000000000000 value: 6.00000000000000 value: 7.00000000000000 value: 11.0000000000000 value: 10.0000000000000 value: 8.00000000000000 value: 13.0000000000000 value: 14.0000000000000 value: 9.00000000000000 value: 12.0000000000000 [root@c0109 ~]#

 

你可能感兴趣的:(c,Integer,include)