Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortran and MPI

Status
Not open for further replies.

dcs4

Programmer
Joined
Jun 4, 2014
Messages
1
Location
ES
Hi boys.

I'm trying to call a barrier in a MPI program with Fortran, but I don't know how do it.

I don't have any problem with the main program, but i have a lot of problems with the comunicator when I have tried to do it in a Fortran Routine. I don't know how I can do it. Can you give me an example?

Thanks in advande
 
The barrier basically stops execution until all the processes call it.
Code:
program main
include 'mpif.h'
integer ierr
integer rank, sleepsec
character(10):: now

! Initialize the MPI environment
call MPI_Init(ierr)

! Find the node
call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)

sleepsec = 5 * rank
call date_and_time(time=now)
print *, rank, ' sleeping for ', sleepsec, ' from ', now
call SLEEP(sleepsec)
call MPI_BARRIER(MPI_COMM_WORLD, ierr)
call date_and_time(time=now)
print *, rank, ' awake ', now
call MPI_FINALIZE(ierr)
end
Code:
mpif90 -o barrier barrier.f90
Code:
mpirun -n 4 barrier
What you will see is that the different processes sleep for differing numbers of seconds but they all only awake when the longest sleeping process callse MPI_BARRIER.
 
The example uses gfortran and the open MPI package that comes with Linux. You didn't specify which compiler/operating system you were using with MPI.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top