I am encountering precision problems with MPI_REDUCE() in fortran. I have tested two methods of summing double precision numbers stored on each node. The MPI_REDUCE() line I use is
call MPI_REDUCE(num,total,1,MPI_DOUBLE_PRECISION,MPI_SUM,0,MPI_COMM_WORLD,ierr)
which stores the sum of the values of "num" on each core and sends it to "total" on the root core.
The other method I use involves sends and receives
if (rank .eq. 0) total = num
do i = 1,nproc-1
if (rank .eq. i) call MPI_SEND(num,1,MPI_DOUBLE_PRECISION,0,&
100,MPI_COMM_WORLD,ierr)
if (rank .eq. 0) then
call MPI_RECV(num,1,MPI_DOUBLE_PRECISION,i,&
100,MPI_COMM_WORLD,stat,ierr)
total = total + num
end if
end do
The latter always gives me the same number for total, while the former produces a different value depending on the number of processors I use (It usually changes by 1x10^-5 or so). ierr is 0 in all cases. Am I doing something wrong?
Thanks