0

I am doing a simple MPI based program in Fortran. I have been successful in estimating the partial sums, but I am facing a problem in calculation of the global sum using MPI_allreduce.

Main code:

    program tst_trap
      use iso_fortran_env
      use some_functions
      implicit none
      include 'mpif.h'
      integer :: count1, count2, count_rate, i, npts,n,n1
      real(kind=8) :: answer, dx, sum, x, xmax, xmin,ssum,ierror
      integer(4) ::  ista, iend,ierr, iproc, nproc

      call MPI_INIT(ierr)
      call MPI_COMM_SIZE(MPI_COMM_WORLD, nproc, ierr)
      call MPI_COMM_RANK(MPI_COMM_WORLD, iproc, ierr)

      npts = 1000000001

      call para_range(1,npts,nproc, iproc, ista, iend)  

      write(output_unit,'(a)') 'Fortran version (MPI)'


      dx = (xmax-xmin)/real(npts-1)

       sum=0.0

      do i = ista, iend
         x = xmin + real(i-1)*dx
        sum = sum +  g(x)
      end do

      sum = (sum + 0.5*(g(xmin) + g(xmax)) )*dx

        write(6,*) 'Procesor ',iproc,':',' partial sum=', sum

        call MPI_allREDUCE(sum,ssum,1,MPI_REAL,MPI_SUM,MPI_COMM_WORLD,ierr)
        sum = ssum
        if ( iproc .eq.  0) write(6,*) 'global sum =', sum

     call MPI_FINALIZE(ierr)

    end program tst_trap

Output :

Procesor 0 : partial sum=  7.490350421761612E-002
Procesor 2 : partial sum=   3.94636946947332
Procesor 3 : partial sum=   19.0687865689115
Procesor 1 : partial sum=  0.696046284884674
global sum =  2.114738958711681E-314
Mechanician
  • 525
  • 1
  • 6
  • 20
  • Thanks. I changed it to MPI_REAL, even then , I am getting the same thing – Mechanician Apr 18 '16 at 20:46
  • Please edit your question to provide a [mcve]. Also do not use images to show text, copy the results in the question instead. – Zulan Apr 18 '16 at 20:48
  • I have shown the main code, Could you please provide your suggestions ? – Mechanician Apr 18 '16 at 20:58
  • 3
    You use `8` as the kind for your real variables (which is [not portable](http://stackoverflow.com/q/838310/)). Without further information I'll guess that that means something not compatible with `mpi_real`, such as `mpi_double_precision`. – francescalus Apr 18 '16 at 21:06
  • Thanks a lot. I used MPI_REAL8 and it worked :) – Mechanician Apr 18 '16 at 21:23

0 Answers0