| CCM_MOD | MPI |
program ccm_bcast use ccm_mod call ccm_init(myid,nodes) if(myid .eq. 0)x=3.14 call ccm_bcast(x) write(*,*)"x=",x call ccm_close() end program |
program mpi_bcast include "mpif.h" call mpi_init(ierr) call mpi_com_size(mpi_comm_world,nodes,ierr) call mpi_com_rank(mpi_comm_world,myid,ierr) if(myid .eq. 0)x=3.14 call mpi_bcast(x,1,mpi_real,0,mpi_comm_world) write(*,*)"x=",x call mpi_finalize(ierr) end program |
| CCM_MOD | MPI |
program ccm_reduce
use ccm
integer time_info_array(8)
integer hour,min,sec,millisec
integer ierr,nprocs,myid
real local_t,gtime_min,gtime_sum,gtime_max
call ccm_init(num_procs=nprocs)
call date_and_time(values=time_info_array)
hour=time_info_array(5)
min=time_info_array(6)
sec=time_info_array(7)
millisec=time_info_array(8)
local_t=(hour*60+min)*60+sec+millisec/1000.0
gtime_sum=0.0
call ccm_reduce(local_t,gtime_sum,"+")
call ccm_reduce(local_t,gtime_min,"min")
call ccm_reduce(local_t,gtime_max,"max")
if(gtime_sum .gt. 0)then
write(*,*)gtime_min,&
gtime_sum/nprocs,&
gtime_max
endif
call ccm_close()
end program
|
program mpi_reduce
include "mpif.h"
integer time_info_array(8)
integer hour,min,sec,millisec
integer ierr,nprocs,myid
real local_t,gtime_min,gtime_sum,gtime_max
call mpi_init(ierr)
call mpi_com_size(mpi_comm_world,nodes,ierr)
call mpi_com_rank(mpi_comm_world,myid,ierr)
call date_and_time(values=time_info_array)
hour=time_info_array(5)
min=time_info_array(6)
sec=time_info_array(7)
millisec=time_info_array(8)
local_t=(hour*60+min)*60+sec+millisec/1000.0
gtime_sum=0.0
call mpi_reduce(local_t,gtime_sum,1,mpi_real,&
mpi_sum,0,mpi_com_world,ierr)
call mpi_reduce(local_t,gtime_min,1,mpi_real,&
mpi_min,0,mpi_com_world,ierr)
call mpi_reduce(local_t,gtime_max,1,mpi_real,&
mpi_max,0,mpi_com_world,ierr)
if(gtime_sum .gt. 0)then
write(*,*)gtime_min,&
gtime_sum/nprocs,&
gtime_max
endif
call mpi_finalize(ierr)
end program
|
| CCM_MOD | MPI |
program ccm_scatter
use ccm
implicit none
integer :: myid,nprocs,igot,i
integer ,allocatable :: to_send(:)
call ccm_init(myid,nprocs)
allocate(to_send(0:nprocs-1))
if(myid .eq. 1)then
do i=0,nprocs-1
to_send(i)=i*i
enddo
endif
call ccm_scatter(to_send,igot,root=1)
write(*,*)"for i= ",myid," igot= ",igot
call ccm_close()
end program
|
program mpi_scatter
implicit none
include "mpif.h"
integer :: myid,nprocs,igot,i,ierr
integer ,allocatable :: to_send(:)
call mpi_init(ierr)
call mpi_com_size(mpi_comm_world,nodes,ierr)
call mpi_com_rank(mpi_comm_world,myid,ierr)
allocate(to_send(0:nprocs-1))
if(myid .eq. 1)then
do i=0,nprocs-1
to_send(i)=i*i
enddo
endif
call mpi_scatter(to_send, 1,mpi_integer,&
igot,1,mpi_integer,&
1,mpi_comm_world,ierr)
write(*,*)"for i= ",myid," igot= ",igot
call ccm_close()
end program
|
| CCM_MOD | MPI |
program ccm_alltoallv
use ccm
implicit none
integer :: myid,nodes,igot,i,j
integer, allocatable :: xin(:),xout(:)
integer ,allocatable :: to_send(:),to_get(:)
real local_time,global_time
call mpi_init(ierr)
call mpi_com_size(mpi_comm_world,nodes,ierr)
call mpi_com_rank(mpi_comm_world,myid,ierr)
allocate(to_send(0:nodes-1),to_get(0:nodes-1))
do i=0,nodes-1
to_send(i)=myid+i
enddo
allocate(xin(sum(to_send)))
call ccm_alltoall(to_send,to_get)
allocate(xout(sum(to_get)))
xin=myid
call ccm_alltoallv(xin,xout,to_send,to_get)
write(*,"("" i= "",i4,"" xout= "",20i3)")myid,xout
call ccm_close()
end program
|
program mpi_alltoallv
use ccm
implicit none
integer :: myid,nodes,igot,i,j
integer, allocatable :: xin(:),xout(:)
integer ,allocatable :: to_send(:),to_get(:)
integer ,allocatable :: sdisp(:),rdisp(:)
integer :: i_err
call ccm_init(myid,nodes)
allocate(to_send(0:nodes-1),to_get(0:nodes-1))
allocate(sdisp(0:nodes-1),rdisp(0:nodes-1))
do i=0,nodes-1
to_send(i)=myid+i
enddo
allocate(xin(sum(to_send)))
call mpi_alltoall(xin, 1,mpi_integer,&
xout,1,mpi_integer,&
mpi_comm_world,i_err)
allocate(xout(sum(to_get)))
xin=myid
rdisp(1)=0
do i=2,nodes
rdisp(i)=rdisp(i-1)+to_get(i-1)
enddo
sdisp(1)=0
do i=2,nodes
sdisp(i)=sdisp(i-1)+to_send(i-1)
enddo
call mpi_alltoallv(xin,to_send,sdisp,mpi_integer,&
xout, to_get,rdisp,mpi_integer,&
mpi_comm_world,i_err)
write(*,"("" i= "",i4,"" xout= "",20i3)")myid,xout
call ccm_close()
end program
|
| CCM_MOD | MPI |
program ccm_checkin
use ccm
implicit none
integer my_id,num_nodes,the_err
call ccm_init(my_id,num_nodes)
!this checkin should pass ok
call ccm_checkin(10.0,"hello",the_err)
if(the_err .ne. 0)then
write(*,*)"error in checkin ",the_err
else
write(*,*)" checkin ok"
endif
! the next lines should cause a
! deadlock that is detected
if(my_id .eq. 1)then
call ccm_checkin(10.0,"one")
else
call ccm_checkin(10.0,"the_rest")
endif
call ccm_close()
end program
|
Left to the student as an exercise |