41 integer,
parameter :: rk = kind(1.0d0)
42 integer :: i,old,j,dupepos,dupe,particle,k
43 real(kind=rk),
dimension(pf%nens) :: cumweights
44 integer,
dimension(pf%nens) :: new,tobereplaced,brandnew
46 real(kind=rk) :: point,draw
48 integer,
dimension(2*pf%nens) :: requests
49 integer :: summ,destination,source
50 integer,
allocatable,
dimension(:,:) :: statuses
53 integer :: ensemble_comm
57 select case(comm_version)
59 ensemble_comm = pf_mpi_comm
61 ensemble_comm = pf_ens_comm
63 write(emp_e,*)
'EMPIRE VERSION ',comm_version,
' NOT SUPPORTED IN RESAMP&
65 write(emp_e,*)
'THIS IS AN ERROR. STOPPING'
70 call mpi_gatherv(pf%weight(gbldisp(pfrank+1)+1:gbldisp(pfrank+1)+pf%count&
71 &),pf%count,mpi_double_precision,pf%weight&
72 &,gblcount,gbldisp,mpi_double_precision,0,ensemble_comm,mpi_err)
81 if(.not. all(pf%weight .eq. pf%weight))
then
83 if(pf%weight(i) .ne. pf%weight(i))
then
84 write(emp_e,*)
'EMPIRE ERROR in resample.f90'
85 write(emp_e,*)
'Particle ',i,
' has weight ',pf%weight(i)
86 write(emp_e,*)
'stopping now'
94 pf%weight = exp(-pf%weight + minval(pf%weight) )
96 pf%weight = pf%weight/sum(pf%weight)
100 cumweights(1) = pf%weight(1)
102 cumweights(i) = cumweights(i-1) + pf%weight(i)
110 call random_number(draw)
120 do particle = 1,pf%nens
121 point =
real(particle-1,rk)/pf%nens + draw
127 if(point .lt. cumweights(old))
then
148 if(i .eq. new(j))
then
153 if(.not. in) tobereplaced(i) = i
159 brandnew = (/ (i,i=1,pf%nens) /)
163 if(tobereplaced(i) .ne. -1)
then
166 do k = dupepos,pf%nens
167 if(new(k) .eq. new(k+1))
then
175 brandnew(tobereplaced(i)) = dupe
187 call mpi_bcast(brandnew,pf%nens,mpi_integer,0,pf_mpi_comm,mpi_err)
196 particle = pf%particles(i)
197 if(particle .ne. brandnew(particle))
then
198 print*,
'replacing particle ',particle,
'with particle ',brandnew(particle)
202 print*,
'pfrank ',pfrank,
'going to receive particle ',i,
' from ta&
203 &g ',brandnew(particle)
206 call mpi_irecv(pf%psi(:,i),state_dim,mpi_double_precision&
207 &,mpi_any_source,brandnew(particle),ensemble_comm,requests(k)&
223 if(brandnew(i) .ge. pf%particles(1) .and. brandnew(i) .le.&
224 & pf%particles(pf%count) .and. brandnew(i) .ne. i )
then
231 if(i .le. summ+gblcount(j))
then
236 summ = summ + gblcount(j)
249 if(pf%particles(j) .eq. brandnew(i))
then
257 print*,
'going to send ',brandnew(i),
'with tag',brandnew(i)
258 print*,
'from pfrank ',pfrank,
' to destination ',destination
260 print*,
'the source number is ',source
265 call mpi_isend(pf%psi(:,source),state_dim&
266 &,mpi_double_precision,destination,brandnew(i),ensemble_comm&
267 &,requests(k),mpi_err)
276 print*,
'going into mpi_waitall with pfrank = ',pfrank
277 ALLOCATE( statuses(mpi_status_size,k) )
278 print*,
'going into mpi_testall'
282 call mpi_testall(k,requests(1:k),flag,statuses,mpi_err)
284 print*,
'mpi testall finished with flag ',flag
287 print*,
'did the mpi_waitall on pfrank = ',pfrank
289 print*,
'hit the barrier'
290 call mpi_barrier(pf_mpi_comm,mpi_err)
294 pf%weight = 1.0_rk/
real(pf%nens,rk)
295 pf%weight = -log(pf%weight)
subroutine resample
Subroutine to perform Universal Importance Resampling.
Module containing EMPIRE coupling data.
Module that stores the information about the outputting from empire.
Module that stores the dimension of observation and state spaces.
module pf_control holds all the information to control the the main program
A module for random number generation from the following distributions: