Skip to content

Commit

Permalink
Farming: rename of variables and introduction of external commands (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
juerghutter committed Mar 6, 2023
1 parent a7bd535 commit b951fa5
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 117 deletions.
28 changes: 14 additions & 14 deletions src/farming_methods.F
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ SUBROUTINE get_next_job(farming_env, start, END, current, todo)
END DO
END DO dep

! if there are pending jobs, the slave can not be told to stop
! if there are pending jobs, the minion can not be told to stop
! at least wait if there are unresolved dependencies
IF (dep_OK) THEN
todo = itry
Expand Down Expand Up @@ -121,7 +121,7 @@ SUBROUTINE farming_parse_input(farming_env, root_section, para_env)
TYPE(mp_para_env_type), POINTER :: para_env

CHARACTER(LEN=3) :: text
INTEGER :: i, iunit, n_rep_val, num_slaves, &
INTEGER :: i, iunit, n_rep_val, num_minions, &
output_unit, stat
INTEGER, DIMENSION(:), POINTER :: dependencies, i_vals
LOGICAL :: explicit, has_dep
Expand Down Expand Up @@ -187,8 +187,8 @@ SUBROUTINE farming_parse_input(farming_env, root_section, para_env)
CALL section_vals_val_get(farming_section, "WAIT_TIME", &
r_val=farming_env%wait_time)

CALL section_vals_val_get(farming_section, "MASTER_SLAVE", &
l_val=farming_env%master_slave)
CALL section_vals_val_get(farming_section, "CAPTAIN_MINION", &
l_val=farming_env%captain_minion)

jobs_section => section_vals_get_subs_vals(farming_section, "JOB")
CALL section_vals_get(jobs_section, n_repetition=farming_env%njobs)
Expand Down Expand Up @@ -230,22 +230,22 @@ SUBROUTINE farming_parse_input(farming_env, root_section, para_env)
END DO

IF (has_dep) THEN
CPASSERT(farming_env%master_slave)
CPASSERT(farming_env%captain_minion)
CPASSERT(.NOT. farming_env%cycle)
END IF

output_unit = cp_print_key_unit_nr(logger, farming_section, "PROGRAM_RUN_INFO", &
extension=".log")

! master slave not supported
! Captain/Minion not supported
IF (para_env%num_pe == 1) THEN
farming_env%master_slave = .FALSE.
WRITE (output_unit, FMT="(T2,A)") "FARMING| Master-slave setup not supported for serial runs"
farming_env%captain_minion = .FALSE.
WRITE (output_unit, FMT="(T2,A)") "FARMING| Captain-Minion setup not supported for serial runs"
END IF
IF (farming_env%master_slave) THEN
num_slaves = para_env%num_pe - 1
IF (farming_env%captain_minion) THEN
num_minions = para_env%num_pe - 1
ELSE
num_slaves = para_env%num_pe
num_minions = para_env%num_pe
END IF

IF (output_unit > 0) THEN
Expand All @@ -259,10 +259,10 @@ SUBROUTINE farming_parse_input(farming_env, root_section, para_env)
WRITE (output_unit, FMT='(I4)', ADVANCE="NO") farming_env%group_partition(i)
END DO
WRITE (output_unit, *)
IF (SUM(farming_env%group_partition) .NE. num_slaves) THEN
IF (SUM(farming_env%group_partition) .NE. num_minions) THEN
WRITE (output_unit, FMT="(T2,A,T61,I10,T71,I10)") &
"FARMING| WARNING : group partition CPUs not equal to the available number (ignoring master) ", &
num_slaves, SUM(farming_env%group_partition)
"FARMING| WARNING : group partition CPUs not equal to the available number (ignoring Captain) ", &
num_minions, SUM(farming_env%group_partition)
WRITE (output_unit, FMT="(T2,A)") "FARMING| partition data ignored" ! any better idea ??
DEALLOCATE (farming_env%group_partition)
END IF
Expand Down
6 changes: 3 additions & 3 deletions src/farming_types.F
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ MODULE farming_types
LOGICAL :: ngroup_wish_set
LOGICAL :: restart
LOGICAL :: CYCLE
LOGICAL :: master_slave
LOGICAL :: captain_minion
INTEGER, DIMENSION(:), POINTER :: group_partition ! user preference for partitioning the cpus
CHARACTER(LEN=default_path_length) :: restart_file_name ! restart file for farming
CHARACTER(LEN=default_path_length) :: cwd ! directory we started from
INTEGER :: Njobs ! how many jobs to run
INTEGER :: restart_n ! where to start
INTEGER :: max_steps ! max number of steps,
! results in max_steps*Ngroup jobs being run
INTEGER :: stride ! for creating slave groups.
INTEGER :: stride ! for creating minion groups.
TYPE(job_type), DIMENSION(:), POINTER :: job ! a list of jobs
REAL(KIND=dp) :: wait_time
END TYPE farming_env_type
Expand All @@ -70,7 +70,7 @@ SUBROUTINE init_farming_env(farming_env)
farming_env%restart = .FALSE.
farming_env%restart_n = 1
farming_env%cycle = .FALSE.
farming_env%master_slave = .FALSE.
farming_env%captain_minion = .FALSE.
NULLIFY (farming_env%group_partition)
farming_env%cwd = "."
farming_env%Njobs = 0
Expand Down
2 changes: 1 addition & 1 deletion src/motion/cp_lbfgs_optimizer_gopt.F
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ MODULE cp_lbfgs_optimizer_gopt
! **************************************************************************************************
!> \brief info for the optimizer (see the description of this module)
!> \param task the actual task of the optimizer (in the master it is up to
!> date, in case of error also the slaves one get updated.
!> date, in case of error also the minions one get updated.
!> \param csave internal character string used by the lbfgs optimizer,
!> meaningful only in the master
!> \param lsave logical array used by the lbfgs optimizer, updated only
Expand Down
32 changes: 16 additions & 16 deletions src/optimize_input.F
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ SUBROUTINE force_matching(oi_env, input_declaration, root_section, para_env)
CHARACTER(len=default_string_length), &
ALLOCATABLE, DIMENSION(:, :) :: initial_variables
INTEGER :: color, energies_unit, handle, history_unit, i_atom, i_el, i_frame, i_free_var, &
i_var, ierr, mepos_master, mepos_slave, n_atom, n_el, n_frames, n_free_var, n_groups, &
i_var, ierr, mepos_master, mepos_minion, n_atom, n_el, n_frames, n_free_var, n_groups, &
n_var, new_env_id, num_pe_master, output_unit, restart_unit, state
INTEGER, ALLOCATABLE, DIMENSION(:) :: free_var_index
INTEGER, DIMENSION(:), POINTER :: group_distribution
Expand All @@ -177,8 +177,8 @@ SUBROUTINE force_matching(oi_env, input_declaration, root_section, para_env)
force_traj_read, force_var, pos_traj, &
pos_traj_read
TYPE(cp_logger_type), POINTER :: logger
TYPE(mp_comm_type) :: mpi_comm_master, mpi_comm_slave, &
mpi_comm_slave_primus
TYPE(mp_comm_type) :: mpi_comm_master, mpi_comm_minion, &
mpi_comm_minion_primus
TYPE(opt_state_type) :: ostate
TYPE(section_vals_type), POINTER :: oi_section, variable_section

Expand Down Expand Up @@ -232,11 +232,11 @@ SUBROUTINE force_matching(oi_env, input_declaration, root_section, para_env)
ALLOCATE (group_distribution(0:num_pe_master - 1))
IF (oi_env%fm_env%group_size > para_env%num_pe) oi_env%fm_env%group_size = para_env%num_pe

CALL mpi_comm_slave%from_split(mpi_comm_master, n_groups, group_distribution, subgroup_min_size=oi_env%fm_env%group_size)
mepos_slave = mpi_comm_slave%mepos
CALL mpi_comm_minion%from_split(mpi_comm_master, n_groups, group_distribution, subgroup_min_size=oi_env%fm_env%group_size)
mepos_minion = mpi_comm_minion%mepos
color = 0
IF (mepos_slave == 0) color = 1
CALL mpi_comm_slave_primus%from_split(mpi_comm_master, color)
IF (mepos_minion == 0) color = 1
CALL mpi_comm_minion_primus%from_split(mpi_comm_master, color)

! assign initial variables
n_var = SIZE(oi_env%variables, 1)
Expand Down Expand Up @@ -320,13 +320,13 @@ SUBROUTINE force_matching(oi_env, input_declaration, root_section, para_env)
ierr = 0
CALL create_force_env(new_env_id=new_env_id, input_declaration=input_declaration, &
input_path=input_path, output_path=output_path, &
mpi_comm=mpi_comm_slave, initial_variables=initial_variables, ierr=ierr)
mpi_comm=mpi_comm_minion, initial_variables=initial_variables, ierr=ierr)

! set to zero initialy, for easier mp_summing
energy_var = 0.0_dp
force_var = 0.0_dp

! compute energies and forces for all frames, doing the work on a slave sub group based on round robin
! compute energies and forces for all frames, doing the work on a minion sub group based on round robin
t5 = 0.0_dp
DO i_frame = group_distribution(mepos_master) + 1, n_frames, n_groups

Expand Down Expand Up @@ -366,13 +366,13 @@ SUBROUTINE force_matching(oi_env, input_declaration, root_section, para_env)
CALL destroy_force_env(env_id=new_env_id, ierr=ierr)

! get data everywhere on the master group, we could reduce the amount of data by reducing to partial RMSD first
! furthermore, we should only do this operation among the masters of the slave group
IF (mepos_slave == 0) THEN
CALL mpi_comm_slave_primus%sum(energy_var)
CALL mpi_comm_slave_primus%sum(force_var)
! furthermore, we should only do this operation among the masters of the minion group
IF (mepos_minion == 0) THEN
CALL mpi_comm_minion_primus%sum(energy_var)
CALL mpi_comm_minion_primus%sum(force_var)
END IF

! now evaluate the target function to be minimized (only valid on mepos_slave==0)
! now evaluate the target function to be minimized (only valid on mepos_minion==0)
IF (para_env%is_source()) THEN
rf = SQRT(SUM((force_var - force_traj)**2)/(REAL(n_frames, KIND=dp)*REAL(n_atom, KIND=dp)))
IF (oi_env%fm_env%shift_average) THEN
Expand Down Expand Up @@ -480,8 +480,8 @@ SUBROUTINE force_matching(oi_env, input_declaration, root_section, para_env)
IF (ASSOCIATED(cell_traj)) DEALLOCATE (cell_traj)
DEALLOCATE (pos, force, force_traj, pos_traj, force_var)
DEALLOCATE (group_distribution, energy_traj, energy_var)
CALL mpi_comm_slave%free()
CALL mpi_comm_slave_primus%free()
CALL mpi_comm_minion%free()
CALL mpi_comm_minion_primus%free()

CALL timestop(handle)

Expand Down

0 comments on commit b951fa5

Please sign in to comment.