32 real(kind=kind(1.0D0)) :: dt=1.0d-2
33 real(kind=kind(1.0D0)),
allocatable,
dimension(:) :: x,k1,k2,k3,k4
34 real(kind=kind(1.0d0)) :: F=8.0d0
36 integer :: total_timesteps=100
38 integer :: mpi_err,mdl_id,cpl_root,cpl_mpi_comm
39 integer,
dimension(MPI_STATUS_SIZE) :: mpi_status
48 inquire(file=
'l96.nml', exist=l96_exists)
50 open(32,file=
'l96.nml',iostat=ios,action=
'read'&
52 if(ios .ne. 0) stop
'Cannot open l96.nml'
67 allocate(x(n),k1(n),k2(n),k3(n),k4(n))
72 if(mdl_id .eq. 0)
then
73 call mpi_send(x,n,mpi_double_precision,cpl_root&
74 &,1,cpl_mpi_comm,mpi_err)
75 call mpi_recv(x,n,mpi_double_precision,cpl_root&
76 &,mpi_any_tag,cpl_mpi_comm,mpi_status,mpi_err)
82 do t = 1,total_timesteps
84 k2 =
g(x +0.5d0 * dt * k1 , n , f )
85 k3 =
g(x +0.5d0 * dt * k2 , n , f )
86 k4 =
g(x + dt * k3 , n , f )
87 x = x + dt *( k1 + 2.0d0 *( k2 + k3 ) + k4 )/6.0d0
89 if(mdl_id .eq. 0)
then
90 call mpi_send(x,n,mpi_double_precision,cpl_root&
91 &,1,cpl_mpi_comm,mpi_err)
92 call mpi_recv(x,n,mpi_double_precision,cpl_root&
93 &,mpi_any_tag,cpl_mpi_comm,mpi_status,mpi_err)
97 select case(mpi_status(mpi_tag))
107 call mpi_finalize(mpi_err)
110 function g (x , N, F )
112 real(kind=kind(1.0D0)),
intent(in),
dimension(0:N-1) :: x
113 integer,
intent(in) :: N
114 real(kind=kind(1.0D0)),
dimension(0:N-1) :: g
115 real(kind=kind(1.0D0)),
intent(in) :: F
118 g(j) = ( x(modulo(j+1,n)) -x( modulo(j-2,n)) )*&
119 &x(modulo(j-1,n)) - x(j) + f
125 integer,
intent(out) :: mdl_id,cpl_root,cpl_mpi_comm
126 integer :: mdl_num_proc=1
127 integer :: mpi_err,world_size,world_id
128 integer :: cpl_colour
129 integer :: particle_id,nens, da, nda
130 integer :: mdl_mpi_comm,mdlcolour
131 integer :: tmp_mdls_comm,models_id,models_size
132 call mpi_init(mpi_err)
134 call mpi_comm_rank(mpi_comm_world,world_id,mpi_err)
135 call mpi_comm_size(mpi_comm_world,world_size,mpi_err)
136 call mpi_comm_split(mpi_comm_world,da,world_id,tmp_mdls_comm,mpi_err)
137 call mpi_comm_size(tmp_mdls_comm,models_size,mpi_err)
138 call mpi_comm_rank(tmp_mdls_comm,models_id, mpi_err)
139 mdlcolour = models_id/mdl_num_proc
140 call mpi_comm_split(tmp_mdls_comm,mdlcolour,models_id,mdl_mpi_comm,mpi_err)
141 call mpi_comm_rank(mdl_mpi_comm,mdl_id,mpi_err)
142 if(mdl_id .eq. 0)
then
145 cpl_colour = mpi_undefined
147 call mpi_comm_split(mpi_comm_world,cpl_colour,mdlcolour,cpl_mpi_comm,mpi_err)
148 if(mdl_id .eq. 0)
then
149 call mpi_comm_size(cpl_mpi_comm,nens,mpi_err)
150 call mpi_comm_rank(cpl_mpi_comm,particle_id,mpi_err)
151 nda = world_size-models_size;nens = nens - nda
152 cpl_root = ((nda*particle_id)/nens)+nens
subroutine initialise_mpi(mdl_id, cpl_root, cpl_mpi_comm)
real(kind=kind(1.0d0)) function, dimension(n, 3) g(X, N, F, alpha, delta, epsilon, gamma)