(git:1f285aa)
tmc_setup.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 ! **************************************************************************************************
9 !> \brief Tree Monte Carlo entry point, set up, CPU redistribution and
10 !> input reading
11 !> \par History
12 !> 11.2012 created [Mandes Schoenherr]
13 !> \author Mandes
14 ! **************************************************************************************************
15 
16 MODULE tmc_setup
17  USE bibliography, ONLY: cite_reference,&
19  USE cp_files, ONLY: close_file,&
20  open_file
21  USE cp_log_handling, ONLY: &
24  cp_rm_default_logger, cp_to_string
26  USE f77_interface, ONLY: create_force_env,&
28  USE global_types, ONLY: global_environment_type
29  USE header, ONLY: tmc_ana_header,&
31  USE input_section_types, ONLY: section_type,&
34  section_vals_type,&
36  USE kinds, ONLY: default_path_length,&
38  dp
39  USE machine, ONLY: default_output_unit,&
40  m_flush
41  USE message_passing, ONLY: mp_para_env_type
42  USE parallel_rng_types, ONLY: uniform,&
43  rng_stream_type
44  USE physcon, ONLY: au2a => angstrom,&
45  au2bar => bar
46  USE tmc_analysis, ONLY: analysis_init,&
53  tmc_ana_list_type
55  USE tmc_master, ONLY: do_tmc_master
59  USE tmc_stati, ONLY: &
65  USE tmc_tree_types, ONLY: tree_type
66  USE tmc_types, ONLY: tmc_comp_set_type,&
69  tmc_env_type,&
74  USE tmc_worker, ONLY: do_tmc_worker,&
77 #include "../base/base_uses.f90"
78 
79  IMPLICIT NONE
80 
81  PRIVATE
82 
83  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'tmc_setup'
84 
85  PUBLIC :: do_tmc, do_analyze_files
86 
87 CONTAINS
88 
89 ! **************************************************************************************************
90 !> \brief tmc_entry point
91 !> \param input_declaration ...
92 !> \param root_section ...
93 !> \param para_env ...
94 !> \param globenv the global environment for the simulation
95 !> \author Mandes 11.2012
96 ! **************************************************************************************************
97  SUBROUTINE do_tmc(input_declaration, root_section, para_env, globenv)
98  TYPE(section_type), POINTER :: input_declaration
99  TYPE(section_vals_type), POINTER :: root_section
100  TYPE(mp_para_env_type), POINTER :: para_env
101  TYPE(global_environment_type), POINTER :: globenv
102 
103  CHARACTER(LEN=*), PARAMETER :: routinen = 'do_tmc'
104 
105  INTEGER :: bcast_output_unit, handle, i, ierr, &
106  output_unit
107  LOGICAL :: init_rng, success
108  REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: init_rng_seed
109  TYPE(cp_logger_type), POINTER :: logger, logger_sub
110  TYPE(section_vals_type), POINTER :: tmc_ana_section
111  TYPE(tmc_ana_list_type), DIMENSION(:), POINTER :: tmc_ana_env_list
112  TYPE(tmc_env_type), POINTER :: tmc_env
113 
114 ! start the timing
115 
116  CALL timeset(routinen, handle)
117 
118  CALL cite_reference(schonherr2014)
119 
120  NULLIFY (logger, logger_sub, tmc_env, tmc_ana_env_list)
121  logger => cp_get_default_logger()
122  output_unit = cp_logger_get_default_io_unit(logger)
123 
124  ! write header, on the 'rank 0' of the global communicator
125  IF (output_unit > 0) THEN
126  CALL tmc_header(output_unit)
127  CALL m_flush(output_unit)
128  END IF
129  ! ugly, we need to know the output unit on source, everywhere, in particular
130  ! the tmc master
131  IF (output_unit .NE. default_output_unit .AND. output_unit .GT. 0) THEN
132  WRITE (unit=output_unit, fmt="(/,T2,A)") repeat("-", 79)
133  WRITE (unit=output_unit, fmt="(/,T2,A)") "The TMC output files are:"
134  WRITE (unit=output_unit, fmt="(/,T2,A)") &
135  trim(tmc_master_out_file_name)//" the TMC master"
136  WRITE (unit=output_unit, fmt="(/,T2,A)") &
137  trim(tmc_energy_worker_out_file_name)//" the worker outputs (energy calculations etc.)"
138  WRITE (unit=output_unit, fmt="(/,T2,A)") &
139  trim(tmc_ana_out_file_name)//" the analysis output"
140  WRITE (unit=output_unit, fmt="(/,T2,A)") repeat("-", 79)
141  END IF
142  bcast_output_unit = output_unit
143  CALL para_env%bcast(bcast_output_unit)
144 
145  ! create tmc_env
146  CALL tmc_env_create(tmc_env)
147  CALL tmc_preread_input(root_section, tmc_env)
148  CALL tmc_redistributing_cores(tmc_env%tmc_comp_set, para_env, &
149  ana_on_the_fly=tmc_env%tmc_comp_set%ana_on_the_fly, &
150  success=success)
151 
152  IF (success) THEN
153  ! initialize master and worker environment
154  IF (tmc_env%tmc_comp_set%group_nr .EQ. 0) THEN
155  CALL tmc_master_env_create(tmc_env) ! create master env
156  ELSE IF (tmc_env%tmc_comp_set%group_nr .NE. 0) THEN
157  CALL tmc_worker_env_create(tmc_env) ! create worker env
158  END IF
159 
160  CALL tmc_read_input(root_section, tmc_env)
161  !CALL init_move_types(tmc_params=tmc_env%params)
162 
163  ! init random number generator: use determistic random numbers
164  init_rng = .true.
165  IF (tmc_env%tmc_comp_set%group_nr .EQ. 0) THEN
166  IF (tmc_env%m_env%rnd_init .GT. 0) THEN
167  init_rng = .false.
168  ALLOCATE (init_rng_seed(3, 2))
169  init_rng_seed(:, :) = &
170  reshape((/tmc_env%m_env%rnd_init*42.0_dp, &
171  tmc_env%m_env%rnd_init*54.0_dp, &
172  tmc_env%m_env%rnd_init*63.0_dp, &
173  tmc_env%m_env%rnd_init*98.0_dp, &
174  tmc_env%m_env%rnd_init*10.0_dp, &
175  tmc_env%m_env%rnd_init*2.0_dp/), &
176  (/3, 2/))
177  tmc_env%rng_stream = rng_stream_type( &
178  name="TMC_deterministic_rng_stream", &
179  seed=init_rng_seed(:, :), &
180  distribution_type=uniform)
181  DEALLOCATE (init_rng_seed)
182  END IF
183  END IF
184  IF (init_rng) THEN
185  tmc_env%rng_stream = rng_stream_type( &
186  name="TMC_rng_stream", &
187  distribution_type=uniform)
188  END IF
189 
190  ! start running master and worker routines
191  ! the master
192  IF (tmc_env%tmc_comp_set%group_nr .EQ. 0) THEN
193  !TODO get the correct usage of creating and handling the logger...
194  CALL cp_logger_create(logger_sub, para_env=tmc_env%tmc_comp_set%para_env_m_only, &
195  default_global_unit_nr=default_output_unit, close_global_unit_on_dealloc=.false.)
196  CALL cp_logger_set(logger_sub, local_filename="tmc_main")
197  CALL cp_add_default_logger(logger_sub)
198 
199  ! if we're doing output to the screen, keep it there, else this master
200  ! opens a file (not that two different ranks are writing to the
201  ! default_output_unit, we leave it up to mpirun or so to merge stuff
202  IF (bcast_output_unit == default_output_unit) THEN
203  tmc_env%m_env%io_unit = default_output_unit
204  ELSE
205  CALL open_file(file_name=tmc_master_out_file_name, file_status="UNKNOWN", &
206  file_action="WRITE", file_position="APPEND", &
207  unit_number=tmc_env%m_env%io_unit)
208  CALL tmc_header(tmc_env%m_env%io_unit)
209  END IF
210  ! print the intresting parameters and starting values
211  CALL tmc_print_params(tmc_env)
212  CALL print_move_types(init=.true., file_io=tmc_env%m_env%io_unit, &
213  tmc_params=tmc_env%params)
214  CALL do_tmc_master(tmc_env=tmc_env, globenv=globenv) ! start the master routine
215 
216  IF (bcast_output_unit .NE. tmc_env%m_env%io_unit) THEN
217  CALL close_file(unit_number=tmc_env%m_env%io_unit)
218  END IF
219 
220  CALL cp_rm_default_logger()
221  CALL cp_logger_release(logger_sub)
222 
223  ! the worker groups
224  ELSE IF (tmc_env%tmc_comp_set%group_nr .GT. 0) THEN
225  NULLIFY (logger_sub)
226  ! create separate logger and error handler for each worker
227  CALL cp_logger_create(logger_sub, para_env=tmc_env%tmc_comp_set%para_env_sub_group, &
228  default_global_unit_nr=default_output_unit, close_global_unit_on_dealloc=.false.)
229  CALL cp_logger_set(logger_sub, local_filename="tmc_localLog")
230  CALL cp_add_default_logger(logger_sub)
231  tmc_env%w_env%io_unit = default_output_unit
232 
233  ! energy worker
234  IF (tmc_env%tmc_comp_set%group_nr .LE. tmc_env%tmc_comp_set%group_ener_nr) THEN
235  CALL create_force_env(new_env_id=tmc_env%w_env%env_id_ener, &
236  input_declaration=input_declaration, &
237  input_path=tmc_env%params%energy_inp_file, &
238  mpi_comm=tmc_env%tmc_comp_set%para_env_sub_group, &
239  output_path=trim(expand_file_name_int(file_name=tmc_energy_worker_out_file_name, &
240  ivalue=tmc_env%tmc_comp_set%group_nr)), &
241  ierr=ierr)
242  IF (ierr .NE. 0) &
243  cpabort("creating force env result in error "//cp_to_string(ierr))
244  END IF
245  ! worker for configurational change
246  IF (tmc_env%params%NMC_inp_file .NE. "" .AND. &
247  (tmc_env%tmc_comp_set%group_cc_nr .EQ. 0 .OR. &
248  tmc_env%tmc_comp_set%group_nr .GT. tmc_env%tmc_comp_set%group_ener_nr)) THEN
249  CALL create_force_env(new_env_id=tmc_env%w_env%env_id_approx, &
250  input_declaration=input_declaration, &
251  input_path=tmc_env%params%NMC_inp_file, &
252  mpi_comm=tmc_env%tmc_comp_set%para_env_sub_group, &
253  output_path=trim(expand_file_name_int(file_name=tmc_nmc_worker_out_file_name, &
254  ivalue=tmc_env%tmc_comp_set%group_nr)), &
255  ierr=ierr)
256  IF (ierr .NE. 0) &
257  cpabort("creating approx force env result in error "//cp_to_string(ierr))
258  END IF
259  CALL do_tmc_worker(tmc_env=tmc_env) ! start the worker routine
260 
261  IF (tmc_env%w_env%env_id_ener .GT. 0) &
262  CALL destroy_force_env(tmc_env%w_env%env_id_ener, ierr)
263  IF (tmc_env%w_env%env_id_approx .GT. 0) &
264  CALL destroy_force_env(tmc_env%w_env%env_id_approx, ierr)
265 
266  CALL cp_rm_default_logger()
267  CALL cp_logger_release(logger_sub)
268 
269  ! the analysis group
270  ELSE IF (ASSOCIATED(tmc_env%tmc_comp_set%para_env_m_ana)) THEN
271  ! unused worker groups can do analysis
272  NULLIFY (logger_sub)
273  ! create separate logger and error handler for each worker
274  CALL cp_logger_create(logger_sub, para_env=tmc_env%tmc_comp_set%para_env_m_ana, &
275  default_global_unit_nr=default_output_unit, close_global_unit_on_dealloc=.false.)
276  tmc_env%w_env%io_unit = default_output_unit
277  CALL cp_logger_set(logger_sub, local_filename="tmc_ana_localLog")
278  CALL cp_add_default_logger(logger_sub)
279  ! if we're doing output to the screen, keep it there, else this master
280  ! opens a file (not that two different ranks are writing to the
281  ! default_output_unit, we leave it up to mpirun or so to merge stuff
282  IF (bcast_output_unit == default_output_unit) THEN
283  output_unit = default_output_unit
284  ELSE
285  CALL open_file(file_name=tmc_ana_out_file_name, file_status="UNKNOWN", &
286  file_action="WRITE", file_position="APPEND", &
287  unit_number=output_unit)
288  CALL tmc_ana_header(output_unit)
289  END IF
290 
291  ALLOCATE (tmc_ana_env_list(tmc_env%params%nr_temp))
292  tmc_ana_section => section_vals_get_subs_vals(root_section, "MOTION%TMC%TMC_ANALYSIS")
293  DO i = 1, tmc_env%params%nr_temp
294  CALL tmc_read_ana_input(tmc_ana_section, tmc_ana_env_list(i)%temp)
295  tmc_ana_env_list(i)%temp%io_unit = output_unit
296  END DO
297  CALL do_tmc_worker(tmc_env=tmc_env, ana_list=tmc_ana_env_list) ! start the worker routine for analysis
298  DO i = 1, tmc_env%params%nr_temp
299  IF (ASSOCIATED(tmc_ana_env_list(i)%temp%last_elem)) &
300  CALL deallocate_sub_tree_node(tree_elem=tmc_ana_env_list(i)%temp%last_elem)
301  CALL tmc_ana_env_release(tmc_ana_env_list(i)%temp)
302  END DO
303  DEALLOCATE (tmc_ana_env_list)
304  IF (bcast_output_unit .NE. output_unit) THEN
305  CALL close_file(unit_number=tmc_env%m_env%io_unit)
306  END IF
307  CALL cp_rm_default_logger()
308  CALL cp_logger_release(logger_sub)
309 
310  END IF ! unused worker groups have nothing to do
311 
312  ! delete the random numbers
313  DEALLOCATE (tmc_env%rng_stream)
314 
315  ! deallocate the move types
316  CALL finalize_mv_types(tmc_env%params)
317 
318  ! finalize master and worker environment
319  IF (tmc_env%tmc_comp_set%group_nr .EQ. 0) THEN
320  CALL tmc_master_env_release(tmc_env) ! release master env
321  ELSE IF (tmc_env%tmc_comp_set%group_nr .NE. 0) THEN
322  CALL tmc_worker_env_release(tmc_env) ! release worker env
323  END IF ! unused worker groups have nothing to do
324 
325  ELSE
326  IF (tmc_env%params%print_test_output) THEN
327  WRITE (output_unit, *) "TMC|NOTenoughProcessorsX= -999"
328  WRITE (output_unit, *) "TMC|NOTcalculatedTotal energy: -999"
329  END IF
330  END IF
331  ! finalize / deallocate everything
332  CALL tmc_env_release(tmc_env)
333 
334  ! end the timing
335  CALL timestop(handle)
336 
337  END SUBROUTINE do_tmc
338 
339 ! **************************************************************************************************
340 !> \brief analyze TMC trajectory files
341 !> \param input_declaration ...
342 !> \param root_section ...
343 !> \param para_env ...
344 !> \param
345 !> \author Mandes 03.2013
346 ! **************************************************************************************************
347  SUBROUTINE do_analyze_files(input_declaration, root_section, para_env)
348  TYPE(section_type), POINTER :: input_declaration
349  TYPE(section_vals_type), POINTER :: root_section
350  TYPE(mp_para_env_type), POINTER :: para_env
351 
352  CHARACTER(LEN=*), PARAMETER :: routinen = 'do_analyze_files'
353 
354  INTEGER :: dir_ind, handle, nr_dim, output_unit, &
355  temp
356  TYPE(cp_logger_type), POINTER :: logger
357  TYPE(tmc_ana_list_type), DIMENSION(:), POINTER :: ana_list
358  TYPE(tmc_env_type), POINTER :: tmc_env
359  TYPE(tree_type), POINTER :: elem
360 
361  NULLIFY (ana_list, tmc_env, elem, logger)
362 
363  ! start the timing
364  CALL timeset(routinen, handle)
365 
366  ! create a TMC environment (also to have a params environment)
367  CALL tmc_env_create(tmc_env)
368  ! -- spiltting communicator
369  ALLOCATE (tmc_env%tmc_comp_set%para_env_m_ana)
370  CALL tmc_env%tmc_comp_set%para_env_m_ana%from_split(para_env, para_env%mepos, 0)
371  IF (para_env%num_pe .NE. 1) &
372  cpwarn("just one out of "//cp_to_string(para_env%num_pe)//"cores is used ")
373  ! distribute work to availuble cores
374  IF (para_env%mepos .EQ. 0) THEN
375  !TODO get the correct usage of creating and handling the logger...
376  logger => cp_get_default_logger()
377  output_unit = cp_logger_get_default_io_unit(logger)
378  cpassert(output_unit .GT. 0)
379  ! write the header
380  CALL tmc_ana_header(output_unit)
381 
382  ! read the input and create the ana environments for each temp
383  CALL tmc_read_ana_files_input(input_declaration=input_declaration, &
384  input=root_section, ana_list=ana_list, &
385  elem=elem, tmc_env=tmc_env)
386  nr_dim = SIZE(elem%pos)
387  ! we need a new tree element with all neccessay arrays, (e.g. dipoles could not be allocated already)
388  CALL deallocate_sub_tree_node(tree_elem=elem)
389  cpassert(SIZE(ana_list) .GT. 0)
390 
391  ! print initial test output (for single core tests, where no data is produced)
392  IF (tmc_env%params%print_test_output) THEN
393  WRITE (output_unit, *) "TMC|ANAtestOutputInitX= -999"
394  END IF
395 
396  ! do the analysis
397  DO temp = 1, SIZE(ana_list)
398  ! initialize the structures
399  ana_list(temp)%temp%io_unit = output_unit
400  CALL analysis_init(ana_env=ana_list(temp)%temp, nr_dim=nr_dim)
401  ! to allocate the dipole array in tree elements
402  IF (ana_list(temp)%temp%costum_dip_file_name .NE. &
404  tmc_env%params%print_dipole = .true.
405 
406  IF (.NOT. ASSOCIATED(elem)) &
407  CALL allocate_new_sub_tree_node(tmc_params=tmc_env%params, &
408  next_el=elem, nr_dim=nr_dim)
409  CALL analysis_restart_read(ana_env=ana_list(temp)%temp, &
410  elem=elem)
411  IF (.NOT. ASSOCIATED(elem) .AND. .NOT. ASSOCIATED(ana_list(temp)%temp%last_elem)) &
412  cpabort("uncorrect initialization of the initial configuration")
413  ! do for all directories
414  DO dir_ind = 1, SIZE(ana_list(temp)%temp%dirs)
415  WRITE (output_unit, fmt='(T2,A,"| ",A,T41,A40)') "TMC_ANA", &
416  "read directory", trim(ana_list(temp)%temp%dirs(dir_ind))
418  start_id=ana_list(temp)%temp%from_elem, &
419  end_id=ana_list(temp)%temp%to_elem, &
420  dir_ind=dir_ind, &
421  ana_env=ana_list(temp)%temp, &
422  tmc_params=tmc_env%params)
423  ! remove the last saved element to start with a new file
424  ! there is no weight for this element
425  IF (dir_ind .LT. SIZE(ana_list(temp)%temp%dirs) .AND. &
426  ASSOCIATED(ana_list(temp)%temp%last_elem)) &
427  CALL deallocate_sub_tree_node(tree_elem=ana_list(temp)%temp%last_elem)
428  IF (ASSOCIATED(ana_list(temp)%temp%last_elem)) &
429  ana_list(temp)%temp%conf_offset = ana_list(temp)%temp%conf_offset &
430  + ana_list(temp)%temp%last_elem%nr
431  END DO
432  CALL finalize_tmc_analysis(ana_env=ana_list(temp)%temp)
433  ! write analysis restart file
434  ! if there is something to write
435  ! shifts the last element to actual element
436  IF (ASSOCIATED(ana_list(temp)%temp%last_elem)) &
437  CALL analysis_restart_print(ana_env=ana_list(temp)%temp)
438  IF (ASSOCIATED(ana_list(temp)%temp%last_elem)) &
439  CALL deallocate_sub_tree_node(tree_elem=ana_list(temp)%temp%last_elem)
440  IF (ASSOCIATED(elem)) &
441  CALL deallocate_sub_tree_node(tree_elem=elem)
442 
443  IF (ASSOCIATED(ana_list(temp)%temp%last_elem)) &
444  CALL deallocate_sub_tree_node(tree_elem=ana_list(temp)%temp%last_elem)
445 
446  CALL tmc_ana_env_release(ana_list(temp)%temp)
447  END DO
448 
449  DEALLOCATE (ana_list)
450  END IF
451  CALL tmc_env_release(tmc_env)
452 
453  ! end the timing
454  CALL timestop(handle)
455  END SUBROUTINE do_analyze_files
456 
457 ! **************************************************************************************************
458 !> \brief creates a new para environment for tmc analysis for each temperature
459 !> \param input_declaration ...
460 !> \param input global environment
461 !> \param ana_list ...
462 !> \param elem ...
463 !> \param tmc_env TMC analysis environment
464 !> \author Mandes 03.2013
465 ! **************************************************************************************************
466  SUBROUTINE tmc_read_ana_files_input(input_declaration, input, ana_list, elem, tmc_env)
467  TYPE(section_type), POINTER :: input_declaration
468  TYPE(section_vals_type), POINTER :: input
469  TYPE(tmc_ana_list_type), DIMENSION(:), POINTER :: ana_list
470  TYPE(tree_type), POINTER :: elem
471  TYPE(tmc_env_type), POINTER :: tmc_env
472 
473  CHARACTER(len=default_string_length), &
474  DIMENSION(:), POINTER :: directories
475  INTEGER :: env_id, ierr, nr_temp, t_act
476  LOGICAL :: flag
477  REAL(kind=dp) :: tmax, tmin
478  REAL(kind=dp), DIMENSION(:), POINTER :: inp_temp, temps
479  TYPE(section_vals_type), POINTER :: tmc_section
480 
481  NULLIFY (tmc_section, inp_temp, temps)
482  cpassert(ASSOCIATED(input))
483  cpassert(.NOT. ASSOCIATED(ana_list))
484  cpassert(.NOT. ASSOCIATED(elem))
485  cpassert(ASSOCIATED(tmc_env))
486 
487  ! first global TMC stuff
488  tmc_section => section_vals_get_subs_vals(input, "MOTION%TMC")
489  CALL section_vals_val_get(tmc_section, "PRINT_TEST_OUTPUT", l_val=tmc_env%params%print_test_output)
490  ! TMC analysis stuff
491  tmc_section => section_vals_get_subs_vals(input, "MOTION%TMC%TMC_ANALYSIS_FILES")
492  CALL section_vals_get(tmc_section, explicit=flag)
493  cpassert(flag)
494 
495  CALL section_vals_val_get(tmc_section, "FORCE_ENV_FILE", &
496  c_val=tmc_env%params%energy_inp_file)
497 
498  CALL section_vals_val_get(tmc_section, "NR_TEMPERATURE", i_val=nr_temp)
499 
500  CALL section_vals_val_get(tmc_section, "TEMPERATURE", r_vals=inp_temp)
501  IF ((nr_temp .GT. 1) .AND. (SIZE(inp_temp) .NE. 2)) &
502  cpabort("specify each temperature, skip keyword NR_TEMPERATURE")
503  IF (nr_temp .EQ. 1) THEN
504  nr_temp = SIZE(inp_temp)
505  ALLOCATE (temps(nr_temp))
506  temps(:) = inp_temp(:)
507  ELSE
508  tmin = inp_temp(1)
509  tmax = inp_temp(2)
510  ALLOCATE (temps(nr_temp))
511  temps(1) = tmin
512  DO t_act = 2, SIZE(temps)
513  temps(t_act) = temps(t_act - 1) + (tmax - tmin)/(SIZE(temps) - 1.0_dp)
514  END DO
515  IF (any(temps .LT. 0.0_dp)) &
516  CALL cp_abort(__location__, "The temperatures are negative. Should be specified using "// &
517  "TEMPERATURE {T_min} {T_max} and NR_TEMPERATURE {#temperatures}")
518  END IF
519 
520  ! get multiple directories
521  CALL section_vals_val_get(tmc_section, "DIRECTORIES", c_vals=directories)
522 
523  ! get init configuration (for sizes)
524  CALL create_force_env(new_env_id=env_id, &
525  input_declaration=input_declaration, &
526  input_path=tmc_env%params%energy_inp_file, &
527  mpi_comm=tmc_env%tmc_comp_set%para_env_m_ana, &
528  output_path="tmc_ana.out", ierr=ierr)
529  CALL get_initial_conf(tmc_params=tmc_env%params, init_conf=elem, &
530  env_id=env_id)
531  CALL get_atom_kinds_and_cell(env_id=env_id, atoms=tmc_env%params%atoms, &
532  cell=tmc_env%params%cell)
533  CALL destroy_force_env(env_id, ierr)
534 
535  ALLOCATE (ana_list(SIZE(temps)))
536  DO t_act = 1, SIZE(temps)
537  ana_list(t_act)%temp => null()
538  CALL tmc_read_ana_input(tmc_section, ana_list(t_act)%temp)
539  ana_list(t_act)%temp%temperature = temps(t_act)
540  ALLOCATE (ana_list(t_act)%temp%dirs(SIZE(directories)))
541  ana_list(t_act)%temp%dirs(:) = directories(:)
542  ana_list(t_act)%temp%cell => tmc_env%params%cell
543  ana_list(t_act)%temp%atoms => tmc_env%params%atoms
544  ana_list(t_act)%temp%print_test_output = tmc_env%params%print_test_output
545 
546  CALL section_vals_val_get(tmc_section, "POSITION_FILE", &
547  c_val=ana_list(t_act)%temp%costum_pos_file_name)
548  CALL section_vals_val_get(tmc_section, "DIPOLE_FILE", &
549  c_val=ana_list(t_act)%temp%costum_dip_file_name)
550  CALL section_vals_val_get(tmc_section, "CELL_FILE", &
551  c_val=ana_list(t_act)%temp%costum_cell_file_name)
552  CALL section_vals_val_get(tmc_section, "START_ELEM", i_val=ana_list(t_act)%temp%from_elem)
553  CALL section_vals_val_get(tmc_section, "END_ELEM", i_val=ana_list(t_act)%temp%to_elem)
554  END DO
555  DEALLOCATE (temps)
556  END SUBROUTINE tmc_read_ana_files_input
557 
558 ! **************************************************************************************************
559 !> \brief read the variables for distributing cores
560 !> \param input ...
561 !> \param tmc_env structure for storing all the tmc parameters
562 !> \author Mandes 11.2012
563 ! **************************************************************************************************
564  SUBROUTINE tmc_preread_input(input, tmc_env)
565  TYPE(section_vals_type), POINTER :: input
566  TYPE(tmc_env_type), POINTER :: tmc_env
567 
568  CHARACTER(LEN=default_path_length) :: c_tmp
569  INTEGER :: itmp
570  LOGICAL :: explicit_key, flag
571  REAL(kind=dp) :: tmax, tmin
572  REAL(kind=dp), DIMENSION(:), POINTER :: inp_temp
573  TYPE(section_vals_type), POINTER :: tmc_section
574 
575  NULLIFY (tmc_section, inp_temp)
576 
577  cpassert(ASSOCIATED(input))
578 
579  tmc_env%tmc_comp_set%ana_on_the_fly = 0
580  tmc_section => section_vals_get_subs_vals(input, "MOTION%TMC%TMC_ANALYSIS")
581  CALL section_vals_get(tmc_section, explicit=flag)
582  IF (flag) THEN
583  tmc_env%tmc_comp_set%ana_on_the_fly = 1
584  END IF
585 
586  tmc_section => section_vals_get_subs_vals(input, "MOTION%TMC")
587  CALL section_vals_get(tmc_section, explicit=flag)
588  cpassert(flag)
589 
590  CALL section_vals_val_get(tmc_section, "PRINT_TEST_OUTPUT", l_val=tmc_env%params%print_test_output)
591 
592  cpassert(ASSOCIATED(tmc_env%tmc_comp_set))
593  ! read the parameters for the computational setup
594  CALL section_vals_val_get(tmc_section, "GROUP_ENERGY_SIZE", i_val=tmc_env%tmc_comp_set%group_ener_size)
595  CALL section_vals_val_get(tmc_section, "GROUP_ENERGY_NR", i_val=tmc_env%tmc_comp_set%group_ener_nr)
596  CALL section_vals_val_get(tmc_section, "GROUP_CC_SIZE", i_val=tmc_env%tmc_comp_set%group_cc_size)
597  CALL section_vals_val_get(tmc_section, "GROUP_ANLYSIS_NR", i_val=itmp)
598  IF (tmc_env%tmc_comp_set%ana_on_the_fly .GT. 0) &
599  tmc_env%tmc_comp_set%ana_on_the_fly = itmp
600  IF (tmc_env%tmc_comp_set%ana_on_the_fly .GT. 1) &
601  CALL cp_abort(__location__, &
602  "analysing on the fly is up to now not supported for multiple cores. "// &
603  "Restart file witing for this case and temperature "// &
604  "distribution has to be solved.!.")
605  CALL section_vals_val_get(tmc_section, "RESULT_LIST_IN_MEMORY", l_val=tmc_env%params%USE_REDUCED_TREE)
606  ! swap the variable, because of oposit meaning
607  tmc_env%params%USE_REDUCED_TREE = .NOT. tmc_env%params%USE_REDUCED_TREE
608  CALL section_vals_val_get(tmc_section, "NR_TEMPERATURE", i_val=tmc_env%params%nr_temp)
609 
610  ! stuff everyone needs to know
611  CALL section_vals_val_get(tmc_section, "NMC_MOVES%NMC_FILE_NAME", c_val=tmc_env%params%NMC_inp_file)
612  IF (tmc_env%params%NMC_inp_file .EQ. tmc_default_unspecified_name) THEN
613  ! file name keyword without file name
614  cpabort("no or a valid NMC input file has to be specified ")
615  ELSE IF (tmc_env%params%NMC_inp_file .EQ. "") THEN
616  ! no keyword
617  IF (tmc_env%tmc_comp_set%group_cc_size .GT. 0) &
618  CALL cp_warn(__location__, &
619  "The configurational groups are deactivated, "// &
620  "because no approximated energy input is specified.")
621  tmc_env%tmc_comp_set%group_cc_size = 0
622  ELSE
623  ! check file existence
624  INQUIRE (file=trim(tmc_env%params%NMC_inp_file), exist=flag, iostat=itmp)
625  IF (.NOT. flag .OR. itmp .NE. 0) &
626  cpabort("a valid NMC input file has to be specified")
627  END IF
628 
629  CALL section_vals_val_get(tmc_section, "TEMPERATURE", r_vals=inp_temp)
630  IF (tmc_env%params%nr_temp .GT. 1 .AND. SIZE(inp_temp) .NE. 2) &
631  cpabort("specify each temperature, skip keyword NR_TEMPERATURE")
632  IF (tmc_env%params%nr_temp .EQ. 1) THEN
633  tmc_env%params%nr_temp = SIZE(inp_temp)
634  ALLOCATE (tmc_env%params%Temp(tmc_env%params%nr_temp))
635  tmc_env%params%Temp(:) = inp_temp(:)
636  ELSE
637  tmin = inp_temp(1)
638  tmax = inp_temp(2)
639  ALLOCATE (tmc_env%params%Temp(tmc_env%params%nr_temp))
640  tmc_env%params%Temp(1) = tmin
641  DO itmp = 2, SIZE(tmc_env%params%Temp)
642  tmc_env%params%Temp(itmp) = tmc_env%params%Temp(itmp - 1) + (tmax - tmin)/(SIZE(tmc_env%params%Temp) - 1.0_dp)
643  END DO
644  IF (any(tmc_env%params%Temp .LT. 0.0_dp)) &
645  CALL cp_abort(__location__, "The temperatures are negative. Should be specified using "// &
646  "TEMPERATURE {T_min} {T_max} and NR_TEMPERATURE {#temperatures}")
647  END IF
648 
649  CALL section_vals_val_get(tmc_section, "TASK_TYPE", explicit=explicit_key)
650  IF (explicit_key) THEN
651  CALL section_vals_val_get(tmc_section, "TASK_TYPE", c_val=c_tmp)
652  SELECT CASE (trim(c_tmp))
653  CASE (trim(tmc_default_unspecified_name))
654  tmc_env%params%task_type = task_type_mc
655  CASE ("IDEAL_GAS")
656  tmc_env%params%task_type = task_type_ideal_gas
657  CASE DEFAULT
658  CALL cp_warn(__location__, &
659  'unknown TMC task type "'//trim(c_tmp)//'" specified. '// &
660  " Set to default.")
661  tmc_env%params%task_type = task_type_mc
662  END SELECT
663  END IF
664 
665  END SUBROUTINE tmc_preread_input
666 
667 ! **************************************************************************************************
668 !> \brief read the tmc subsection from the input file
669 !> \param input points to the tmc subsection in the input file
670 !> \param tmc_env structure for storing all the tmc parameters
671 !> \author Mandes 11.2012
672 ! **************************************************************************************************
673  SUBROUTINE tmc_read_input(input, tmc_env)
674  TYPE(section_vals_type), POINTER :: input
675  TYPE(tmc_env_type), POINTER :: tmc_env
676 
677  INTEGER :: itmp
678  LOGICAL :: explicit, flag
679  REAL(kind=dp) :: r_tmp
680  REAL(kind=dp), DIMENSION(:), POINTER :: r_arr_tmp
681  TYPE(section_vals_type), POINTER :: tmc_section
682 
683  NULLIFY (tmc_section)
684 
685  cpassert(ASSOCIATED(input))
686 
687  tmc_section => section_vals_get_subs_vals(input, "MOTION%TMC")
688  CALL section_vals_get(tmc_section, explicit=flag)
689  cpassert(flag)
690 
691  ! only for the master
692  IF (tmc_env%tmc_comp_set%group_nr == 0) THEN
693  cpassert(ASSOCIATED(tmc_env%m_env))
694  ! the walltime input can be done as HH:MM:SS or just in seconds.
695  CALL cp2k_get_walltime(section=input, keyword_name="GLOBAL%WALLTIME", &
696  walltime=tmc_env%m_env%walltime)
697 
698  CALL section_vals_val_get(tmc_section, "NUM_MC_ELEM", i_val=tmc_env%m_env%num_MC_elem)
699  CALL section_vals_val_get(tmc_section, "RND_DETERMINISTIC", i_val=tmc_env%m_env%rnd_init)
700  ! restarting
701  CALL section_vals_val_get(tmc_section, "RESTART_IN", c_val=tmc_env%m_env%restart_in_file_name)
702  IF (tmc_env%m_env%restart_in_file_name .EQ. tmc_default_unspecified_name) THEN
703  tmc_env%m_env%restart_in_file_name = tmc_default_restart_in_file_name
704  INQUIRE (file=tmc_env%m_env%restart_in_file_name, exist=flag)
705  IF (.NOT. flag) tmc_env%m_env%restart_in_file_name = ""
706  END IF
707  CALL section_vals_val_get(tmc_section, "RESTART_OUT", i_val=tmc_env%m_env%restart_out_step)
708  ! restart just at the end (lone keyword)
709  IF (tmc_env%m_env%restart_out_step .EQ. -9) THEN
710  tmc_env%m_env%restart_out_file_name = tmc_default_restart_out_file_name
711  tmc_env%m_env%restart_out_step = huge(tmc_env%m_env%restart_out_step)
712  END IF
713  IF (tmc_env%m_env%restart_out_step .LT. 0) &
714  CALL cp_abort(__location__, &
715  "Please specify a valid value for the frequency "// &
716  "to write restart files (RESTART_OUT #). "// &
717  "# > 0 to define the amount of Markov chain elements in between, "// &
718  "or 0 to deactivate the restart file writing. "// &
719  "Lonely keyword writes restart file only at the end of the run.")
720 
721  CALL section_vals_val_get(tmc_section, "INFO_OUT_STEP_SIZE", i_val=tmc_env%m_env%info_out_step_size)
722  CALL section_vals_val_get(tmc_section, "DOT_TREE", c_val=tmc_env%params%dot_file_name)
723  CALL section_vals_val_get(tmc_section, "ALL_CONF_FILE_NAME", c_val=tmc_env%params%all_conf_file_name)
724  IF (tmc_env%params%dot_file_name .NE. "") tmc_env%params%DRAW_TREE = .true.
725 
726  ! everything for the worker group
727  ELSE IF (tmc_env%tmc_comp_set%group_nr .NE. 0) THEN
728  cpassert(ASSOCIATED(tmc_env%w_env))
729  END IF
730 
731  ! stuff everyone needs to know
732 
733  ! the NMC_FILE_NAME is already read in tmc_preread_input
734  CALL section_vals_val_get(tmc_section, "ENERGY_FILE_NAME", c_val=tmc_env%params%energy_inp_file)
735  ! file name keyword without file name
736  IF (tmc_env%params%energy_inp_file .EQ. "") &
737  cpabort("a valid exact energy input file has to be specified ")
738  ! check file existence
739  INQUIRE (file=trim(tmc_env%params%energy_inp_file), exist=flag, iostat=itmp)
740  IF (.NOT. flag .OR. itmp .NE. 0) &
741  CALL cp_abort(__location__, "a valid exact energy input file has to be specified, "// &
742  trim(tmc_env%params%energy_inp_file)//" does not exist.")
743 
744  CALL section_vals_val_get(tmc_section, "NUM_MV_ELEM_IN_CELL", i_val=tmc_env%params%nr_elem_mv)
745 
746  CALL section_vals_val_get(tmc_section, "VOLUME_ISOTROPIC", l_val=tmc_env%params%v_isotropic)
747  CALL section_vals_val_get(tmc_section, "PRESSURE", r_val=tmc_env%params%pressure)
748  tmc_env%params%pressure = tmc_env%params%pressure/au2bar
749  CALL section_vals_val_get(tmc_section, "MOVE_CENTER_OF_MASS", l_val=tmc_env%params%mv_cen_of_mass)
750 
751  CALL section_vals_val_get(tmc_section, "SUB_BOX", r_vals=r_arr_tmp)
752  IF (SIZE(r_arr_tmp) .GT. 1) THEN
753  IF (SIZE(r_arr_tmp) .NE. tmc_env%params%dim_per_elem) &
754  cpabort("The entered sub box sizes does not fit in number of dimensions.")
755  IF (any(r_arr_tmp .LE. 0.0_dp)) &
756  cpabort("The entered sub box lengths should be greater than 0.")
757  DO itmp = 1, SIZE(tmc_env%params%sub_box_size)
758  tmc_env%params%sub_box_size(itmp) = r_arr_tmp(itmp)/au2a
759  END DO
760  ELSE IF (r_arr_tmp(1) .GT. 0.0_dp) THEN
761  r_tmp = r_arr_tmp(1)/au2a
762  tmc_env%params%sub_box_size(:) = r_tmp
763  END IF
764 
765  ! read all the distinct moves
766  CALL read_init_move_types(tmc_params=tmc_env%params, &
767  tmc_section=tmc_section)
768 
769  CALL section_vals_val_get(tmc_section, "ESIMATE_ACC_PROB", l_val=tmc_env%params%esimate_acc_prob)
770  CALL section_vals_val_get(tmc_section, "SPECULATIVE_CANCELING", l_val=tmc_env%params%SPECULATIVE_CANCELING)
771  CALL section_vals_val_get(tmc_section, "USE_SCF_ENERGY_INFO", l_val=tmc_env%params%use_scf_energy_info)
772  ! printing
773  CALL section_vals_val_get(tmc_section, "PRINT_ONLY_ACC", l_val=tmc_env%params%print_only_diff_conf)
774  CALL section_vals_val_get(tmc_section, "PRINT_COORDS", l_val=tmc_env%params%print_trajectory)
775  CALL section_vals_val_get(tmc_section, "PRINT_DIPOLE", explicit=explicit)
776  IF (explicit) &
777  CALL section_vals_val_get(tmc_section, "PRINT_DIPOLE", l_val=tmc_env%params%print_dipole)
778  CALL section_vals_val_get(tmc_section, "PRINT_FORCES", explicit=explicit)
779  IF (explicit) &
780  CALL section_vals_val_get(tmc_section, "PRINT_FORCES", l_val=tmc_env%params%print_forces)
781  CALL section_vals_val_get(tmc_section, "PRINT_CELL", explicit=explicit)
782  IF (explicit) &
783  CALL section_vals_val_get(tmc_section, "PRINT_CELL", l_val=tmc_env%params%print_cell)
784  CALL section_vals_val_get(tmc_section, "PRINT_ENERGIES", l_val=tmc_env%params%print_energies)
785 
786  END SUBROUTINE tmc_read_input
787 
788 ! **************************************************************************************************
789 !> \brief creates a new para environment for tmc
790 !> \param tmc_comp_set structure with parameters for computational setup
791 !> \param para_env the old parallel environment
792 !> \param ana_on_the_fly ...
793 !> \param success ...
794 !> \author Mandes 11.2012
795 ! **************************************************************************************************
796  SUBROUTINE tmc_redistributing_cores(tmc_comp_set, para_env, ana_on_the_fly, &
797  success)
798  TYPE(tmc_comp_set_type), POINTER :: tmc_comp_set
799  TYPE(mp_para_env_type), POINTER :: para_env
800  INTEGER :: ana_on_the_fly
801  LOGICAL :: success
802 
803  INTEGER :: cc_group, cc_group_rank, master_ana_group, master_ana_rank, &
804  master_first_e_worker_g, master_first_e_worker_r, master_worker_group, &
805  master_worker_rank, my_mpi_undefined, total_used
806  LOGICAL :: flag, master
807 
808  cpassert(ASSOCIATED(tmc_comp_set))
809  cpassert(ASSOCIATED(para_env))
810 
811  ! colors and positions for new communicators
812  ! variables for printing
813  tmc_comp_set%group_nr = -1
814  my_mpi_undefined = para_env%num_pe + 10000 !HUGE(my_mpi_undefined)! mp_undefined
815  master_worker_group = my_mpi_undefined
816  master_worker_rank = -1
817  cc_group = my_mpi_undefined
818  cc_group_rank = -1
819  master_first_e_worker_g = my_mpi_undefined
820  master_first_e_worker_r = -1
821  master_ana_group = my_mpi_undefined
822  master_ana_rank = -1
823 
824  master = .false.
825  flag = .false.
826  success = .true.
827 
828  IF (para_env%num_pe .LE. 1) THEN
829  cpwarn("TMC need at least 2 cores (one for master, one for worker)")
830  success = .false.
831  ELSE
832  ! check if there are enougth cores available
833  IF (tmc_comp_set%group_ener_size*tmc_comp_set%group_ener_nr .GT. (para_env%num_pe - 1)) &
834  cpwarn("The selected energy group size is too huge. ")
835  IF (flag) THEN
836  tmc_comp_set%group_ener_nr = int((para_env%num_pe - 1)/ &
837  REAL(tmc_comp_set%group_ener_size, kind=dp))
838  IF (tmc_comp_set%group_ener_nr .LT. 1) &
839  cpwarn("The selected energy group size is too huge. ")
840  IF (flag) success = .false.
841  END IF
842 
843  ! set the amount of configurational change worker groups
844  tmc_comp_set%group_cc_nr = 0
845  IF (tmc_comp_set%group_cc_size .GT. 0) THEN
846  tmc_comp_set%group_cc_nr = int((para_env%num_pe - 1 - tmc_comp_set%ana_on_the_fly &
847  - tmc_comp_set%group_ener_size*tmc_comp_set%group_ener_nr)/ &
848  REAL(tmc_comp_set%group_cc_size, kind=dp))
849 
850  IF (tmc_comp_set%group_cc_nr .LT. 1) &
851  CALL cp_warn(__location__, &
852  "There are not enougth cores left for creating groups for configurational change.")
853  IF (flag) success = .false.
854  END IF
855 
856  total_used = tmc_comp_set%group_ener_size*tmc_comp_set%group_ener_nr + &
857  tmc_comp_set%group_cc_size*tmc_comp_set%group_cc_nr + &
858  tmc_comp_set%ana_on_the_fly
859  IF (para_env%num_pe - 1 .GT. total_used) &
860  cpwarn(" mpi ranks are unused, but can be used for analysis.")
861 
862  ! determine the master node
863  IF (para_env%mepos == para_env%num_pe - 1) THEN
864  master = .true.
865  master_worker_group = para_env%num_pe + 3 ! belong to master_worker_comm
866  master_worker_rank = 0 ! rank in m_w_comm
867  master_first_e_worker_g = para_env%num_pe + 3 ! belong to master_first_energy_worker_comm
868  master_first_e_worker_r = 0
869  tmc_comp_set%group_nr = 0 !para_env%num_pe +3
870  master_ana_group = para_env%num_pe + 4
871  master_ana_rank = 0
872  ELSE
873  ! energy calculation groups
874  IF (para_env%mepos .LT. tmc_comp_set%group_ener_size*tmc_comp_set%group_ener_nr) THEN
875  tmc_comp_set%group_nr = int(para_env%mepos/tmc_comp_set%group_ener_size) + 1 ! assign to groups
876  ! master of worker group
877  IF (modulo(para_env%mepos, tmc_comp_set%group_ener_size) .EQ. 0) THEN ! tmc_comp_set%group_nr masters
878  master_worker_group = para_env%num_pe + 3 ! belong to master_worker_comm
879  master_worker_rank = tmc_comp_set%group_nr ! rank in m_w_comm
880  IF (master_worker_rank .EQ. 1) THEN
881  master_first_e_worker_g = para_env%num_pe + 3 ! belong to master_first_energy_worker_comm
882  master_first_e_worker_r = 1
883  END IF
884  END IF
885  cc_group = tmc_comp_set%group_nr
886  cc_group_rank = para_env%mepos - &
887  (tmc_comp_set%group_nr - 1)*tmc_comp_set%group_ener_size ! rank in worker group
888 
889  ! configurational change groups
890  ELSE IF (para_env%mepos .LT. (tmc_comp_set%group_ener_size*tmc_comp_set%group_ener_nr + &
891  tmc_comp_set%group_cc_size*tmc_comp_set%group_cc_nr)) THEN
892  cc_group_rank = para_env%mepos - tmc_comp_set%group_ener_size*tmc_comp_set%group_ener_nr ! temporary
893  tmc_comp_set%group_nr = tmc_comp_set%group_ener_nr + 1 + int(cc_group_rank/tmc_comp_set%group_cc_size)
894  cc_group = tmc_comp_set%group_nr
895  ! master of worker group
896  IF (modulo(cc_group_rank, tmc_comp_set%group_cc_size) .EQ. 0) THEN ! tmc_comp_set%group_nr masters
897  master_worker_group = para_env%num_pe + 3 ! belong to master_worker_comm
898  master_worker_rank = tmc_comp_set%group_nr ! rank in m_w_comm
899  END IF
900  !cc_group_rank = cc_group_rank-(tmc_comp_set%group_nr-1)*tmc_comp_set%group_cc_size ! rank in worker group
901  cc_group_rank = modulo(cc_group_rank, tmc_comp_set%group_cc_size) ! rank in worker group
902  ELSE
903  ! not used cores
904  ! up to now we use just one core for doing the analysis
905  IF (para_env%mepos .EQ. para_env%num_pe - 2) THEN
906  tmc_comp_set%group_nr = para_env%mepos - (para_env%num_pe - 1) ! negative
907  cpassert(tmc_comp_set%group_nr .LT. 0)
908  IF (para_env%mepos .GE. para_env%num_pe - 1 - ana_on_the_fly) THEN
909  master_ana_group = para_env%num_pe + 4
910  master_ana_rank = -tmc_comp_set%group_nr
911  END IF
912  END IF
913  END IF
914  END IF
915 
916  IF (success) THEN
917  ! -- splitting communicators
918  ! worker intern communication
919  ALLOCATE (tmc_comp_set%para_env_sub_group)
920  CALL tmc_comp_set%para_env_sub_group%from_split(para_env, cc_group, cc_group_rank)
921  ! not the unused cores
922  IF (cc_group_rank < 0) THEN
923  CALL tmc_comp_set%para_env_sub_group%free()
924  DEALLOCATE (tmc_comp_set%para_env_sub_group)
925  END IF
926 
927  ! worker master communication
928  ALLOCATE (tmc_comp_set%para_env_m_w)
929  CALL tmc_comp_set%para_env_m_w%from_split(para_env, master_worker_group, master_worker_rank)
930  ! not the unused cores
931  IF (master_worker_rank < 0) THEN
932  CALL tmc_comp_set%para_env_m_w%free()
933  DEALLOCATE (tmc_comp_set%para_env_m_w)
934  END IF
935 
936  ! communicator only for first energy worker master and global master
937  ALLOCATE (tmc_comp_set%para_env_m_first_w)
938  CALL tmc_comp_set%para_env_m_first_w%from_split(para_env, master_first_e_worker_g, master_first_e_worker_r)
939  ! not the unused cores
940  IF (master_first_e_worker_r < 0) THEN
941  CALL tmc_comp_set%para_env_m_first_w%free()
942  DEALLOCATE (tmc_comp_set%para_env_m_first_w)
943  END IF
944 
945  ! communicator only for analysis worker and global master
946  ALLOCATE (tmc_comp_set%para_env_m_ana)
947  CALL tmc_comp_set%para_env_m_ana%from_split(para_env, master_ana_group, master_ana_rank)
948  IF (master_ana_rank < 0) THEN
949  CALL tmc_comp_set%para_env_m_ana%free()
950  DEALLOCATE (tmc_comp_set%para_env_m_ana)
951  END IF
952 
953  ! communicator for master only to handle external control
954  master_ana_group = my_mpi_undefined
955  master_ana_rank = -1
956  IF (master) THEN
957  master_ana_group = 1
958  master_ana_rank = 1
959  END IF
960  ALLOCATE (tmc_comp_set%para_env_m_only)
961  CALL tmc_comp_set%para_env_m_only%from_split(para_env, master_ana_group, master_ana_rank)
962  IF (master_ana_rank < 0) THEN
963  CALL tmc_comp_set%para_env_m_only%free()
964  DEALLOCATE (tmc_comp_set%para_env_m_only)
965  END IF
966  END IF
967  END IF
968  END SUBROUTINE tmc_redistributing_cores
969 
970 ! **************************************************************************************************
971 !> \brief prints the most important parameters used for TMC
972 !> \param tmc_env tructure with parameters for TMC
973 !> \author Mandes 11.2012
974 ! **************************************************************************************************
975  SUBROUTINE tmc_print_params(tmc_env)
976  TYPE(tmc_env_type), POINTER :: tmc_env
977 
978  CHARACTER(LEN=*), PARAMETER :: fmt_my = '(T2,A,"| ",A,T41,A40)', plabel = "TMC"
979 
980  CHARACTER(LEN=80) :: c_tmp, fmt_tmp
981  INTEGER :: file_nr
982 
983  cpassert(ASSOCIATED(tmc_env))
984  cpassert(ASSOCIATED(tmc_env%tmc_comp_set))
985  ! only the master prints out
986  IF (tmc_env%tmc_comp_set%group_nr == 0) THEN
987  file_nr = tmc_env%m_env%io_unit
988  cpassert(ASSOCIATED(tmc_env%tmc_comp_set%para_env_m_w))
989  cpassert(ASSOCIATED(tmc_env%m_env))
990 
991  CALL m_flush(file_nr)
992  WRITE (file_nr, *)
993 
994  WRITE (unit=file_nr, fmt="(/,T2,A)") repeat("-", 79)
995  WRITE (unit=file_nr, fmt="(T2,A,T80,A)") "-", "-"
996  WRITE (unit=file_nr, fmt="(T2,A,T35,A,T80,A)") "-", "TMC setting", "-"
997  WRITE (unit=file_nr, fmt="(T2,A,T80,A)") "-", "-"
998  WRITE (unit=file_nr, fmt="(T2,A)") repeat("-", 79)
999 
1000  WRITE (unit=file_nr, fmt="(T2,A,T35,A,T80,A)") "-", "distribution of cores", "-"
1001  WRITE (file_nr, fmt=fmt_my) plabel, "number of all working groups ", &
1002  cp_to_string(tmc_env%tmc_comp_set%para_env_m_w%num_pe - 1)
1003  WRITE (file_nr, fmt=fmt_my) plabel, "number of groups (ener|cc)", &
1004  cp_to_string(tmc_env%tmc_comp_set%group_ener_nr)//" | "// &
1005  cp_to_string(tmc_env%tmc_comp_set%group_cc_nr)
1006  WRITE (file_nr, fmt=fmt_my) plabel, "cores per group (ener|cc) ", &
1007  cp_to_string(tmc_env%tmc_comp_set%group_ener_size)//" | "// &
1008  cp_to_string(tmc_env%tmc_comp_set%group_cc_size)
1009  IF (ASSOCIATED(tmc_env%tmc_comp_set%para_env_m_ana)) &
1010  WRITE (file_nr, fmt=fmt_my) plabel, "Analysis groups ", &
1011  cp_to_string(tmc_env%tmc_comp_set%para_env_m_ana%num_pe - 1)
1012  IF (SIZE(tmc_env%params%Temp(:)) .LE. 7) THEN
1013  WRITE (fmt_tmp, *) '(T2,A,"| ",A,T25,A56)'
1014  c_tmp = ""
1015  WRITE (c_tmp, fmt="(1000F8.2)") tmc_env%params%Temp(:)
1016  WRITE (file_nr, fmt=fmt_tmp) plabel, "Temperature(s) [K]", trim(c_tmp)
1017  ELSE
1018  WRITE (file_nr, fmt='(A,1000F8.2)') " "//plabel//"| Temperature(s) [K]", &
1019  tmc_env%params%Temp(:)
1020  END IF
1021  WRITE (file_nr, fmt=fmt_my) plabel, "# of Monte Carlo Chain elements: ", &
1022  cp_to_string(tmc_env%m_env%num_MC_elem)
1023  WRITE (file_nr, fmt=fmt_my) plabel, "exact potential input file:", &
1024  trim(tmc_env%params%energy_inp_file)
1025  IF (tmc_env%params%NMC_inp_file .NE. "") &
1026  WRITE (file_nr, fmt=fmt_my) plabel, "approximate potential input file:", &
1027  trim(tmc_env%params%NMC_inp_file)
1028  IF (any(tmc_env%params%sub_box_size .GT. 0.0_dp)) THEN
1029  WRITE (fmt_tmp, *) '(T2,A,"| ",A,T25,A56)'
1030  c_tmp = ""
1031  WRITE (c_tmp, fmt="(1000F8.2)") tmc_env%params%sub_box_size(:)*au2a
1032  WRITE (file_nr, fmt=fmt_tmp) plabel, "Sub box size [A]", trim(c_tmp)
1033  END IF
1034  IF (tmc_env%params%pressure .GT. 0.0_dp) &
1035  WRITE (file_nr, fmt=fmt_my) plabel, "Pressure [bar]: ", &
1036  cp_to_string(tmc_env%params%pressure*au2bar)
1037  WRITE (file_nr, fmt=fmt_my) plabel, "Numbers of atoms/molecules moved "
1038  WRITE (file_nr, fmt=fmt_my) plabel, " within one conf. change", &
1039  cp_to_string(tmc_env%params%nr_elem_mv)
1040  WRITE (unit=file_nr, fmt="(/,T2,A)") repeat("-", 79)
1041  END IF
1042 
1043  END SUBROUTINE tmc_print_params
1044 
1045 END MODULE
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
Definition: grid_common.h:117
collects all references to literature in CP2K as new algorithms / method are included from literature...
Definition: bibliography.F:28
integer, save, public schonherr2014
Definition: bibliography.F:43
Utility routines to open and close files. Tracking of preconnections.
Definition: cp_files.F:16
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
Definition: cp_files.F:308
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
Definition: cp_files.F:119
various routines to log and control the output. The idea is that decisions about where to log should ...
subroutine, public cp_logger_set(logger, local_filename, global_filename)
sets various attributes of the given logger
subroutine, public cp_rm_default_logger()
the cousin of cp_add_default_logger, decrements the stack, so that the default logger is what it has ...
subroutine, public cp_logger_release(logger)
releases this logger
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
subroutine, public cp_logger_create(logger, para_env, print_level, default_global_unit_nr, default_local_unit_nr, global_filename, local_filename, close_global_unit_on_dealloc, iter_info, close_local_unit_on_dealloc, suffix, template_logger)
initializes a logger
subroutine, public cp_add_default_logger(logger)
adds a default logger. MUST be called before logging occours
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
Sets up and terminates the global environment variables.
Definition: environment.F:17
subroutine, public cp2k_get_walltime(section, keyword_name, walltime)
reads the Walltime also in format HH:MM:SS
Definition: environment.F:1166
interface to use cp2k as library
Definition: f77_interface.F:20
recursive subroutine, public destroy_force_env(env_id, ierr, q_finalize)
deallocates the force_env with the given id
recursive subroutine, public create_force_env(new_env_id, input_declaration, input_path, output_path, mpi_comm, output_unit, owns_out_unit, input, ierr, work_dir, initial_variables)
creates a new force environment using the given input, and writing the output to the given output uni...
Define type storing the global information of a run. Keep the amount of stored data small....
Definition: global_types.F:21
Definition: header.F:13
subroutine, public tmc_ana_header(iw)
...
Definition: header.F:446
subroutine, public tmc_header(iw)
...
Definition: header.F:423
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
integer, parameter, public default_string_length
Definition: kinds.F:57
integer, parameter, public default_path_length
Definition: kinds.F:58
Machine interface based on Fortran 2003 and POSIX.
Definition: machine.F:17
integer, parameter, public default_output_unit
Definition: machine.F:45
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
Definition: machine.F:106
Interface to the message passing library MPI.
Parallel (pseudo)random number generator (RNG) for multiple streams and substreams of random numbers.
integer, parameter, public uniform
Definition of physical constants:
Definition: physcon.F:68
real(kind=dp), parameter, public angstrom
Definition: physcon.F:144
real(kind=dp), parameter, public bar
Definition: physcon.F:177
module provides variables for the TMC analysis tool
subroutine, public tmc_ana_env_release(tmc_ana)
releases the structure environment for TMC analysis
module analyses element of the TMC tree element structure e.g. density, radial distribution function,...
Definition: tmc_analysis.F:16
subroutine, public analysis_restart_read(ana_env, elem)
read analysis restart file
Definition: tmc_analysis.F:366
subroutine, public finalize_tmc_analysis(ana_env)
call all the necessarry analysis printing routines
Definition: tmc_analysis.F:587
subroutine, public tmc_read_ana_input(tmc_ana_section, tmc_ana)
creates a new para environment for tmc analysis
Definition: tmc_analysis.F:86
subroutine, public analyze_file_configurations(start_id, end_id, dir_ind, ana_env, tmc_params)
read the files and analyze the configurations
Definition: tmc_analysis.F:633
subroutine, public analysis_init(ana_env, nr_dim)
initialize all the necessarry analysis structures
Definition: tmc_analysis.F:204
subroutine, public analysis_restart_print(ana_env)
print analysis restart file
Definition: tmc_analysis.F:269
writing and printing the files, trajectory (pos, cell, dipoles) as well as restart files
Definition: tmc_file_io.F:20
character(len=default_path_length) function, public expand_file_name_int(file_name, ivalue)
placing an integer at the end of a file name (before the file extension)
Definition: tmc_file_io.F:166
module contains the master routine handling the tree creation, communication with workers and task di...
Definition: tmc_master.F:23
subroutine, public do_tmc_master(tmc_env, globenv)
global master handling tree creation and communication/work distribution with workers
Definition: tmc_master.F:211
acceptance ratio handling of the different Monte Carlo Moves types For each move type and each temper...
subroutine, public read_init_move_types(tmc_params, tmc_section)
initialization of the different moves, with sizes and probabilities
subroutine, public finalize_mv_types(tmc_params)
deallocating the module variables
subroutine, public print_move_types(init, file_io, tmc_params)
routine pronts out the probabilities and sized for each type and temperature the output is divided in...
Tree Monte Carlo entry point, set up, CPU redistribution and input reading.
Definition: tmc_setup.F:16
subroutine, public do_analyze_files(input_declaration, root_section, para_env)
analyze TMC trajectory files
Definition: tmc_setup.F:348
subroutine, public do_tmc(input_declaration, root_section, para_env, globenv)
tmc_entry point
Definition: tmc_setup.F:98
tree nodes creation, searching, deallocation, references etc.
Definition: tmc_stati.F:15
character(len= *), parameter, public tmc_nmc_worker_out_file_name
Definition: tmc_stati.F:32
character(len= *), parameter, public tmc_master_out_file_name
Definition: tmc_stati.F:34
character(len= *), parameter, public tmc_default_unspecified_name
Definition: tmc_stati.F:40
character(len= *), parameter, public tmc_ana_out_file_name
Definition: tmc_stati.F:36
integer, parameter, public task_type_mc
Definition: tmc_stati.F:44
character(len= *), parameter, public tmc_default_restart_in_file_name
Definition: tmc_stati.F:28
character(len= *), parameter, public tmc_default_restart_out_file_name
Definition: tmc_stati.F:26
character(len= *), parameter, public tmc_energy_worker_out_file_name
Definition: tmc_stati.F:30
integer, parameter, public task_type_ideal_gas
Definition: tmc_stati.F:45
tree nodes creation, deallocation, references etc.
subroutine, public deallocate_sub_tree_node(tree_elem)
deallocates an elements of the subtree element structure
subroutine, public allocate_new_sub_tree_node(tmc_params, next_el, nr_dim)
allocates an elements of the subtree element structure
module handles definition of the tree nodes for the global and the subtrees binary tree parent elemen...
module handles definition of the tree nodes for the global and the subtrees binary tree parent elemen...
Definition: tmc_types.F:32
subroutine, public tmc_env_release(tmc_env)
releases the structure environment for TMC
Definition: tmc_types.F:207
subroutine, public tmc_worker_env_create(tmc_env)
creates a new structure environment for TMC master
Definition: tmc_types.F:342
subroutine, public tmc_master_env_create(tmc_env)
creates a new structure environment for TMC master
Definition: tmc_types.F:250
subroutine, public tmc_master_env_release(tmc_env)
releases the structure environment for TMC master
Definition: tmc_types.F:309
subroutine, public tmc_worker_env_release(tmc_env)
releases the structure environment for TMC master
Definition: tmc_types.F:370
subroutine, public tmc_env_create(tmc_env)
creates a new structure environment for TMC
Definition: tmc_types.F:177
module contains the worker routine handling the communication and the calculation / creation of the c...
Definition: tmc_worker.F:30
subroutine, public do_tmc_worker(tmc_env, ana_list)
worker get tasks form master and fulfill them
Definition: tmc_worker.F:114
subroutine, public get_initial_conf(tmc_params, init_conf, env_id)
get the initial confuguration (pos,...)
Definition: tmc_worker.F:767
subroutine, public get_atom_kinds_and_cell(env_id, atoms, cell)
get the pointer to the atoms, for easy handling
Definition: tmc_worker.F:815