Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Understanding MPI_Gather

Understanding MPI_Gather

Understanding MPI_Gather

Hi there,

I’m relatively new to Fortran and to this community. I’m trying to write some code that performs some calculations on a multidimensional array using MPI. And for the life of me I can’t get MPI_Gather to work, and I’m sure it’s something very obvious that I’m missing here.

My code is:

program test

    USE mpi
    USE netcdf


    INTEGER,ALLOCATABLE,DIMENSION(:,:,:) :: array, global_array
    INTEGER :: j_start, j_end, i_start, i_end, J, I, t

    ! MPI
    INTEGER :: mpirank, mpisize, mpierr

    ! Initialize MPI
    call MPI_INIT(mpierr)
    call MPI_COMM_SIZE(MPI_COMM_WORLD, mpisize, mpierr)
    call MPI_COMM_RANK(MPI_COMM_WORLD, mpirank, mpierr)

    j_start = 1
    j_end   = 4
    i_start = 1 + (mpirank*4/mpisize)
    i_end   = (mpirank + 1)*4/mpisize
    DO t=1,2

        DO J=j_start,j_end

            DO I=i_start,i_end

                array(J,I,t) = J+I+t
            END DO

        END DO ! J

    END DO ! t

    IF (mpirank==0) WRITE(*,*) 'before MPI_Gather...'
    WRITE(*,*) mpirank, array(1,:,1)
    CALL MPI_Barrier(MPI_COMM_WORLD, mpierr)

    CALL MPI_Gather(array(:,i_start:i_end,:), 4*2*2, MPI_INTEGER, & 
                    global_array(:,i_start:i_end,:), 4*2*2, MPI_INTEGER, &
                    0, MPI_COMM_WORLD, mpierr)

    IF (mpirank == 0) THEN
        WRITE(*,*) 'AFTER MPI_Gather...'
        DO J=1,4
            WRITE(*,*) (global_array(J,I,t), I=1,4,1)
        END DO
    END IF

    ! Finalise MPI

end program test 

And I get these results, which are obviously wrong:

 before MPI_Gather...
           1           0           0           5           6
           0           3           4           0           0
 AFTER MPI_Gather...
           0     5289440           0           0
           0           0           0           0
         225           0           0           0
           0           0           0           0 

I’m using Intel Fortran 2022, and I compile the program with mpiifort

Any help/comment/advice will be truly appreciated!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close