215 CHARACTER(LEN=*),
PARAMETER :: routinen =
'do_tmc_master'
217 INTEGER :: cancel_count, handle, last_output, reactivation_cc_count, &
218 reactivation_ener_count, restart_count, restarted_elem_nr, stat, walltime_delay, &
219 walltime_offset, wg, worker_counter
220 INTEGER(KIND=int_8) :: mem
221 INTEGER,
DIMENSION(6) :: nr_of_job
222 INTEGER,
DIMENSION(:),
POINTER :: tree_elem_counters, tree_elem_heads
223 LOGICAL :: external_stop, flag, l_update_tree
224 REAL(kind=
dp) :: run_time_start
225 REAL(kind=
dp),
DIMENSION(4) :: worker_timings_aver
226 REAL(kind=
dp),
DIMENSION(:),
POINTER :: efficiency
227 TYPE(
elem_array_type),
DIMENSION(:),
POINTER :: ana_worker_info, worker_info
231 external_stop = .false.
232 restarted_elem_nr = 0
233 NULLIFY (init_conf, worker_info, ana_worker_info, gt_elem_tmp, tree_elem_counters)
235 cpassert(
ASSOCIATED(tmc_env))
237 cpassert(tmc_env%tmc_comp_set%group_nr == 0)
238 cpassert(
ASSOCIATED(tmc_env%tmc_comp_set))
239 cpassert(
ASSOCIATED(tmc_env%tmc_comp_set%para_env_m_w))
241 cpassert(
ASSOCIATED(tmc_env%m_env))
245 CALL timeset(routinen, handle)
251 IF (tmc_env%params%DRAW_TREE)
THEN
260 reactivation_ener_count = 0
261 reactivation_cc_count = 0
263 tmc_env%m_env%result_count = 0
264 l_update_tree = .false.
269 worker_timings_aver(:) = 0.0_dp
272 ALLOCATE (worker_info(tmc_env%tmc_comp_set%para_env_m_w%num_pe - 1))
273 ALLOCATE (ana_worker_info(tmc_env%tmc_comp_set%para_env_m_ana%num_pe - 1))
280 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
281 tmc_params=tmc_env%params, &
282 wait_for_message=.true.)
286 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
287 tmc_params=tmc_env%params, &
288 elem=init_conf, success=flag, wait_for_message=.true.)
290 CALL cp_abort(__location__, &
291 "receiving start configuration failed, received stat "// &
297 para_env=tmc_env%tmc_comp_set%para_env_m_first_w)
303 move_types=tmc_env%params%move_types, &
304 mol_array=init_conf%mol)
305 IF (
ASSOCIATED(tmc_env%params%nmc_move_types))
THEN
307 move_types=tmc_env%params%nmc_move_types, &
308 mol_array=init_conf%mol)
316 job_counts=nr_of_job, &
317 worker_timings=worker_timings_aver)
320 IF (tmc_env%m_env%restart_out_step /= 0)
THEN
321 restart_count = int(tmc_env%m_env%result_count(0)/ &
322 REAL(tmc_env%m_env%restart_out_step, kind=
dp)) + 1
324 restarted_elem_nr = tmc_env%m_env%result_count(0)
329 DO wg = 1, tmc_env%tmc_comp_set%para_env_m_w%num_pe - 1
332 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
333 tmc_params=tmc_env%params)
337 IF (tmc_env%tmc_comp_set%para_env_m_ana%num_pe > 1)
THEN
338 DO wg = 1, tmc_env%tmc_comp_set%para_env_m_ana%num_pe - 1
341 para_env=tmc_env%tmc_comp_set%para_env_m_ana, &
342 result_count=tmc_env%m_env%result_count, &
343 tmc_params=tmc_env%params, &
345 wait_for_message=.true.)
349 para_env=tmc_env%tmc_comp_set%para_env_m_ana)
355 IF (tmc_env%params%print_test_output .OR. debug > 0)
THEN
356 WRITE (tmc_env%m_env%io_unit, *)
"TMC|first_global_tree_rnd_nr_X= ", &
357 tmc_env%m_env%gt_head%rnd_nr
363 IF (tmc_env%tmc_comp_set%group_cc_nr > 0)
THEN
364 wg = tmc_env%tmc_comp_set%group_ener_nr + 1
368 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
369 tmc_params=tmc_env%params, &
370 elem=tmc_env%m_env%gt_head%conf(1)%elem)
371 worker_info(wg)%busy = .true.
372 worker_info(wg)%elem => tmc_env%m_env%gt_head%conf(1)%elem
373 init_conf => tmc_env%m_env%gt_head%conf(1)%elem
374 ELSE IF (tmc_env%m_env%gt_head%conf(1)%elem%stat ==
status_created)
THEN
375 init_conf => tmc_env%m_env%gt_head%conf(1)%elem
389 worker_request_loop:
DO
393 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
394 tmc_params=tmc_env%params, &
395 elem_array=worker_info(:), success=flag)
397 IF (flag .EQV. .false.)
EXIT worker_request_loop
401 WRITE (tmc_env%m_env%io_unit, *) &
403 " of canceled worker group"
405 cycle worker_request_loop
410 IF (.NOT.
ASSOCIATED(worker_info(wg)%elem))
THEN
411 CALL cp_abort(__location__, &
412 "no tree elem exist when receiving stat "// &
417 WRITE (tmc_env%m_env%io_unit, *) &
419 " of sub tree "//
cp_to_string(worker_info(wg)%elem%sub_tree_nr)// &
421 " with stat"//
cp_to_string(worker_info(wg)%elem%stat)// &
422 " of group"//
cp_to_string(wg)//
" group canceled ", worker_info(wg)%canceled
431 cpassert(worker_info(wg)%canceled)
432 worker_info(wg)%canceled = .false.
433 worker_info(wg)%busy = .false.
435 IF (
ASSOCIATED(worker_info(wg)%elem))
THEN
436 SELECT CASE (worker_info(wg)%elem%stat)
439 worker_timings_aver(4) = (worker_timings_aver(4)*nr_of_job(6) + &
440 (
m_walltime() - worker_info(wg)%start_time))/real(nr_of_job(6) + 1, kind=
dp)
441 nr_of_job(6) = nr_of_job(6) + 1
444 worker_info(wg)%elem%potential = 8000.0_dp
445 IF (tmc_env%params%DRAW_TREE)
THEN
447 tmc_params=tmc_env%params)
451 worker_timings_aver(3) = (worker_timings_aver(3)*nr_of_job(5) + &
452 (
m_walltime() - worker_info(wg)%start_time))/real(nr_of_job(5) + 1, kind=
dp)
453 nr_of_job(5) = nr_of_job(5) + 1
456 worker_info(wg)%elem%potential = 8000.0_dp
457 IF (tmc_env%params%DRAW_TREE)
THEN
459 tmc_params=tmc_env%params)
464 worker_info(wg)%elem => null()
469 cpabort(
"TMC_STAT_START_CONF_RESULT is invalid")
472 nr_of_job(3) = nr_of_job(3) + 1
473 worker_info(wg)%busy = .false.
475 IF (tmc_env%params%DRAW_TREE)
THEN
477 tmc_params=tmc_env%params)
479 worker_info(wg)%elem => null()
484 IF (.NOT. worker_info(wg)%canceled) worker_info(wg)%busy = .false.
486 worker_timings_aver(1) = (worker_timings_aver(1)*nr_of_job(3) + &
487 (
m_walltime() - worker_info(wg)%start_time))/real(nr_of_job(3) + 1, kind=
dp)
488 nr_of_job(3) = nr_of_job(3) + 1
490 worker_info(wg)%start_time =
m_walltime() - worker_info(wg)%start_time
491 CALL set_walltime_delay(worker_info(wg)%start_time, walltime_delay)
493 IF (tmc_env%params%DRAW_TREE)
THEN
495 tmc_params=tmc_env%params)
499 IF (tmc_env%params%NMC_inp_file ==
"")
THEN
500 worker_info(wg)%elem%potential = worker_info(wg)%elem%e_pot_approx
503 IF (.NOT. (
ASSOCIATED(worker_info(wg)%elem, init_conf)))
THEN
507 IF (tmc_env%params%DRAW_TREE)
THEN
509 tmc_params=tmc_env%params)
512 CALL cancel_calculations(cancel_list=tmc_env%m_env%cancelation_list, &
513 work_list=worker_info, &
514 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
516 cancel_count=cancel_count)
517 worker_info(wg)%elem => null()
520 IF (tmc_env%tmc_comp_set%group_cc_nr <= 0 &
521 .AND. (.NOT. worker_info(wg)%canceled))
THEN
526 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
527 tmc_params=tmc_env%params, &
528 elem=worker_info(wg)%elem)
529 worker_info(wg)%busy = .true.
530 nr_of_job(2) = nr_of_job(2) + 1
531 IF (tmc_env%params%DRAW_TREE)
THEN
533 tmc_params=tmc_env%params)
538 worker_info(wg)%elem => null()
544 worker_timings_aver(2) = (worker_timings_aver(2)*nr_of_job(4) + &
545 (
m_walltime() - worker_info(wg)%start_time))/real(nr_of_job(4) + 1, kind=
dp)
546 nr_of_job(4) = nr_of_job(4) + 1
548 worker_info(wg)%start_time =
m_walltime() - worker_info(wg)%start_time
549 CALL set_walltime_delay(worker_info(wg)%start_time, walltime_delay)
551 IF (.NOT. worker_info(wg)%canceled)
THEN
552 worker_info(wg)%busy = .false.
555 IF (
ASSOCIATED(worker_info(wg)%elem, init_conf))
THEN
559 IF (tmc_env%params%DRAW_TREE)
THEN
561 tmc_params=tmc_env%params)
563 tmc_params=tmc_env%params)
568 IF (tmc_env%params%DRAW_TREE)
THEN
570 tmc_params=tmc_env%params)
578 IF (tmc_env%params%all_conf_file_name /=
"")
THEN
580 file_name=tmc_env%params%all_conf_file_name, &
581 tmc_params=tmc_env%params, &
582 conf_nr=nr_of_job(4))
587 CALL cancel_calculations(cancel_list=tmc_env%m_env%cancelation_list, &
588 work_list=worker_info, &
589 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
591 cancel_count=cancel_count)
593 WRITE (tmc_env%m_env%io_unit, *) &
594 "TMC|master: handled energy result of sub tree ", &
595 worker_info(wg)%elem%sub_tree_nr,
" elem ", worker_info(wg)%elem%nr, &
596 " with stat", worker_info(wg)%elem%stat
598 worker_info(wg)%elem => null()
602 IF (.NOT. (
ASSOCIATED(worker_info(wg)%elem, init_conf)) .AND. &
610 CALL cancel_calculations(cancel_list=tmc_env%m_env%cancelation_list, &
611 work_list=worker_info, &
612 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
614 cancel_count=cancel_count)
616 ana_worker_info(wg)%busy = .false.
617 ana_worker_info(wg)%elem => null()
619 cpabort(
"received message with unknown info/stat type")
621 END DO worker_request_loop
623 CALL tree_update(tmc_env=tmc_env, result_acc=flag, &
624 something_updated=l_update_tree)
625 IF (debug >= 2 .AND. l_update_tree)
THEN
626 WRITE (tmc_env%m_env%io_unit, *) &
627 "TMC|master: tree updated "//
cp_to_string(l_update_tree)// &
628 " of with gt elem "//
cp_to_string(tmc_env%m_env%gt_act%nr)// &
632 CALL send_analysis_tasks(ana_list=tmc_env%m_env%analysis_list, &
633 ana_worker_info=ana_worker_info, &
634 para_env=tmc_env%tmc_comp_set%para_env_m_ana, &
643 CALL external_control(should_stop=external_stop, flag=
"TMC", globenv=globenv)
644 IF ((any(tmc_env%m_env%result_count(1:) >= tmc_env%m_env%num_MC_elem) &
647 tmc_env%m_env%walltime - walltime_delay - walltime_offset) .OR. &
649 WRITE (tmc_env%m_env%io_unit, fmt=
"(/,T2,A)") repeat(
"=", 79)
651 IF (.NOT. any(tmc_env%m_env%result_count(1:) &
652 >= tmc_env%m_env%num_MC_elem))
THEN
653 WRITE (tmc_env%m_env%io_unit, *)
"Walltime exceeded.", &
654 m_walltime() - run_time_start,
" of ", tmc_env%m_env%walltime - walltime_delay - walltime_offset, &
655 "(incl. delay", walltime_delay,
"and offset", walltime_offset,
") left"
658 IF (tmc_env%params%print_test_output)
THEN
659 WRITE (tmc_env%m_env%io_unit, *)
"Total energy: ", &
660 tmc_env%m_env%result_list(1)%elem%potential
663 IF (tmc_env%m_env%restart_out_step /= 0)
THEN
673 IF (l_update_tree)
THEN
675 WRITE (tmc_env%m_env%io_unit, *) &
676 "TMC|master: start remove elem and cancel calculation"
686 CALL cancel_calculations(cancel_list=tmc_env%m_env%cancelation_list, &
687 work_list=worker_info, &
688 cancel_count=cancel_count, &
689 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
696 worker_counter = worker_counter + 1
697 wg =
modulo(worker_counter, tmc_env%tmc_comp_set%para_env_m_w%num_pe - 1) + 1
699 IF (debug >= 16 .AND. all(worker_info(:)%busy))
THEN
700 WRITE (tmc_env%m_env%io_unit, *)
"all workers are busy"
703 IF (.NOT. worker_info(wg)%busy)
THEN
704 IF (debug >= 13)
THEN
705 WRITE (tmc_env%m_env%io_unit, *) &
706 "TMC|master: search new task for worker ", wg
709 IF (tmc_env%tmc_comp_set%group_cc_nr <= 0)
THEN
712 new_gt_elem=gt_elem_tmp, stat=stat, &
713 react_count=reactivation_ener_count)
716 new_elem=gt_elem_tmp, &
717 reactivation_cc_count=reactivation_cc_count)
719 ELSE IF (wg > tmc_env%tmc_comp_set%group_ener_nr)
THEN
724 new_elem=gt_elem_tmp, &
725 reactivation_cc_count=reactivation_cc_count)
734 new_gt_elem=gt_elem_tmp, stat=stat, &
735 react_count=reactivation_ener_count)
738 IF (debug >= 10)
THEN
739 WRITE (tmc_env%m_env%io_unit, *) &
740 "TMC|master: send task with elem stat "//
cp_to_string(stat)// &
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)
759 nr_of_job(1) = nr_of_job(1) + 1
764 IF (tmc_env%params%DRAW_TREE)
THEN
765 CALL create_dot_color(tree_element=gt_elem_tmp%conf(gt_elem_tmp%mv_conf)%elem, &
766 tmc_params=tmc_env%params)
770 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
771 tmc_params=tmc_env%params, &
772 elem=gt_elem_tmp%conf(gt_elem_tmp%mv_conf)%elem)
773 nr_of_job(2) = nr_of_job(2) + 1
777 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
778 tmc_params=tmc_env%params, &
779 elem=gt_elem_tmp%conf(gt_elem_tmp%mv_conf)%elem)
781 nr_of_job(1) = nr_of_job(1) + 1
786 para_env=tmc_env%tmc_comp_set%para_env_m_w, &
787 tmc_params=tmc_env%params, &
788 elem=gt_elem_tmp%conf(gt_elem_tmp%mv_conf)%elem)
789 nr_of_job(1) = nr_of_job(1) + 1
794 CALL cp_abort(__location__, &
795 "new task of tree element"// &
799 worker_info(wg)%elem => gt_elem_tmp%conf(gt_elem_tmp%mv_conf)%elem
800 worker_info(wg)%busy = .true.
805 IF (nr_of_job(4) > last_output .AND. &
806 (
modulo(nr_of_job(4), tmc_env%m_env%info_out_step_size) == 0) .AND. &
808 last_output = nr_of_job(4)
809 WRITE (tmc_env%m_env%io_unit, fmt=
"(/,T2,A)") repeat(
"-", 79)
810 WRITE (tmc_env%m_env%io_unit, *) &
811 "Tasks submitted: E ", nr_of_job(2),
", cc", nr_of_job(1)
812 WRITE (tmc_env%m_env%io_unit, *) &
813 "Results received: E ", nr_of_job(4),
", cc", nr_of_job(3)
814 WRITE (tmc_env%m_env%io_unit, *) &
815 "Configurations used:", tmc_env%m_env%result_count(0), &
816 ", sub trees", tmc_env%m_env%result_count(1:)
819 tmc_params=tmc_env%params)
820 ALLOCATE (tree_elem_counters(0:
SIZE(tmc_env%params%Temp)))
821 ALLOCATE (tree_elem_heads(0:
SIZE(tmc_env%params%Temp)))
823 end_of_clean_trees=tmc_env%m_env%st_clean_ends, &
824 counters=tree_elem_counters, head_elements_nr=tree_elem_heads)
825 WRITE (tmc_env%m_env%io_unit, *)
"nodes in trees", tree_elem_counters(:)
826 WRITE (tmc_env%m_env%io_unit, *)
"tree heads ", tree_elem_heads(:)
827 IF (tmc_env%params%NMC_inp_file /=
"")
THEN
829 counters=tree_elem_counters)
830 WRITE (tmc_env%m_env%io_unit, fmt=*) &
831 "ener prepared ", tree_elem_counters
833 IF (tmc_env%params%SPECULATIVE_CANCELING)
THEN
834 WRITE (tmc_env%m_env%io_unit, *) &
835 "canceled cc|E: ", nr_of_job(5:6), &
836 ", reactivated: cc ", &
837 reactivation_cc_count, &
838 ", reactivated: E ", &
839 reactivation_ener_count
841 WRITE (tmc_env%m_env%io_unit, fmt=
'(A,2F10.2)') &
842 " Average time for cc/ener calc ", &
843 worker_timings_aver(1), worker_timings_aver(2)
844 IF (tmc_env%params%SPECULATIVE_CANCELING)
THEN
845 WRITE (tmc_env%m_env%io_unit, fmt=
'(A,2F10.2)') &
846 " Average time until cancel cc/ener calc ", &
847 worker_timings_aver(3), worker_timings_aver(4)
849 IF (tmc_env%params%esimate_acc_prob)
THEN
850 WRITE (tmc_env%m_env%io_unit, *) &
851 "Estimate correct (acc/Nacc) | wrong (acc/nacc)", &
852 tmc_env%m_env%estim_corr_wrong(1), &
853 tmc_env%m_env%estim_corr_wrong(3),
" | ", &
854 tmc_env%m_env%estim_corr_wrong(2), &
855 tmc_env%m_env%estim_corr_wrong(4)
857 WRITE (tmc_env%m_env%io_unit, *) &
858 "Time: ", int(
m_walltime() - run_time_start),
"of", &
859 int(tmc_env%m_env%walltime - walltime_delay - walltime_offset), &
862 WRITE (tmc_env%m_env%io_unit, *) &
863 "Memory used: ", int(mem/(1024*1024), kind=kind(0)),
"MiBytes"
864 CALL m_flush(tmc_env%m_env%io_unit)
865 DEALLOCATE (tree_elem_heads)
866 DEALLOCATE (tree_elem_counters)
869 IF (tmc_env%m_env%restart_out_step > 0 .AND. &
870 tmc_env%m_env%result_count(0) > &
871 restart_count*tmc_env%m_env%restart_out_step)
THEN
874 restart_count = restart_count + 1
881 WRITE (tmc_env%m_env%io_unit, fmt=
"(/,T2,A)") repeat(
"=", 79)
882 WRITE (unit=tmc_env%m_env%io_unit, fmt=
"(T2,A,T35,A,T80,A)")
"=", &
883 "finalizing TMC",
"="
884 WRITE (tmc_env%m_env%io_unit, *)
"acceptance rates:"
886 tmc_params=tmc_env%params)
887 WRITE (tmc_env%m_env%io_unit, fmt=
"(/,T2,A)") repeat(
"-", 79)
889 ALLOCATE (efficiency(0:tmc_env%params%nr_temp))
891 WRITE (tmc_env%m_env%io_unit, *)
"Efficiencies:"
892 WRITE (tmc_env%m_env%io_unit, fmt=
"(A,F5.2,A,1000F5.2)") &
893 " (MC elements/calculated configuration) global:", &
894 efficiency(0),
" sub tree(s): ", efficiency(1:)
895 DEALLOCATE (efficiency)
896 IF (tmc_env%tmc_comp_set%group_cc_nr > 0)
THEN
897 WRITE (tmc_env%m_env%io_unit, fmt=
"(A,1000F5.2)") &
898 " (MC elements/created configuration) :", &
899 tmc_env%m_env%result_count(:)/real(nr_of_job(3), kind=
dp)
901 WRITE (tmc_env%m_env%io_unit, fmt=
"(A,1000F5.2)") &
902 " (MC elements/energy calculated configuration):", &
903 tmc_env%m_env%result_count(:)/real(nr_of_job(4), kind=
dp)
904 IF (tmc_env%params%NMC_inp_file /=
"")
THEN
905 WRITE (tmc_env%m_env%io_unit, *) &
906 "Amount of canceled elements (E/cc):", &
907 tmc_env%m_env%count_cancel_ener, tmc_env%m_env%count_cancel_NMC
908 WRITE (tmc_env%m_env%io_unit, *) &
909 " reactivated E ", reactivation_ener_count
910 WRITE (tmc_env%m_env%io_unit, *) &
911 " reactivated cc ", reactivation_cc_count
913 WRITE (tmc_env%m_env%io_unit, fmt=
"(A,F10.2)") &
914 " computing time of one Markov chain element ", &
915 (
m_walltime() - run_time_start)/real(tmc_env%m_env%result_count(0) - &
916 restarted_elem_nr, kind=
dp)
917 WRITE (tmc_env%m_env%io_unit, fmt=
"(A,F10.2)")
" TMC run time[s]: ",
m_walltime() - run_time_start
918 WRITE (tmc_env%m_env%io_unit, fmt=
"(/,T2,A)") repeat(
"=", 79)
921 WRITE (tmc_env%m_env%io_unit, *)
"stopping workers"
923 worker_info=worker_info, &
924 tmc_params=tmc_env%params)
925 DEALLOCATE (worker_info)
927 worker_info=ana_worker_info, &
928 tmc_params=tmc_env%params)
929 DEALLOCATE (ana_worker_info)
937 IF (tmc_env%params%DRAW_TREE)
THEN
941 WRITE (tmc_env%m_env%io_unit, *)
"TMC master: all work done."
944 CALL timestop(handle)