214 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_tmc_master'
216 INTEGER :: cancel_count, handle, last_output, reactivation_cc_count, &
217 reactivation_ener_count, restart_count, restarted_elem_nr, stat, walltime_delay, &
218 walltime_offset, wg, worker_counter
219 INTEGER(KIND=int_8) :: mem
220 INTEGER,
DIMENSION(6) :: nr_of_job
221 INTEGER,
DIMENSION(:),
POINTER :: tree_elem_counters, tree_elem_heads
222 LOGICAL :: external_stop, flag, l_update_tree
223 REAL(kind=
dp) :: run_time_start
224 REAL(kind=
dp),
DIMENSION(4) :: worker_timings_aver
225 REAL(kind=
dp),
DIMENSION(:),
POINTER :: efficiency
226 TYPE(
elem_array_type),
DIMENSION(:),
POINTER :: ana_worker_info, worker_info
230 external_stop = .false.
231 restarted_elem_nr = 0
232 NULLIFY (init_conf, worker_info, ana_worker_info, gt_elem_tmp, tree_elem_counters)
234 cpassert(
ASSOCIATED(tmc_env))
236 cpassert(tmc_env%tmc_comp_set%group_nr == 0)
237 cpassert(
ASSOCIATED(tmc_env%tmc_comp_set))
238 cpassert(
ASSOCIATED(tmc_env%tmc_comp_set%para_env_m_w))
240 cpassert(
ASSOCIATED(tmc_env%m_env))
244 CALL timeset(routinen, handle)
250 IF (tmc_env%params%DRAW_TREE) &
258 reactivation_ener_count = 0
259 reactivation_cc_count = 0
261 tmc_env%m_env%result_count = 0
262 l_update_tree = .false.
267 worker_timings_aver(:) = 0.0_dp
270 ALLOCATE (worker_info(tmc_env%tmc_comp_set%para_env_m_w%num_pe - 1))
271 ALLOCATE (ana_worker_info(tmc_env%tmc_comp_set%para_env_m_ana%num_pe - 1))
278 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
279 tmc_params=tmc_env%params, &
280 wait_for_message=.true.)
284 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
285 tmc_params=tmc_env%params, &
286 elem=init_conf, success=flag, wait_for_message=.true.)
288 CALL cp_abort(__location__, &
289 "receiving start configuration failed, received stat "// &
294 para_env=tmc_env%tmc_comp_set%para_env_m_first_w)
300 move_types=tmc_env%params%move_types, &
301 mol_array=init_conf%mol)
302 IF (
ASSOCIATED(tmc_env%params%nmc_move_types)) &
304 move_types=tmc_env%params%nmc_move_types, &
305 mol_array=init_conf%mol)
312 job_counts=nr_of_job, &
313 worker_timings=worker_timings_aver)
316 IF (tmc_env%m_env%restart_out_step .NE. 0)
THEN
317 restart_count = int(tmc_env%m_env%result_count(0)/ &
318 REAL(tmc_env%m_env%restart_out_step, kind=
dp)) + 1
320 restarted_elem_nr = tmc_env%m_env%result_count(0)
325 DO wg = 1, tmc_env%tmc_comp_set%para_env_m_w%num_pe - 1
328 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
329 tmc_params=tmc_env%params)
333 IF (tmc_env%tmc_comp_set%para_env_m_ana%num_pe .GT. 1)
THEN
334 DO wg = 1, tmc_env%tmc_comp_set%para_env_m_ana%num_pe - 1
337 para_env=tmc_env%tmc_comp_set%para_env_m_ana, &
338 result_count=tmc_env%m_env%result_count, &
339 tmc_params=tmc_env%params, &
341 wait_for_message=.true.)
345 para_env=tmc_env%tmc_comp_set%para_env_m_ana)
351 IF (tmc_env%params%print_test_output .OR. debug .GT. 0) &
352 WRITE (tmc_env%m_env%io_unit, *)
"TMC|first_global_tree_rnd_nr_X= ", &
353 tmc_env%m_env%gt_head%rnd_nr
358 IF (tmc_env%tmc_comp_set%group_cc_nr .GT. 0) &
359 wg = tmc_env%tmc_comp_set%group_ener_nr + 1
362 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
363 tmc_params=tmc_env%params, &
364 elem=tmc_env%m_env%gt_head%conf(1)%elem)
365 worker_info(wg)%busy = .true.
366 worker_info(wg)%elem => tmc_env%m_env%gt_head%conf(1)%elem
367 init_conf => tmc_env%m_env%gt_head%conf(1)%elem
368 ELSE IF (tmc_env%m_env%gt_head%conf(1)%elem%stat .EQ.
status_created)
THEN
369 init_conf => tmc_env%m_env%gt_head%conf(1)%elem
383 worker_request_loop:
DO
387 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
388 tmc_params=tmc_env%params, &
389 elem_array=worker_info(:), success=flag)
391 IF (flag .EQV. .false.)
EXIT worker_request_loop
395 WRITE (tmc_env%m_env%io_unit, *) &
397 " of canceled worker group"
398 cycle worker_request_loop
403 IF (.NOT.
ASSOCIATED(worker_info(wg)%elem)) &
404 CALL cp_abort(__location__, &
405 "no tree elem exist when receiving stat "// &
409 WRITE (tmc_env%m_env%io_unit, *) &
411 " of sub tree "//
cp_to_string(worker_info(wg)%elem%sub_tree_nr)// &
413 " with stat"//
cp_to_string(worker_info(wg)%elem%stat)// &
414 " of group"//
cp_to_string(wg)//
" group canceled ", worker_info(wg)%canceled
422 cpassert(worker_info(wg)%canceled)
423 worker_info(wg)%canceled = .false.
424 worker_info(wg)%busy = .false.
426 IF (
ASSOCIATED(worker_info(wg)%elem))
THEN
427 SELECT CASE (worker_info(wg)%elem%stat)
430 worker_timings_aver(4) = (worker_timings_aver(4)*nr_of_job(6) + &
431 (
m_walltime() - worker_info(wg)%start_time))/real(nr_of_job(6) + 1, kind=
dp)
432 nr_of_job(6) = nr_of_job(6) + 1
435 worker_info(wg)%elem%potential = 8000.0_dp
436 IF (tmc_env%params%DRAW_TREE)
THEN
438 tmc_params=tmc_env%params)
442 worker_timings_aver(3) = (worker_timings_aver(3)*nr_of_job(5) + &
443 (
m_walltime() - worker_info(wg)%start_time))/real(nr_of_job(5) + 1, kind=
dp)
444 nr_of_job(5) = nr_of_job(5) + 1
447 worker_info(wg)%elem%potential = 8000.0_dp
448 IF (tmc_env%params%DRAW_TREE)
THEN
450 tmc_params=tmc_env%params)
455 worker_info(wg)%elem => null()
463 nr_of_job(3) = nr_of_job(3) + 1
464 worker_info(wg)%busy = .false.
466 IF (tmc_env%params%DRAW_TREE)
THEN
468 tmc_params=tmc_env%params)
470 worker_info(wg)%elem => null()
475 IF (.NOT. worker_info(wg)%canceled) worker_info(wg)%busy = .false.
477 worker_timings_aver(1) = (worker_timings_aver(1)*nr_of_job(3) + &
478 (
m_walltime() - worker_info(wg)%start_time))/real(nr_of_job(3) + 1, kind=
dp)
479 nr_of_job(3) = nr_of_job(3) + 1
481 worker_info(wg)%start_time =
m_walltime() - worker_info(wg)%start_time
482 CALL set_walltime_delay(worker_info(wg)%start_time, walltime_delay)
484 IF (tmc_env%params%DRAW_TREE)
THEN
486 tmc_params=tmc_env%params)
490 IF (tmc_env%params%NMC_inp_file .EQ.
"")
THEN
491 worker_info(wg)%elem%potential = worker_info(wg)%elem%e_pot_approx
494 IF (.NOT. (
ASSOCIATED(worker_info(wg)%elem, init_conf)))
THEN
498 IF (tmc_env%params%DRAW_TREE)
THEN
500 tmc_params=tmc_env%params)
503 CALL cancel_calculations(cancel_list=tmc_env%m_env%cancelation_list, &
504 work_list=worker_info, &
505 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
507 cancel_count=cancel_count)
508 worker_info(wg)%elem => null()
511 IF (tmc_env%tmc_comp_set%group_cc_nr .LE. 0 &
512 .AND. (.NOT. worker_info(wg)%canceled))
THEN
517 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
518 tmc_params=tmc_env%params, &
519 elem=worker_info(wg)%elem)
520 worker_info(wg)%busy = .true.
521 nr_of_job(2) = nr_of_job(2) + 1
522 IF (tmc_env%params%DRAW_TREE)
THEN
524 tmc_params=tmc_env%params)
529 worker_info(wg)%elem => null()
535 worker_timings_aver(2) = (worker_timings_aver(2)*nr_of_job(4) + &
536 (
m_walltime() - worker_info(wg)%start_time))/real(nr_of_job(4) + 1, kind=
dp)
537 nr_of_job(4) = nr_of_job(4) + 1
539 worker_info(wg)%start_time =
m_walltime() - worker_info(wg)%start_time
540 CALL set_walltime_delay(worker_info(wg)%start_time, walltime_delay)
542 IF (.NOT. worker_info(wg)%canceled) &
543 worker_info(wg)%busy = .false.
545 IF (
ASSOCIATED(worker_info(wg)%elem, init_conf))
THEN
549 IF (tmc_env%params%DRAW_TREE)
THEN
551 tmc_params=tmc_env%params)
553 tmc_params=tmc_env%params)
558 IF (tmc_env%params%DRAW_TREE) &
560 tmc_params=tmc_env%params)
567 IF (tmc_env%params%all_conf_file_name .NE.
"")
THEN
569 file_name=tmc_env%params%all_conf_file_name, &
570 tmc_params=tmc_env%params, &
571 conf_nr=nr_of_job(4))
576 CALL cancel_calculations(cancel_list=tmc_env%m_env%cancelation_list, &
577 work_list=worker_info, &
578 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
580 cancel_count=cancel_count)
582 WRITE (tmc_env%m_env%io_unit, *) &
583 "TMC|master: handled energy result of sub tree ", &
584 worker_info(wg)%elem%sub_tree_nr,
" elem ", worker_info(wg)%elem%nr, &
585 " with stat", worker_info(wg)%elem%stat
586 worker_info(wg)%elem => null()
590 IF (.NOT. (
ASSOCIATED(worker_info(wg)%elem, init_conf)) .AND. &
598 CALL cancel_calculations(cancel_list=tmc_env%m_env%cancelation_list, &
599 work_list=worker_info, &
600 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
602 cancel_count=cancel_count)
604 ana_worker_info(wg)%busy = .false.
605 ana_worker_info(wg)%elem => null()
607 cpabort(
"received message with unknown info/stat type")
609 END DO worker_request_loop
611 CALL tree_update(tmc_env=tmc_env, result_acc=flag, &
612 something_updated=l_update_tree)
613 IF (debug .GE. 2 .AND. l_update_tree) &
614 WRITE (tmc_env%m_env%io_unit, *) &
615 "TMC|master: tree updated "//
cp_to_string(l_update_tree)// &
616 " of with gt elem "//
cp_to_string(tmc_env%m_env%gt_act%nr)// &
619 CALL send_analysis_tasks(ana_list=tmc_env%m_env%analysis_list, &
620 ana_worker_info=ana_worker_info, &
621 para_env=tmc_env%tmc_comp_set%para_env_m_ana, &
630 CALL external_control(should_stop=external_stop, flag=
"TMC", globenv=globenv)
631 IF ((any(tmc_env%m_env%result_count(1:) .GE. tmc_env%m_env%num_MC_elem) &
634 tmc_env%m_env%walltime - walltime_delay - walltime_offset) .OR. &
636 WRITE (tmc_env%m_env%io_unit, fmt=
"(/,T2,A)") repeat(
"=", 79)
638 IF (.NOT. any(tmc_env%m_env%result_count(1:) &
639 .GE. tmc_env%m_env%num_MC_elem))
THEN
640 WRITE (tmc_env%m_env%io_unit, *)
"Walltime exceeded.", &
641 m_walltime() - run_time_start,
" of ", tmc_env%m_env%walltime - walltime_delay - walltime_offset, &
642 "(incl. delay", walltime_delay,
"and offset", walltime_offset,
") left"
645 IF (tmc_env%params%print_test_output) &
646 WRITE (tmc_env%m_env%io_unit, *)
"Total energy: ", &
647 tmc_env%m_env%result_list(1)%elem%potential
649 IF (tmc_env%m_env%restart_out_step .NE. 0) &
658 IF (l_update_tree)
THEN
660 WRITE (tmc_env%m_env%io_unit, *) &
661 "TMC|master: start remove elem and cancel calculation"
670 CALL cancel_calculations(cancel_list=tmc_env%m_env%cancelation_list, &
671 work_list=worker_info, &
672 cancel_count=cancel_count, &
673 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
680 worker_counter = worker_counter + 1
681 wg =
modulo(worker_counter, tmc_env%tmc_comp_set%para_env_m_w%num_pe - 1) + 1
683 IF (debug .GE. 16 .AND. all(worker_info(:)%busy)) &
684 WRITE (tmc_env%m_env%io_unit, *)
"all workers are busy"
686 IF (.NOT. worker_info(wg)%busy)
THEN
688 WRITE (tmc_env%m_env%io_unit, *) &
689 "TMC|master: search new task for worker ", wg
691 IF (tmc_env%tmc_comp_set%group_cc_nr .LE. 0)
THEN
694 new_gt_elem=gt_elem_tmp, stat=stat, &
695 react_count=reactivation_ener_count)
698 new_elem=gt_elem_tmp, &
699 reactivation_cc_count=reactivation_cc_count)
701 ELSEIF (wg .GT. tmc_env%tmc_comp_set%group_ener_nr)
THEN
706 new_elem=gt_elem_tmp, &
707 reactivation_cc_count=reactivation_cc_count)
715 new_gt_elem=gt_elem_tmp, stat=stat, &
716 react_count=reactivation_ener_count)
720 WRITE (tmc_env%m_env%io_unit, *) &
721 "TMC|master: send task with elem stat "//
cp_to_string(stat)// &
736 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
737 tmc_params=tmc_env%params, &
738 elem=gt_elem_tmp%conf(gt_elem_tmp%mv_conf)%elem)
739 nr_of_job(1) = nr_of_job(1) + 1
744 IF (tmc_env%params%DRAW_TREE) &
745 CALL create_dot_color(tree_element=gt_elem_tmp%conf(gt_elem_tmp%mv_conf)%elem, &
746 tmc_params=tmc_env%params)
749 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
750 tmc_params=tmc_env%params, &
751 elem=gt_elem_tmp%conf(gt_elem_tmp%mv_conf)%elem)
752 nr_of_job(2) = nr_of_job(2) + 1
756 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
757 tmc_params=tmc_env%params, &
758 elem=gt_elem_tmp%conf(gt_elem_tmp%mv_conf)%elem)
760 nr_of_job(1) = nr_of_job(1) + 1
765 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
766 tmc_params=tmc_env%params, &
767 elem=gt_elem_tmp%conf(gt_elem_tmp%mv_conf)%elem)
768 nr_of_job(1) = nr_of_job(1) + 1
773 CALL cp_abort(__location__, &
774 "new task of tree element"// &
778 worker_info(wg)%elem => gt_elem_tmp%conf(gt_elem_tmp%mv_conf)%elem
779 worker_info(wg)%busy = .true.
784 IF (nr_of_job(4) .GT. last_output .AND. &
785 (
modulo(nr_of_job(4), tmc_env%m_env%info_out_step_size) .EQ. 0) .AND. &
787 last_output = nr_of_job(4)
788 WRITE (tmc_env%m_env%io_unit, fmt=
"(/,T2,A)") repeat(
"-", 79)
789 WRITE (tmc_env%m_env%io_unit, *) &
790 "Tasks submitted: E ", nr_of_job(2),
", cc", nr_of_job(1)
791 WRITE (tmc_env%m_env%io_unit, *) &
792 "Results received: E ", nr_of_job(4),
", cc", nr_of_job(3)
793 WRITE (tmc_env%m_env%io_unit, *) &
794 "Configurations used:", tmc_env%m_env%result_count(0), &
795 ", sub trees", tmc_env%m_env%result_count(1:)
798 tmc_params=tmc_env%params)
799 ALLOCATE (tree_elem_counters(0:
SIZE(tmc_env%params%Temp)))
800 ALLOCATE (tree_elem_heads(0:
SIZE(tmc_env%params%Temp)))
802 end_of_clean_trees=tmc_env%m_env%st_clean_ends, &
803 counters=tree_elem_counters, head_elements_nr=tree_elem_heads)
804 WRITE (tmc_env%m_env%io_unit, *)
"nodes in trees", tree_elem_counters(:)
805 WRITE (tmc_env%m_env%io_unit, *)
"tree heads ", tree_elem_heads(:)
806 IF (tmc_env%params%NMC_inp_file .NE.
"")
THEN
808 counters=tree_elem_counters)
809 WRITE (tmc_env%m_env%io_unit, fmt=*) &
810 "ener prepared ", tree_elem_counters
812 IF (tmc_env%params%SPECULATIVE_CANCELING) &
813 WRITE (tmc_env%m_env%io_unit, *) &
814 "canceled cc|E: ", nr_of_job(5:6), &
815 ", reactivated: cc ", &
816 reactivation_cc_count, &
817 ", reactivated: E ", &
818 reactivation_ener_count
819 WRITE (tmc_env%m_env%io_unit, fmt=
'(A,2F10.2)') &
820 " Average time for cc/ener calc ", &
821 worker_timings_aver(1), worker_timings_aver(2)
822 IF (tmc_env%params%SPECULATIVE_CANCELING) &
823 WRITE (tmc_env%m_env%io_unit, fmt=
'(A,2F10.2)') &
824 " Average time until cancel cc/ener calc ", &
825 worker_timings_aver(3), worker_timings_aver(4)
826 IF (tmc_env%params%esimate_acc_prob) &
827 WRITE (tmc_env%m_env%io_unit, *) &
828 "Estimate correct (acc/Nacc) | wrong (acc/nacc)", &
829 tmc_env%m_env%estim_corr_wrong(1), &
830 tmc_env%m_env%estim_corr_wrong(3),
" | ", &
831 tmc_env%m_env%estim_corr_wrong(2), &
832 tmc_env%m_env%estim_corr_wrong(4)
833 WRITE (tmc_env%m_env%io_unit, *) &
834 "Time: ", int(
m_walltime() - run_time_start),
"of", &
835 int(tmc_env%m_env%walltime - walltime_delay - walltime_offset), &
838 WRITE (tmc_env%m_env%io_unit, *) &
839 "Memory used: ", int(mem/(1024*1024), kind=kind(0)),
"MiBytes"
840 CALL m_flush(tmc_env%m_env%io_unit)
841 DEALLOCATE (tree_elem_heads)
842 DEALLOCATE (tree_elem_counters)
845 IF (tmc_env%m_env%restart_out_step .GT. 0 .AND. &
846 tmc_env%m_env%result_count(0) .GT. &
847 restart_count*tmc_env%m_env%restart_out_step)
THEN
850 restart_count = restart_count + 1
857 WRITE (tmc_env%m_env%io_unit, fmt=
"(/,T2,A)") repeat(
"=", 79)
858 WRITE (unit=tmc_env%m_env%io_unit, fmt=
"(T2,A,T35,A,T80,A)")
"=", &
859 "finalizing TMC",
"="
860 WRITE (tmc_env%m_env%io_unit, *)
"acceptance rates:"
862 tmc_params=tmc_env%params)
863 WRITE (tmc_env%m_env%io_unit, fmt=
"(/,T2,A)") repeat(
"-", 79)
865 ALLOCATE (efficiency(0:tmc_env%params%nr_temp))
867 WRITE (tmc_env%m_env%io_unit, *)
"Efficiencies:"
868 WRITE (tmc_env%m_env%io_unit, fmt=
"(A,F5.2,A,1000F5.2)") &
869 " (MC elements/calculated configuration) global:", &
870 efficiency(0),
" sub tree(s): ", efficiency(1:)
871 DEALLOCATE (efficiency)
872 IF (tmc_env%tmc_comp_set%group_cc_nr .GT. 0) &
873 WRITE (tmc_env%m_env%io_unit, fmt=
"(A,1000F5.2)") &
874 " (MC elements/created configuration) :", &
875 tmc_env%m_env%result_count(:)/real(nr_of_job(3), kind=
dp)
876 WRITE (tmc_env%m_env%io_unit, fmt=
"(A,1000F5.2)") &
877 " (MC elements/energy calculated configuration):", &
878 tmc_env%m_env%result_count(:)/real(nr_of_job(4), kind=
dp)
879 IF (tmc_env%params%NMC_inp_file .NE.
"")
THEN
880 WRITE (tmc_env%m_env%io_unit, *) &
881 "Amount of canceled elements (E/cc):", &
882 tmc_env%m_env%count_cancel_ener, tmc_env%m_env%count_cancel_NMC
883 WRITE (tmc_env%m_env%io_unit, *) &
884 " reactivated E ", reactivation_ener_count
885 WRITE (tmc_env%m_env%io_unit, *) &
886 " reactivated cc ", reactivation_cc_count
888 WRITE (tmc_env%m_env%io_unit, fmt=
"(A,F10.2)") &
889 " computing time of one Markov chain element ", &
890 (
m_walltime() - run_time_start)/real(tmc_env%m_env%result_count(0) - &
891 restarted_elem_nr, kind=
dp)
892 WRITE (tmc_env%m_env%io_unit, fmt=
"(A,F10.2)")
" TMC run time[s]: ",
m_walltime() - run_time_start
893 WRITE (tmc_env%m_env%io_unit, fmt=
"(/,T2,A)") repeat(
"=", 79)
896 WRITE (tmc_env%m_env%io_unit, *)
"stopping workers"
898 worker_info=worker_info, &
899 tmc_params=tmc_env%params)
900 DEALLOCATE (worker_info)
902 worker_info=ana_worker_info, &
903 tmc_params=tmc_env%params)
904 DEALLOCATE (ana_worker_info)
912 IF (tmc_env%params%DRAW_TREE) &
915 WRITE (tmc_env%m_env%io_unit, *)
"TMC master: all work done."
918 CALL timestop(handle)