Inglonias
Inglonias

Reputation: 532

When sending data using MPI in Fortran, does it have to be an array?

This is a pretty simple question. I'm practicing using MPI in Fortran, and as far as I can tell, the sending and receiving sources must be arrays, like this:

    do 20 i = 1, 25
    final_sum(1) = final_sum(1) + random_numbers(i)
20  continue
    print *, 'process final sum: ', final_sum(1)
    call MPI_GATHER(final_sum,1,MPI_INTEGER,sum_recv_buff,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierror)

Here, I'm using the array final_sum to hold a single value. Is there a better way to do this? This is my first time using Fortran, and since I've already done some practice in C, I was trying out Fortran to see the differences and similarities.

Upvotes: 0

Views: 93

Answers (1)

High Performance Mark is right. There is actually normally no type checking when calling MPI routines that work with buffers. The MPI routines make use of the Fortran feature that enables calling procedures with implicit interface. On machine language level just a pointer is passed (it may be a pointer to a temporary copy!). That means you can use scalars or arrays without any problem. Just use count 1 and the correct MPI type and you can pass and receive scalars.

The MPI derived types is a feature that will enable you to work with even more complicated pieces of data.

Upvotes: 1

Related Questions