0

This is really new to me. I am testing this hello world code on a machine.

program hello
  include 'mpif.h'
  integer rank, size, ierror, tag, status(MPI_STATUS_SIZE)
  character(12) message

  call MPI_INIT(ierror)
  call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierror)
  call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierror)
  tag = 100
  if(rank .eq. 0) then

     message = 'Hello, world'
     do i=1, size-1
        call MPI_SEND(message, 12, MPI_CHARACTER, i, tag,&
             MPI_COMM_WORLD, ierror)
     enddo
  else
     call MPI_RECV(message, 12, MPI_CHARACTER, 0, tag,&
          MPI_COMM_WORLD, status, ierror)
  endif
  write(*,*) 'node', rank, ':', message

  call MPI_FINALIZE(ierror)
end program hello

I used mpif90 to compile it and submitted the job with 4 nodes. And this is what the output file looks like:

    nodenodenode             2           1              0:: Hello, worldHello, world:Hello, world


node            3 :Hello, world

So I am really worried about this format. Again I don't have much experience with MPI. I tested it on another machine and it looked like this:

 node           1 :Hello, world
 node           0 :Hello, world
 node           2 :Hello, world
 node           3 :Hello, world

Could you tell me if this is an unusual output or it really just differs from machine to machine? Thank you so much. ~

enni707
  • 75
  • 8
  • Thank you. So the output from different nodes can happen at the same time and even overlap with each other? Is that the idea? – enni707 Oct 31 '14 at 20:31
  • On the other machine the output is probably line buffered. It is also often the case when the standard IO gets redirected by the MPI implementation over the network. – Hristo Iliev Oct 31 '14 at 23:34
  • possible duplicate of [Using MPI, a message appears to have been recieved before it has been sent](http://stackoverflow.com/questions/25289625/using-mpi-a-message-appears-to-have-been-recieved-before-it-has-been-sent) – Wesley Bland Nov 03 '14 at 15:14

1 Answers1

0

That looks fairly normal to me.

Multiple processes are writing, essentially simultaneously, to the same terminal and the o/s interleaves their writes. The differences between the two outputs are easily explained by differences in buffering between platforms; one seems to be buffering each line, the other each word.

What you are learning is that, in MPI programming, it is the programmer's responsibility to sequence operations across processes, if that is desirable. The run-time platform won't do it for you and run-time platforms differ.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161