Hi, A fortran 90 code having MPI enabled subroutine is written. The subroutine part is given below,
program abc .................. !usual statements open(20, file='sum.20', action='write') open(30, file='sum.40', action='write') n2= 100; nstep=50 do step=1, nstep n1 = step sum2 = (n2 - n1 + 1) * (2*n1 + (n2 - n1 )) / 2 !from arithmetic progression call routine write(20, *) step, sum1, sum2 end do end program abc subroutine routine use dat !module 'dat' with common variables for both program & subroutine use mpi implicit none integer::ivar, istart, iend, sumt, i if(step.eq.1) call mpi_init(ierr) call mpi_comm_rank(mpi_comm_world, irank, ierr) call mpi_comm_size(mpi_comm_world, np, ierr) ivar = (n2 - n1) / np + 1 istart= min(irank * ivar + 1, n2 + 1) iend = min(istart + ivar - 1, n2) sum1 = 0 do i=istart, iend sum1= sum1 + i end do call mpi_reduce(sum1, sumt, 1, mpi_integer, mpi_sum, 0, mpi_comm_world, ierr) sum1 = sumt if(irank.eq.0) then write(30, *) step, sum1, sum2 end if if(step.eq.nstep) call mpi_finalize(ierr) end subroutine routine The current problem is that once the subroutine is called the data written to sum.30 and sum.20 are not matching. If there's no mistake with the calculation part, how shall it be possible to get the same data in both the files. I could see some of the 'sum1' values in sum.20 are not correct. I expect some good replies. Thanks in advance. Arunkumar