Search This Blog

Friday, October 5, 2007

MPI-Broadcating a new data type

!**********************************************************************
!****************************************************************************
program main

use mpi


TYPE particle ! Defining the DATA TYPE of "particle"
REAL, DIMENSION(3) :: Coord
REAL :: Radius
REAL :: ZetaPt
END TYPE particle

type(particle) :: colloid1

integer n, myid, numprocs , rc

integer, dimension(1) :: t, b, d

call MPI_INIT( ierr )
call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )

print *, 'Process ', myid, ' of ', numprocs, ' is alive'

colloid1%Coord = 0
colloid1%Radius = 0.0
colloid1%ZetaPt = 0.0


if ( myid .eq. 0 ) then
n = 100000
colloid1%Coord(1) = 10.0
colloid1%Coord(2) = 20.0
colloid1%Coord(3) = 30.0
colloid1%Radius = 1.0
colloid1%ZetaPt = 0.0
endif

call MPI_BCAST(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)

if ( myid .gt. -1 ) then
print *, ' n of process ', myid, ' is ', n
endif

t(1) = MPI_REAL
b(1) = 13
d(1) = 0

call MPI_TYPE_STRUCT (1,b,d,t,MPI_PARTICLE, ierr)
call MPI_TYPE_COMMIT (MPI_PARTICLE, ierr)

call MPI_BCAST(colloid1,1,MPI_PARTICLE,0,MPI_COMM_WORLD,ierr)

if ( myid .gt. -1 ) then
print *, myid, colloid1
endif


call MPI_FINALIZE(rc)
stop
end

Labels