! simple_ex.f90 include "mpiSim.f90" program ex1f include "useSim.f90" ! Author unknown. !! generats one new communicator for all MPI processes running on !! The same host. implicit none ! include 'mpif.h' integer :: myrank, nprocs, n, islave, master integer :: status(MPI_STATUS_SIZE) integer :: ierr, resultlen, tag integer :: color, new_comm, new_rank, new_size, one, ssum character (LEN=8) :: hostname Double Precision :: t1, t2 ! Initialize MPI Call MPI_Init(Ierr) ! Get my rank id and number of MPI processes call MPI_Comm_rank(MPI_COMM_WORLD, myrank, ierr) call MPI_Comm_size(MPI_COMM_WORLD, nprocs, ierr) ! Get hostname call MPI_Get_processor_name(hostname, resultlen, ierr) ! Synchonization point call MPI_Barrier (MPI_COMM_WORLD, ierr) t1 = MPI_Wtime() !----------------------------------------------------------- ! Do work here ... Write (*,*) "Rank ", myrank, " out of ", nprocs, & " processes running on ", hostname(1:index(hostname,".")-1) ! our hostnames contain a number, which will be used to generate new ! communicators containing all MPI processes running on the same host. ! sunc.rz.rwth-aachen.de ! read ( hostname(5:6),'(i2)') color ! $$Error: color is undefined in call to MPI_Comm_split. call MPI_Comm_split ( MPI_COMM_WORLD, color, myrank, new_comm, ierr ) call MPI_Comm_rank ( new_comm, new_rank, ierr ) call MPI_Comm_size ( new_comm, new_size, ierr ) one = 1 ssum = 0 call MPI_Reduce ( one, ssum, 1, MPI_INTEGER, MPI_SUM, 0, & new_comm, ierr ) if ( new_rank .eq. 0 ) then Write (*,*) "my rank in MPI_COMM_WORLD is ", myrank, " out of ", nprocs, & " / my rank in new_comm is ", new_rank, " out of ", new_size, & " / ", ssum, "processes have been taking part in the reduction" end if !----------------------------------------------------------- ! Synchronization point call MPI_Barrier (MPI_COMM_WORLD, ierr) t2 = MPI_Wtime() write (*,*) "slave ", myrank, ": ", t2-t1, " seconds" ! Shut Down MPI call MPI_Finalize(ierr ) end program ex1f