Hi,

I wrote this code:

      program hello
       implicit none

       include 'mpif.h'
       integer :: rank, dest, source, tag, ierr, stat
       integer :: n
       integer :: taskinfo, ptr

       call MPI_INIT(ierr)
       call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)

       if(rank.eq.0) then
        write(*,*) 'Hello'

        n = 20
        dest = 1
        tag = 1
        taskinfo = n
        call MPI_SEND(taskinfo, 1, MPI_INTEGER, dest, tag,
     1       MPI_COMM_WORLD, ierr)

        tag = tag + 1
        call MPI_SEND(ptr, 1, MPI_INTEGER, dest, tag,
     1       MPI_COMM_WORLD, ierr)

       else
        source = 0
        tag = 1

!        n = 1
        call MPI_RECV(taskinfo, 1, MPI_INTEGER, source, tag,
     1       MPI_COMM_WORLD, stat, ierr)

        n = taskinfo

        tag = tag + 1

        write(*,*) 'n1 ', n
        write(*,*) 'taskinfo1 ', taskinfo
        call MPI_RECV(ptr, 1, MPI_INTEGER, source, tag,
     1       MPI_COMM_WORLD, stat, ierr)
        write(*,*) 'n2 ', n
        write(*,*) 'taskinfo2 ', taskinfo
       endif

       call MPI_FINALIZE(ierr)
      end


I supposed that it should produce this:
 Hello
 n1           20
 taskinfo1           20
 n2            20
 taskinfo2           20

But in fact it produces this:
 Hello
 n1           20
 taskinfo1           20
 n2            2
 taskinfo2           20

It's strange to me that variable "n" is changed after call to MPI subroutine, but I dont even put it in calls to MPI. If I comment line 13 with " write(*,*) 'Hello' " everything is ok. If I uncomment line 30 with "n = 1", everything is ok as well.

Could anybody explain me what is happening?

I tested it on:
  1) intel fortran compiler 14.0 and openmpi 1.6.5
  1) intel fortran compiler 13.1.3 and openmpi 1.8.4

Best regards,
Pawel J.




Reply via email to