ALF dev.
A QMC Code for fermionic models
Loading...
Searching...
No Matches
Global_mod.F90
1! Copyright (C) 2016 - 2022 The ALF project
2!
3! This file is part of the ALF project.
4!
5! The ALF project is free software: you can redistribute it and/or modify
6! it under the terms of the GNU General Public License as published by
7! the Free Software Foundation, either version 3 of the License, or
8! (at your option) any later version.
9!
10! The ALF project is distributed in the hope that it will be useful,
11! but WITHOUT ANY WARRANTY; without even the implied warranty of
12! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13! GNU General Public License for more details.
14!
15! You should have received a copy of the GNU General Public License
16! along with ALF. If not, see http://www.gnu.org/licenses/.
17!
18! Under Section 7 of GPL version 3 we require you to fulfill the following additional terms:
19!
20! - It is our hope that this program makes a contribution to the scientific community. Being
21! part of that community we feel that it is reasonable to require you to give an attribution
22! back to the original authors if you have benefitted from this program.
23! Guidelines for a proper citation can be found on the project's homepage
24! http://alf.physik.uni-wuerzburg.de .
25!
26! - We require the preservation of the above copyright notice and this license in all original files.
27!
28! - We prohibit the misrepresentation of the origin of the original source files. To obtain
29! the original source files please visit the homepage http://alf.physik.uni-wuerzburg.de .
30!
31! - If you make substantial changes to the program we require you to either consider contributing
32! to the ALF project or to mark your material in a reasonable way as different from the original version.
33
34
35
36!--------------------------------------------------------------------
37!> @author
38!> ALF-project
39!
40!> @brief
41!> Handles global updates and parallel tempering
42!
43!--------------------------------------------------------------------
44
46
47 Use runtime_error_mod
49 Use mymats
50 Use operator_mod
51 Use control
52 Use observables
53 Use fields_mod
54 Use random_wrap
55 use iso_fortran_env, only: output_unit, error_unit
56
57 Implicit none
58
59 Type (Obser_Vec ), private :: Tempering_acceptance
60
61
62 Contains
63#if defined(TEMPERING)
64!--------------------------------------------------------------------
65!> @author
66!> ALF-project
67!
68!> @brief
69!> Handles parrallel tempering \n
70!> This subroutine is called only if the tempering flag is switched on \n
71!> Requires MPI
72!>
73!> @details
74!> On entry and on exit the left storage is full, the Green function is on time slice 0 and the phase is set.
75!> The same holds on exit but with updated quantities.
76!>
77!> @param[inout] Phase Complex
78!> \verbatim
79!> Is updated upon acceptance
80!> \endverbatim
81!> @param[inout] udvl, udvr Class(UDV_State)
82!> \verbatim
83!> On entry udvl contains the last udv decomposition such that G=(1 + VL*DL*UL^{dag})^{-1}
84!> udvr is used as working space
85!> \endverbatim
86!> @param[inout] GR Complex
87!> \verbatim
88!> Green function. Is updated upon acceptance.
89!> \endverbatim
90!> @param[inout] udvst Class(UDV_State)
91!> \verbatim
92!> Storage. Is updated with left propagation upon acceptance
93!> \endverbatim
94!> @param[in] Stab_nt Integer
95!> \verbatim
96!> List of time slices for stabilization.
97!> \endverbatim
98!> @param[in] N_exchange_steps Integer
99!> \verbatim
100!> Number of exchange steps
101!> \endverbatim
102!> @param[in] Tempering_calc_det Logical
103!> \verbatim
104!> If true then the fermion determinant is computed in the calulcation of the exchange weight.
105!> \endverbatim
106!>
107!--------------------------------------------------------------------
108 Subroutine exchange_step(Phase,GR, udvr, udvl, Stab_nt, udvst, N_exchange_steps, Tempering_calc_det)
109 Use udv_state_mod
110 Use mpi
111 use wrapul_mod
112 use cgr1_mod
113 Implicit none
114
115 ! Arguments
116 COMPLEX (Kind=Kind(0.d0)), INTENT(INOUT) :: Phase
117 CLASS(udv_state), intent(inout), allocatable, Dimension(:) :: udvl, udvr
118 COMPLEX (Kind=Kind(0.d0)), Dimension(:,:,:), INTENT(INOUT), allocatable :: GR
119 CLASS(udv_state), intent(inout), allocatable, Dimension(:, :) :: udvst
120 INTEGER, dimension(:), INTENT (IN), allocatable :: Stab_nt
121 INTEGER, INTENT(IN) :: N_exchange_steps
122 Logical, INTENT(IN) :: Tempering_calc_det
123
124
125 !> Local variables.
126 Integer :: NST, NSTM, NF, nf_eff, NT, NT1, NVAR,N, N1,N2, I, NC, I_Partner, n_step, N_count, N_part
127 Type (Fields) :: nsigma_old
128 Real (Kind=kind(0.d0)) :: t0_proposal_ratio, weight, weight1, delta_s0_log, exp_delta_s0
129 Complex (Kind=Kind(0.d0)) :: Z_ONE = cmplx(1.d0, 0.d0, kind(0.d0)), z, ratiotot, ratiotot_p, phase_old, phase_new
130 Real (Kind=kind(0.d0)), allocatable :: det_vec_old(:,:), det_vec_new(:,:)
131 Complex (Kind=Kind(0.d0)), allocatable :: Phase_Det_new(:), Phase_Det_old(:)
132 Complex (Kind=Kind(0.d0)) :: Ratio(2), Ratio_p(2),Phase_array(N_FL)
133 Logical :: TOGGLE, L_Test
134 Integer, allocatable :: List_partner(:), List_masters(:)
135
136 ! Keep track of where the configuration originally came from
137 Integer :: nsigma_irank, nsigma_old_irank, nsigma_irank_temp
138 Integer :: n_GR
139
140 !Integer, Dimension(:,:), allocatable :: nsigma_orig, nsigma_test
141 !Integer :: I1, I2
142
143 Integer :: Isize, Irank, Ierr, irank_g, isize_g, igroup
144 Integer :: STATUS(MPI_STATUS_SIZE)
145
146 Character (Len=64) :: storage
147
148
149 CALL mpi_comm_size(mpi_comm_world,isize,ierr)
150 CALL mpi_comm_rank(mpi_comm_world,irank,ierr)
151 call mpi_comm_rank(group_comm, irank_g, ierr)
152 call mpi_comm_size(group_comm, isize_g, ierr)
153 igroup = irank/isize_g
154 nsigma_irank = irank
155
156 n1 = size(nsigma%f,1)
157 n2 = size(nsigma%f,2)
158 nstm = Size(udvst, 1)
159 call nsigma_old%make(n1, n2)
160 if (tempering_calc_det) then
161 Allocate ( det_vec_old(ndim,n_fl), det_vec_new(ndim,n_fl) )
162 Allocate ( phase_det_new(n_fl), phase_det_old(n_fl) )
163 endif
164 Allocate ( list_partner(0:isize-1), list_masters(isize/2) )
165
166 ! Allocate ( nsigma_orig(n1,n2) )
167 ! nsigma_orig = nsigma
168
169 ! Compute for each core the old weights.
170 l_test = .false.
171 if (tempering_calc_det) then
172 ! Set old weight.
173 storage = "Full"
174 Call compute_fermion_det(phase_det_old,det_vec_old, udvl, udvst, stab_nt, storage)
175 phase_array=1.0d0
176 Do nf_eff = 1,n_fl_eff
177 nf=calc_fl_map(nf_eff)
178 phase_array(nf) = phase_det_old(nf)
179 Call op_phase(phase_array(nf),op_v,nsigma,nf)
180 Enddo
181 if (reconstruction_needed) call ham%weight_reconstruction(phase_array)
182 phase_old=product(phase_array)
183 phase_old=phase_old**n_sun
184 endif
185 !> Store old configuration
186 nsigma_old%f = nsigma%f
187 nsigma_old%t = nsigma%t
188 nsigma_old_irank = nsigma_irank
189 ! Setup the list of masters
190 nc = 0
191 Do i = 0,isize-1,2*isize_g
192 do n = 0,isize_g-1
193 nc = nc + 1
194 list_masters(nc) = i + n
195 enddo
196 Enddo
197 if (l_test) then
198 if (irank == 0) then
199 Write(6,*) 'List of masters: '
200 Do nc = 1,isize/2
201 Write(6,*) nc, list_masters(nc)
202 Enddo
203 endif
204 endif
205 DO n_count = 1,n_exchange_steps
206 ! Set the partner rank on each core
207 If (irank == 0 ) then
208 n_step = isize_g
209 if ( ranf_wrap() > 0.5d0 ) n_step = -isize_g
210 Do i = 0,isize-1,2*isize_g
211 do n = 0,isize_g-1
212 list_partner(npbc_tempering(i + n ,isize)) = npbc_tempering(i + n + n_step ,isize)
213 list_partner(npbc_tempering(i + n + n_step , isize)) = npbc_tempering(i + n ,isize)
214 enddo
215 enddo
216 endif
217
218 CALL mpi_bcast(list_partner, isize ,mpi_integer, 0,mpi_comm_world,ierr)
219
220 If (l_test) then
221 if (irank == 0 ) then
222 Write(6,*) 'Testing global : '
223 do i = 0,isize -1
224 Write(6,*) i, list_partner(i) !, Phase_old, Phase
225 Write(11,*) i, list_partner(i) !, Phase_old, Phase
226 enddo
227 Write(11,*)
228 endif
229 Endif
230
231
232 ! Exchange configurations
233 ! The types do not change --> no need to exchange them
234 n = size(nsigma_old%f,1)*size(nsigma_old%f,2)
235 CALL mpi_sendrecv(nsigma_old%f , n, mpi_complex16, list_partner(irank), 0, &
236 & nsigma%f , n, mpi_complex16, list_partner(irank), 0, mpi_comm_world,status,ierr)
237 CALL mpi_sendrecv(nsigma_old_irank, 1, mpi_integer, list_partner(irank), 0, &
238 & nsigma_irank , 1, mpi_integer, list_partner(irank), 0, mpi_comm_world,status,ierr)
239
240 ! Each node now has a new configuration nsigma
241
242
243 if (tempering_calc_det) then
244 ! HERE
245 ! Compute ratio on weights one each rank
246 storage = "Empty"
247 Call compute_fermion_det(phase_det_new,det_vec_new, udvl, udvst, stab_nt, storage)
248
249 phase_array = cmplx(1.d0,0.d0,kind=kind(0.d0))
250 Do nf_eff = 1,n_fl_eff
251 nf=calc_fl_map(nf_eff)
252 phase_array(nf) = phase_det_new(nf)
253 Call op_phase(phase_array(nf),op_v,nsigma,nf)
254 Enddo
255 if (reconstruction_needed) call ham%weight_reconstruction(phase_array)
256 phase_new=product(phase_array)
257 phase_new=phase_new**n_sun
258
259 t0_proposal_ratio = 1.d0
260 ratiotot = compute_ratio_global(phase_det_old, phase_det_new, &
261 & det_vec_old, det_vec_new, nsigma_old, t0_proposal_ratio,ratio)
262
263 If (l_test) Write(6,*) 'Ratio_global: Irank, Partner',irank,list_partner(irank), &
264 & ratiotot, ratio(1)*exp(ratio(2))
265 else
266 delta_s0_log = ham%Get_Delta_S0_global(nsigma_old)
267 ratio(1) = 1.0d0 !!! @FAKHER @JONAS double check please
268 ratio(2) = delta_s0_log
269 endif
270
271 ! Acceptace/rejection decision taken on master node after receiving information from slave
272 Do nc = 1,isize/2 ! Loop over masters
273 i = list_masters(nc)
274 If (irank == i ) Then
275 CALL mpi_send(ratio ,2, mpi_complex16 , list_partner(i), i+1024, mpi_comm_world,ierr)
276 else if (irank == list_partner(i) ) Then
277 CALL mpi_recv(ratio_p , 2, mpi_complex16, i, i+1024, mpi_comm_world,status,ierr)
278 !Weight = abs(Ratiotot_p*Ratiotot)
279 weight= abs(ratio(1) * ratio_p(1) * exp( ratio_p(2) + ratio(2) ) )
280 toggle = .false.
281 if ( weight > ranf_wrap() ) toggle =.true.
282 If (l_test) Write(6,*) 'Master : ', list_partner(i), i, weight, toggle
283 endif
284 enddo
285
286 !> Send result of acceptance/rejection decision form master to slave
287 Do nc = 1,isize/2 ! Loop over masters
288 i = list_masters(nc)
289 If (irank == list_partner(i) ) Then
290 ! Write(6,*) 'Send from ', List_Partner(I), 'to, ', I, I + 512
291 CALL mpi_send(toggle, 1, mpi_logical, i, i+1024, mpi_comm_world,ierr)
292 else if (irank == i ) Then
293 CALL mpi_recv(toggle , 1, mpi_logical, list_partner(i), i+1024 ,mpi_comm_world,status,ierr)
294 If (l_test) Write(6,*) 'Slave : ', irank, toggle
295 endif
296 enddo
297
298 If (l_test) Write(6,*) 'Final: ', irank, list_partner(irank), toggle
299 Call global_tempering_obser(toggle)
300 Call control_upgrade_temp (toggle)
301 If (toggle) then
302 ! Move has been accepted
303 if (tempering_calc_det) then
304 phase_old = phase_new
305 phase_det_old = phase_det_new
306 det_vec_old = det_vec_new
307 endif
308 nsigma_old%f = nsigma%f
309 nsigma_old%t = nsigma%t
310 nsigma_old_irank = nsigma_irank
311 else
312 nsigma%f = nsigma_old%f
313 nsigma%t = nsigma_old%t
314 nsigma_irank = nsigma_old_irank
315 endif
316 enddo
317
318 ! Finalize
319 if (tempering_calc_det) then
320 ! If move has been accepted, no use to recomute storage
321 If (.not.toggle) then
322 DO nf_eff = 1,n_fl_eff
323 nf=calc_fl_map(nf_eff)
324 if (projector) then
325 CALL udvl(nf_eff)%reset('l',wf_l(nf)%P)
326 else
327 CALL udvl(nf_eff)%reset('l')
328 endif
329 ENDDO
330 DO nst = nstm-1,1,-1
331 nt1 = stab_nt(nst+1)
332 nt = stab_nt(nst )
333 !Write(6,*) NT1,NT, NST
334 CALL wrapul(nt1,nt, udvl)
335 Do nf_eff = 1,n_fl_eff
336 udvst(nst, nf_eff) = udvl(nf_eff)
337 ENDDO
338 ENDDO
339 nt1 = stab_nt(1)
340 CALL wrapul(nt1,0, udvl)
341 Endif
342 ! Compute the Green functions so as to provide correct starting point for the sequential updates.
343 nvar = 1
344 phase_array = cmplx(1.d0,0.d0,kind(0.d0))
345 do nf_eff = 1,n_fl_eff
346 nf=calc_fl_map(nf_eff)
347 CALL cgr(z, nvar, gr(:,:,nf), udvr(nf_eff), udvl(nf_eff))
348 call op_phase(z,op_v,nsigma,nf)
349 phase_array(nf)=z
350 Enddo
351 if (reconstruction_needed) call ham%weight_reconstruction(phase_array)
352 phase=product(phase_array)
353 phase=phase**n_sun
354 else
355 ! Send >> Phase, GR, udvr, udvl, udvst << to new node
356 ! First step: Each node sends to IRANK=0 its value nsigma_irank,
357 ! which is the node where its new Phase, GR, udvr, udvl, udvst is stored
358 ! This node then tells each node where to send its now old Phase, GR, udvr, udvl, udvst
359 ! Finally, the variables get submitted
360 If (irank == 0) then
361 Do i = 1,isize-1
362 CALL mpi_recv(nsigma_irank_temp , 1, mpi_integer, i, 0, mpi_comm_world,status,ierr)
363 If ( nsigma_irank_temp == 0) then
364 nsigma_old_irank = i
365 else
366 CALL mpi_send(i , 1, mpi_integer, nsigma_irank_temp, 0, mpi_comm_world,ierr)
367 endif
368 enddo
369 If ( nsigma_irank /= 0 ) then
370 CALL mpi_send(0 , 1, mpi_integer, nsigma_irank, 0, mpi_comm_world,ierr)
371 endif
372 else
373 CALL mpi_send(nsigma_irank , 1, mpi_integer, 0, 0, mpi_comm_world,ierr)
374 CALL mpi_recv(nsigma_old_irank , 1, mpi_integer, 0, 0, mpi_comm_world,status,ierr)
375 endif
376
377 if ( nsigma_irank /= irank ) then
378 CALL mpi_sendrecv_replace(phase, 1, mpi_complex16, nsigma_old_irank, 0, &
379 & nsigma_irank, 0, mpi_comm_world, status, ierr)
380
381 n_gr = size(gr,1)*size(gr,2)*size(gr,3)
382 CALL mpi_sendrecv_replace(gr, n_gr, mpi_complex16, nsigma_old_irank, 0, &
383 & nsigma_irank, 0, mpi_comm_world, status, ierr)
384
385 do nf_eff = 1,n_fl_eff
386 CALL udvr(nf_eff)%MPI_Sendrecv(nsigma_old_irank, 0, nsigma_irank, 0, status, ierr)
387 enddo
388 do nf_eff = 1,n_fl_eff
389 CALL udvl(nf_eff)%MPI_Sendrecv(nsigma_old_irank, 0, nsigma_irank, 0, status, ierr)
390 enddo
391 do nst = 1, nstm
392 do nf_eff = 1,n_fl_eff
393 CALL udvst(nst, nf_eff)%MPI_Sendrecv(nsigma_old_irank, 0, nsigma_irank, 0, status, ierr)
394 enddo
395 enddo
396 endif
397 endif
398
399
400 call nsigma_old%clear
401
402 if (tempering_calc_det) then
403 Deallocate ( det_vec_old, det_vec_new )
404 Deallocate ( phase_det_new, phase_det_old )
405 endif
406 Deallocate ( list_partner, list_masters )
407
408 end Subroutine exchange_step
409#endif
410
411
412!--------------------------------------------------------------------
413!> @author
414!> The ALF Project contributors
415!>
416!> @brief
417!> Carries out N_global global updates as defeined in the Global_move routine of the Hamiltonian module
418!>
419!> @details
420!> On entry and on exit the left storage is full, the Green function is on time slice 0 and the phase is set.
421!> The same holds on exit but with updated quantities.
422!>
423!> @param[inout] Phase Complex
424!> \verbatim
425!> Is updated upon acceptance
426!> \endverbatim
427!> @param[inout] udvl, udvr Class(UDV_State)
428!> \verbatim
429!> On entry udvl contains the last udv decomposition such that G=(1 + VL*DL*UL^{dag})^{-1}
430!> udvr is used as working space
431!> \endverbatim
432!> @param[inout] GR Complex
433!> \verbatim
434!> Green function. Is updated upon acceptance.
435!> \endverbatim
436!> @param[inout] udvst Class(UDV_State)
437!> \verbatim
438!> Storage. Is updated with left propagation upon acceptance
439!> \endverbatim
440!> @param[in] Stab_nt Integer
441!> \verbatim
442!> List of time slices for stabilization.
443!> \endverbatim
444!> @param[in] N_Global Integer
445!> \verbatim
446!> Number of global moves that will be caried out
447!> \endverbatim
448!>
449!--------------------------------------------------------------------
450 Subroutine global_updates(Phase,GR, udvr, udvl, Stab_nt, udvst,N_Global)
451
452 Use udv_state_mod
453 use wrapul_mod
454 use cgr1_mod
455 Implicit none
456
457 ! Arguments
458 COMPLEX (Kind=Kind(0.d0)), INTENT(INOUT) :: Phase
459 class(udv_state), DIMENSION(:), ALLOCATABLE, INTENT(INOUT) :: udvl, udvr
460 COMPLEX (Kind=Kind(0.d0)), Dimension(:,:,:), allocatable,INTENT(INOUT) :: GR
461 CLASS(udv_state), Dimension(:,:), ALLOCATABLE, INTENT(INOUT) :: udvst
462 INTEGER, dimension(:), allocatable, INTENT(IN) :: Stab_nt
463 Integer, INTENT(IN) :: N_Global
464
465
466 ! Local variables.
467 Integer :: NST, NSTM, NF, NT, NT1, NVAR,N, N1,N2, I, NC, N_part,j, nf_eff
468 Real (Kind=kind(0.d0)) :: t0_proposal_ratio, weight
469 Complex (Kind=Kind(0.d0)) :: Z_ONE = cmplx(1.d0, 0.d0, kind(0.d0)), z, ratiotot, phase_old, phase_new
470 Complex (Kind=Kind(0.d0)), allocatable :: Det_vec_test(:,:), Phase_Det_new(:), Phase_Det_old(:)
471 Real (Kind=kind(0.d0)), allocatable :: det_vec_old(:,:), det_vec_new(:,:)
472 Type (Fields) :: nsigma_old
473
474 Complex (Kind=Kind(0.d0)) :: Ratio(2), Phase_array(N_Fl)
475 Logical :: TOGGLE, L_Test
476 Real (Kind=kind(0.d0)) :: size_clust
477 Real (Kind=kind(0.d0)) :: ratio_2_test
478 Character (Len=64) :: storage
479
480
481
482 n1 = size(nsigma%f,1)
483 n2 = size(nsigma%f,2)
484 nstm = Size(udvst, 1)
485 call nsigma_old%make(n1, n2)
486
487 Allocate ( det_vec_old(ndim,n_fl_eff), det_vec_new(ndim,n_fl_eff), det_vec_test(ndim,n_fl_eff) )
488 Allocate ( phase_det_new(n_fl_eff), phase_det_old(n_fl_eff) )
489
490 l_test = .false.
491 ! Set old weight.
492 storage = "Full"
493 Call compute_fermion_det(phase_det_old,det_vec_old, udvl, udvst, stab_nt, storage)
494 phase_array = cmplx(1.d0,0.d0,kind=kind(0.d0))
495 Do nf_eff = 1,n_fl_eff
496 nf=calc_fl_map(nf_eff)
497 phase_array(nf) = phase_det_old(nf_eff)
498 Call op_phase(phase_array(nf),op_v,nsigma,nf)
499 Enddo
500 if (reconstruction_needed) call ham%weight_reconstruction(phase_array)
501 phase_old=product(phase_array)
502 phase_old=phase_old**n_sun
503
504 If (l_test) then
505 ! Testing
506 Do nf_eff = 1,n_fl_eff
507 nf=calc_fl_map(nf_eff)
508 if (projector) then
509 CALL udvr(nf_eff)%reset('r',wf_r(nf)%P)
510 else
511 CALL udvr(nf_eff)%reset('r')
512 endif
513 Enddo
514 nvar = 1
515 phase_array = cmplx(1.d0,0.d0,kind(0.d0))
516 do nf_eff = 1,n_fl_eff
517 nf=calc_fl_map(nf_eff)
518 CALL cgr(z, nvar, gr(:,:,nf), udvr(nf_eff), udvl(nf_eff))
519 call op_phase(z,op_v,nsigma,nf)
520 phase_array(nf)=z
521 Enddo
522 if (reconstruction_needed) call ham%weight_reconstruction(phase_array)
523 phase=product(phase_array)
524 phase=phase**n_sun
525 Do nf_eff = 1,n_fl_eff
526 nf=calc_fl_map(nf_eff)
527 Call det_c_lu(gr(:,:,nf),det_vec_test(:,nf_eff),ndim)
528 !!!ATTENTION HOW DOES BELOW DEPEND ON NF BLOCK symm
529 z = phase_det_old(nf_eff)
530 ratio_2_test=0.d0
531 DO i = 1,ndim
532 z = z*det_vec_test(i,nf_eff)/abs(det_vec_test(i,nf_eff))
533 ratio_2_test=ratio_2_test+log(abs(det_vec_test(i,nf_eff)))+det_vec_old(i,nf_eff)
534 Enddo
535 z=z*cmplx(exp(ratio_2_test),0.d0,kind(0.d0))
536 Write(6,*) 'Testing weight: ', z
537 if(abs(ratio_2_test)>650) write(6,*) "Weight is about to reach double underflow!"
538 Enddo
539 Endif
540
541 ! Store old configuration
542 nsigma_old%f = nsigma%f
543 nsigma_old%t = nsigma%t
544 ! Phase_old, Phase_det_old and Det_vec_old are all set.
545 nc = 0
546 Do n = 1,n_global
547 ! Draw a new spin configuration. This is provided by the user in the Hamiltonian module
548 ! Note that nsigma is a variable in the module Hamiltonian
549 Call ham%Global_move(t0_proposal_ratio,nsigma_old,size_clust)
550 If (t0_proposal_ratio > 0.d0) then
551 nc = nc + 1
552 ! Compute the new Green function
553 storage = "Empty"
554 Call compute_fermion_det(phase_det_new,det_vec_new, udvl, udvst, stab_nt, storage)
555
556 phase_array = cmplx(1.d0,0.d0,kind=kind(0.d0))
557 Do nf_eff = 1,n_fl_eff
558 nf=calc_fl_map(nf_eff)
559 phase_array(nf) = phase_det_new(nf)
560 Call op_phase(phase_array(nf),op_v,nsigma,nf)
561 Enddo
562 if (reconstruction_needed) call ham%weight_reconstruction(phase_array)
563 phase_new=product(phase_array)
564 phase_new=phase_new**n_sun
565
566 ratiotot = compute_ratio_global(phase_det_old, phase_det_new, &
567 & det_vec_old, det_vec_new, nsigma_old, t0_proposal_ratio, ratio)
568
569 !Write(6,*) 'Ratio_global: ', Ratiotot
570
571 weight = abs( real( phase_old * ratiotot, kind=kind(0.d0))/real(phase_old,kind=kind(0.d0)) )
572
573 z = phase_old * ratiotot/abs(ratiotot)
574 Call control_precisionp_glob(z,phase_new)
575 !Write(6,*) Z, Phase_new
576
577
578 toggle = .false.
579 if ( weight > ranf_wrap() ) Then
580 toggle = .true.
581 phase_old = phase_new
582 phase_det_old = phase_det_new
583 nsigma_old%t = nsigma%t
584 nsigma_old%f = nsigma%f
585 det_vec_old = det_vec_new
586 else
587 nsigma%t = nsigma_old%t
588 nsigma%f = nsigma_old%f
589 endif
590 Call control_upgrade_glob(toggle,size_clust)
591 else
592 nsigma%t = nsigma_old%t
593 nsigma%f = nsigma_old%f
594 endif
595 Enddo
596
597 If (nc > 0 ) then
598 If (.not.toggle) then
599 DO nf_eff = 1,n_fl_eff
600 nf=calc_fl_map(nf_eff)
601 if (projector) then
602 CALL udvl(nf_eff)%reset('l',wf_l(nf)%P)
603 else
604 CALL udvl(nf_eff)%reset('l')
605 endif
606 ENDDO
607 DO nst = nstm-1,1,-1
608 nt1 = stab_nt(nst+1)
609 nt = stab_nt(nst )
610 !Write(6,*) NT1,NT, NST
611 CALL wrapul(nt1,nt, udvl)
612 Do nf_eff = 1,n_fl_eff
613 udvst(nst, nf_eff) = udvl(nf_eff)
614 ENDDO
615 ENDDO
616 nt1 = stab_nt(1)
617 CALL wrapul(nt1,0, udvl)
618 Endif
619 !Compute the Green functions so as to provide correct starting point for the sequential updates.
620 nvar = 1
621 phase_array = cmplx(1.d0,0.d0,kind(0.d0))
622 do nf_eff = 1,n_fl_eff
623 nf=calc_fl_map(nf_eff)
624 CALL cgr(z, nvar, gr(:,:,nf), udvr(nf_eff), udvl(nf_eff))
625 call op_phase(z,op_v,nsigma,nf)
626 phase_array(nf)=z
627 Enddo
628 if (reconstruction_needed) call ham%weight_reconstruction(phase_array)
629 phase=product(phase_array)
630 phase=phase**n_sun
631 endif
632
633
634 call nsigma_old%clear
635 Deallocate ( det_vec_old , det_vec_new, det_vec_test )
636 Deallocate ( phase_det_new, phase_det_old )
637
638
639 End Subroutine global_updates
640
641
642!--------------------------------------------------------------------
643!> @author
644!> The ALF Project contributors
645!>
646!> @brief
647!> This fucntion computes ratio of weights for global moves
648!>
649!> @details
650!> \verbatim
651!> Ratio_Global = T0(nsigma--> nsigma_old) W(nsigma)/T0(nsigma_old--> nsigma) W(nsigma_old) =
652!> T0_Proposal_ratio W(nsigma)/ W(nsigma_old)
653!> On entry the old and new fermion determinants read: Phase_det*e^{ \sum_{n=1}^{ndim} Det_vec(n) }
654!> as obtained from the Compute_Fermion_det routine.
655!> On exit Ratio_Global = Ratio(1)*exp(Ratio(2))
656!> \endverbatim
657!>
658!> @param[in] Phase_det_new Complex, Dimension(N_FL)
659!> @param[in] Phase_det_old Complex, Dimension(N_FL)
660!> @param[in] Det_vec_new Real, Dimension(:,N_FL)
661!> @param[in] Det_vec_old Real, Dimension(:,N_FL)
662!> @param[in] T0_proposal_ratio Real
663!> @param[in] nsigma_old Type(Fields)
664!> \verbatim
665!> Old configuration. The new configuration is stored in nsigma. nsigma is a globale variable
666!> contained in the Hamiltonian module.
667!> \endverbatim
668!--------------------------------------------------------------------
669 Complex (Kind=Kind(0.d0)) Function compute_ratio_global(Phase_Det_old, Phase_Det_new, &
670 & Det_vec_old, Det_vec_new, nsigma_old, T0_Proposal_ratio,Ratio)
671
672
673 Implicit none
674
675 ! Arguments
676 Complex (Kind=Kind(0.d0)), allocatable, INTENT(IN) :: phase_det_old(:), phase_det_new(:)
677 REAL (kind=kind(0.d0)), allocatable, INTENT(IN) :: det_vec_old(:,:), det_vec_new(:,:)
678 Real (kind=kind(0.d0)), INTENT(IN) :: t0_proposal_ratio
679 Type (fields), INTENT(IN) :: nsigma_old
680 Complex (Kind=Kind(0.d0)), INTENT(out) :: ratio(2)
681
682 ! Local
683 Integer :: nf, i, nt, nf_eff
684 Complex (Kind=Kind(0.d0)) :: z, z1, ratio_1_array(n_fl), ratio_2_array(n_fl), g_loc
685 Real (kind=kind(0.d0)) :: x, ratio_2, delta, log_delta
686
687 ratio = cmplx(0.d0,0.d0,kind(0.d0))
688 ratio_2_array = 0.d0
689 !X = 1.d0
690 Do nf_eff = 1,n_fl_eff
691 nf=calc_fl_map(nf_eff)
692 DO i = 1,ndim
693 !X= X*real(Det_vec_new(I,nf),kind(0.d0)) / Real(Det_vec_old(I,nf),kind(0.d0) )
694 ratio_2_array(nf) = ratio_2_array(nf) + det_vec_new(i,nf_eff) - det_vec_old(i,nf_eff)
695 enddo
696 !Z = Z**N_SUN
697 ratio_2_array(nf) = real(n_sun,kind(0.d0))*ratio_2_array(nf)
698 enddo
699 !Z = cmplx(X,0.d0,kind(0.d0))
700 ratio_1_array = cmplx(1.d0,0.d0,kind(0.d0))
701 Do nf_eff = 1,n_fl_eff
702 nf=calc_fl_map(nf_eff)
703 !Z = Z*Phase_Det_new(nf)/Phase_Det_old(nf)
704 ratio_1_array(nf_eff) = ratio_1_array(nf) * phase_det_new(nf_eff)/phase_det_old(nf_eff)
705 !Z = Z**N_SUN
706 ratio_1_array(nf) = ratio_1_array(nf)**n_sun
707 enddo
708
709 ratio(1)=1.d0
710 Do i = 1,Size(op_v,1)
711 x = 0.d0
712 Do nt = 1,ltrot
713 !Z = Z * cmplx( Gaml(nsigma(i,nt),2)/Gaml(nsigma_old(i,nt),2),0.d0,kind(0.d0) )
714 ratio(1) = ratio(1) * cmplx( nsigma%Gama(i,nt)/nsigma_old%Gama(i,nt),0.d0,kind(0.d0) ) !You could put this in Ratio_2
715 !X = X + nsigma%Phi(i,nt) - nsigma_old%Phi(i,nt)
716 Do nf_eff = 1,n_fl_eff
717 nf=calc_fl_map(nf_eff)
718 z = nsigma%Phi(i,nt) - nsigma_old%Phi(i,nt)
719 g_loc = op_v(i,nf)%g
720 if ( op_v(i,nf)%get_g_t_alloc()) g_loc = op_v(i,nf)%g_t(nt)
721 !Z = Z * exp(cmplx( X*Real(N_SUN,Kind(0.d0)), 0.d0,kind(0.d0)) * Op_V(i,nf)%g * Op_V(i,nf)%alpha )
722 ratio_1_array(nf) = ratio_1_array(nf) * exp(z*cmplx( real(n_sun,kind(0.d0)), 0.d0,kind(0.d0)) * g_loc * op_v(i,nf)%alpha )
723 Enddo
724 Enddo
725 Enddo
726 if (reconstruction_needed) then
727 call ham%weight_reconstruction(ratio_1_array)
728 call ham%weight_reconstruction(ratio_2_array)
729 endif
730 ratio(1)=ratio(1)*product(ratio_1_array)
731 !Z = Z * cmplx( ham%Delta_S0_global(Nsigma_old),0.d0,kind(0.d0) )
732 !Z = Z * cmplx( T0_Proposal_ratio, 0.d0,kind(0.d0))
733 ratio(2) = sum(ratio_2_array)
734 log_delta = ham%Get_Delta_S0_global(nsigma_old)
735 ratio(2) = ratio(2) + log_delta + log(t0_proposal_ratio)
736
737 compute_ratio_global = ratio(1)*exp(ratio(2))
738
739
740 end Function compute_ratio_global
741
742!--------------------------------------------------------------------
743!> @author
744!>
745!> @brief
746!> Computes the fermion determinant from scratch or from the storage.
747!>
748!> @details
749!> \verbatim
750!> Finite temperature: If the storage is full then computes
751!> det( 1 + VL*DL*UL^{dag} )= Phase_det*e^{ \sum_{n=1}^{ndim} Det_vec(n)}
752!> Note that Udvl%U = UL, Udvl%D = DL and Udvl%V = VL^{dag}
753!> If storage is empty one first computes Udvl and in doing so fills up the storage.
754!> Zero temperature: If storage is full then computes det \Psi_L U(\theta_tot,0) \Psi_R = Phase_det*e^{ \sum_{n=1}^{N_part} Det_vec(n) }
755!> For the projective code the required scales which one can throw away for the Green function are in udvst.
756!> If the storage is not full, then things will be computed from scratch and intermediate results will be stored in udvst.
757!> \endverbatim
758!>
759!> @param[inout] udvl, udvr Class(UDV_State)
760!> \verbatim
761!> If storage=Full : On entry and exit udvl contains the last udv decomposition such that G=(1 + VL*DL*UL^{dag})^{-1}
762!> If storage=Empty : On exit udv1 will contain the last udv decomposition such that G=(1 + VL*DL*UL^{dag})^{-1}
763!> \endverbatim
764!> @param[out] Phase_det Complex, Dimension(N_FL)
765!> \verbatim
766!> The phase, per flavor
767!> \endverbatim
768!> @param[out] Det_vec Real, Dimension(:,N_FL)
769!> @param[in] Stab_nt Integer, Dimension(:)
770!> \verbatim
771!> List of time slices for stabilization.
772!> \endverbatim
773!> @param[in] Storage Character
774!> \verbatim
775!> storage = "Full". Compute the fermion det with the use of the storage.
776!> storage = "Empty". Compute the fermion det from scratch and in doing so, fill the storage.
777!> \endverbatim
778!>
779!--------------------------------------------------------------------
780 Subroutine compute_fermion_det(Phase_det,Det_Vec, udvl, udvst, Stab_nt, storage)
781!--------------------------------------------------------------------
782
783 Use udv_wrap_mod
784 Use udv_state_mod
785 use wrapul_mod
786
787 Implicit none
788
789 REAL (Kind=kind(0.d0)), Dimension(:,:), Intent(OUT) :: det_vec
790 Complex (Kind=Kind(0.d0)), Dimension(:) , Intent(OUT) :: Phase_det
791 CLASS(udv_state), DIMENSION(:) , ALLOCATABLE, INTENT(INOUT) :: udvl
792 CLASS(udv_state), Dimension(:,:), ALLOCATABLE, INTENT(INOUT) :: udvst
793 INTEGER, dimension(:), allocatable, INTENT(IN) :: Stab_nt
794 Character (Len=64), Intent(IN) :: storage
795
796
797 !> Local variables
798 Integer :: N_size, NCON, I, J, N_part, info, NSTM, N, nf, nst, nt, nt1, nf_eff
799 Integer, allocatable :: ipiv(:)
800 COMPLEX (Kind=Kind(0.d0)) :: alpha,beta, Z, Z1
801 TYPE(udv_state) :: udvlocal
802 COMPLEX (Kind=Kind(0.d0)), Dimension(:,:), Allocatable :: TP!, U, V
803 COMPLEX (Kind=Kind(0.d0)), Dimension(:), Allocatable :: D
804
805 !! TODO adapt to flavor symmetry
806
807 if(udvl(1)%side .ne. "L" .and. udvl(1)%side .ne. "l" ) then
808 write(error_unit,*) "Compute_Fermion_Det: calling wrong decompose"
809 CALL terminate_on_error(error_global_updates,__file__,__line__)
810 endif
811
812 nstm = Size(udvst, 1)
813 If (str_to_upper(storage) == "EMPTY" ) then
814 DO nf_eff = 1,n_fl_eff
815 nf=calc_fl_map(nf_eff)
816 if (projector) then
817 CALL udvl(nf_eff)%reset('l',wf_l(nf)%P)
818 else
819 CALL udvl(nf_eff)%reset('l')
820 endif
821 ENDDO
822 DO nst = nstm-1,1,-1
823 nt1 = stab_nt(nst+1)
824 nt = stab_nt(nst )
825 !Write(6,*) 'Call wrapul', NT1,NT, udvl(1)%d(1), udvl(1)%N_part, udvl(1)%Ndim
826 CALL wrapul(nt1,nt, udvl)
827 Do nf_eff = 1,n_fl_eff
828 udvst(nst, nf_eff) = udvl(nf_eff)
829 ENDDO
830 ENDDO
831 nt1 = stab_nt(1)
832 CALL wrapul(nt1,0, udvl)
833 Endif
834
835 if (projector) then
836 n_part=udvst(1,1)%N_part
837 n_size=udvl(1)%ndim
838 det_vec = 0.d0
839 Allocate (tp(n_part,n_part), ipiv(n_part))
840 do nf_eff=1,n_fl_eff
841 nf=calc_fl_map(nf_eff)
842 n_part=udvst(1,nf)%N_part
843 do i=1,nstm-1
844 do n=1,n_part
845#if !defined(STABLOG)
846 det_vec(n,nf_eff)=det_vec(n,nf_eff)+log(dble(udvst(i,nf)%D(n)))
847#else
848 det_vec(n,nf_eff)=det_vec(n,nf_eff)+udvst(i,nf)%L(n)
849#endif
850 enddo
851 enddo
852 do n=1,n_part
853#if !defined(STABLOG)
854 det_vec(n,nf_eff)=det_vec(n,nf_eff)+log(dble(udvl(nf_eff)%D(n)))
855#else
856 det_vec(n,nf_eff)=det_vec(n,nf_eff)+udvl(nf_eff)%L(n)
857#endif
858 enddo
859 alpha=1.d0
860 beta=0.d0
861 CALL zgemm('C','N',n_part,n_part,n_size,alpha,udvl(nf_eff)%U(1,1),n_size,wf_r(nf)%P(1,1),n_size,beta,tp(1,1),n_part)
862 ! ZGETRF computes an LU factorization of a general M-by-N matrix A
863 ! using partial pivoting with row interchanges.
864 call zgetrf(n_part, n_part, tp(1,1), n_part, ipiv, info)
865 z=1.d0
866 Do j=1,n_part
867 if (ipiv(j).ne.j) then
868 z = -z
869 endif
870 z = z * tp(j,j)
871 enddo
872 phase_det(nf_eff) = z/abs(z)
873 det_vec(1,nf) = det_vec(1,nf)+log(abs(z))
874 enddo
875 Deallocate(tp,ipiv)
876 return
877 endif
878
879 ! N_size = SIZE(DL,1)
880 n_size = udvl(1)%ndim
881 ncon = 0
882 alpha = cmplx(1.d0,0.d0,kind(0.d0))
883 beta = cmplx(0.d0,0.d0,kind(0.d0))
884 Allocate (tp(n_size,n_size),d(n_size))
885 CALL udvlocal%alloc(n_size)
886 Do nf_eff = 1,n_fl_eff
887 nf=calc_fl_map(nf_eff)
888 tp = udvl(nf_eff)%U !udvl stores U^dag instead of U !CT(udvl%U)
889#if !defined(STABLOG)
890#if !defined(STAB3)
891 DO j = 1,n_size
892 tp(:,j) = tp(:,j) + udvl(nf_eff)%V(:,j)*udvl(nf_eff)%D(j)
893 ENDDO
894#else
895 DO j = 1,n_size
896 if ( dble(udvl(nf_eff)%D(j)) <= 1.d0 ) then
897 tp(:,j) = tp(:,j) + udvl(nf_eff)%V(:,j)*udvl(nf_eff)%D(j)
898 else
899 tp(:,j) = tp(:,j)/udvl(nf_eff)%D(j) + udvl(nf_eff)%V(:,j)
900 endif
901 ENDDO
902#endif
903#else
904 DO j = 1,n_size
905 if ( udvl(nf_eff)%L(j) <= 0.d0 ) then
906 tp(:,j) = tp(:,j) + udvl(nf_eff)%V(:,j)*cmplx(exp(udvl(nf_eff)%L(j)),0.d0,kind(0.d0))
907 else
908 tp(:,j) = tp(:,j)*cmplx(exp(-udvl(nf_eff)%L(j)),0.d0,kind(0.d0)) + udvl(nf_eff)%V(:,j)
909 endif
910 ENDDO
911#endif
912
913 !Call UDV_WRAP_Pivot(TP,udvlocal%U, D, udvlocal%V, NCON,N_size,N_Size)
914 Call udv_wrap(tp,udvlocal%U, d, udvlocal%V, ncon )
915 z = det_c(udvlocal%V, n_size) ! Det destroys its argument
916 ! Call MMULT(TP, udvl%U, udvlocal%U)
917 CALL zgemm('C', 'N', n_size, n_size, n_size, alpha, udvl(nf_eff)%U(1,1), n_size, udvlocal%U(1,1), n_size, beta, tp, n_size)
918 z1 = det_c(tp, n_size)
919 phase_det(nf_eff) = z*z1/abs(z*z1)
920#if !defined(STABLOG)
921#if !defined(STAB3)
922 det_vec(:,nf_eff) = log(real(d(:)))
923 det_vec(1,nf_eff) = log(real(d(1))) + log(abs(z*z1))
924#else
925 det_vec(1,nf_eff) = log(real(d(1))*abs(z*z1))
926 if (dble(udvl(nf_eff)%D(1)) > 1.d0) det_vec(1,nf_eff)=det_vec(1,nf_eff)+log(dble(udvl(nf_eff)%D(1)))
927 Do j=2,ndim
928 if (dble(udvl(nf_eff)%D(j))<=1.d0) then
929 det_vec(j,nf_eff) = log(real(d(j)))
930 else
931 det_vec(j,nf_eff) = log(real(d(j)))+log(dble(udvl(nf_eff)%D(j)))
932 endif
933 enddo
934#endif
935#else
936 det_vec(:,nf_eff) = log(real(d(:)))
937 det_vec(1,nf_eff) = log(real(d(1))*abs(z*z1))
938 if (udvl(nf_eff)%L(1) > 0.d0) det_vec(1,nf_eff)=det_vec(1,nf_eff)+udvl(nf_eff)%L(1)
939 Do j=2,ndim
940 if (udvl(nf_eff)%L(j)<=0.d0) then
941 det_vec(j,nf_eff) = log(real(d(j)))
942 else
943 det_vec(j,nf_eff) = log(real(d(j)))+udvl(nf_eff)%L(j)
944 endif
945 enddo
946#endif
947 Enddo
948 Deallocate (tp)
949 CALL udvlocal%dealloc
950
951 end subroutine compute_fermion_det
952
953
954!--------------------------------------------------------------------
955!> @author
956!> The ALF Project contributors
957!>
958!> @brief
959!> Periodic boundary conditions required to defined master and slave for the tempering
960!--------------------------------------------------------------------
961 Integer function npbc_tempering(n,Isize)
962 implicit none
963 Integer, INTENT(IN) :: isize,n
964
965 npbc_tempering = n
966 if ( npbc_tempering < 0 ) npbc_tempering = npbc_tempering + isize
967 if ( npbc_tempering > isize -1) npbc_tempering = npbc_tempering - isize
968
969 end function npbc_tempering
970
971
972!--------------------------------------------------------------------
973!> @author
974!> The ALF Project contributors
975!>
976!> @brief
977!> Allocates the Tempering_acceptance (Type Obser_vec) variable that monitors the exchange acceptance
978!--------------------------------------------------------------------
979 Subroutine global_tempering_setup
980 Integer :: N
981 Character (len=64) :: Filename
982 n = 1
983 filename = "Acc_Temp"
984 Call obser_vec_make(tempering_acceptance,n,filename)
985 End Subroutine global_tempering_setup
986
987!--------------------------------------------------------------------
988!> @author
989!> The ALF Project contributors
990!>
991!> @brief
992!> Initializes Tempering_acceptance
993!--------------------------------------------------------------------
994
995 Subroutine global_tempering_init_obs
996 Call obser_vec_init( tempering_acceptance )
997 end Subroutine global_tempering_init_obs
998
999!--------------------------------------------------------------------
1000!> @author
1001!> The ALF Project contributors
1002!>
1003!> @brief
1004!> Measures Tempering_acceptance
1005!--------------------------------------------------------------------
1006
1007 Subroutine global_tempering_obser(toggle)
1008 Implicit none
1009
1010 Logical, intent(in) :: toggle
1011 tempering_acceptance%N = tempering_acceptance%N + 1
1012 tempering_acceptance%Ave_sign = tempering_acceptance%Ave_sign + 1.d0
1013 if (toggle) tempering_acceptance%Obs_vec(1) = tempering_acceptance%Obs_vec(1) + cmplx(1.d0,0.d0,kind(0.d0))
1014
1015 end Subroutine global_tempering_obser
1016!--------------------------------------------------------------------
1017!> @author
1018!> The ALF Project contributors
1019!>
1020!> @brief
1021!> Prints Tempering_acceptance
1022!--------------------------------------------------------------------
1023 Subroutine global_tempering_pr
1024 Implicit none
1025 Call print_bin_vec(tempering_acceptance,group_comm)
1026 end Subroutine global_tempering_pr
1027
1028
1029end Module global_mod
This module handles the calculation of the acceptance ratio. It also monitors the precision of the co...
Handles Hubbard Stratonovitch fields.
Handles global updates and parallel tempering.
This module defines the interface between the Hamiltonians (= model and observables definition) and t...
Wrappers for linear algebra.
This module defines the Obser_Vec and Obser_Latt types and provides routine to initialize them and to...
Defines the Operator type, and provides a number of operations on this type.
Handles UDV decompositions.
This module contains two version of the stabilization. To switch between the two schemes you should d...
Handles UDV decompositions.