Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: [OMPI users] Doubt regarding MPI_GATHER
From: Arunkumar C R (arunkumar.cr_at_[hidden])
Date: 2009-11-23 02:06:29


I have written an MPI code to find acceleration (a = F/m) of a system of
particles. I would like to know how to perform MPI_GATHER of all the output
data at the root process and print the whole array (in the present case,
f(1:n) ) and reuse it for some other purpose in the serial part of the same
code. Please check the program given below and give me a solution.

program g
        use mpi
        implicit none

        real(kind(1d0)),allocatable,dimension(:)::a, f
        integer::i, n, true, ierr, np, irank, istart, iend, var, nprocs

        nprocs= 4 !no: of processors used
        n = 100 !no: of array elements
        m = 12.0d0 !mass of the moving particle
        var = n / nprocs !no: of array elements per process
        allocate(a(n), f(n), stat=true)
        if( print*,'mem err'

        call mpi_init(ierr)
        call mpi_comm_size(mpi_comm_world, np, ierr)
        call mpi_comm_rank(mpi_comm_world, irank, ierr)
        istart= irank * var + 1
        iend = (irank + 1) * var

        do i= istart, iend
                f(i) = dble(i) !the magnitude of force is taken
as continuous (real) numbers !!
                a(i) = f(i) / m
        end do
        if(irank.eq.0) then !root process
            do i=1,n
                print*,i,a(i) !here, all the root elements are
printed correctly and the other elements as zeroes
            end do
        end if
  call mpi_finalize(ierr)

Thanks in Advance