optimise_nprocs Subroutine

public subroutine optimise_nprocs(state)

FIXME : Add documentation

Arguments

Type IntentOptional Attributes Name
type(gs2_program_state_type), intent(inout) :: state

Contents

Source Code


Source Code

  subroutine optimise_nprocs(state)
    use mp, only: proc0
    use ingen_mod, only: init_ingen, finish_ingen, report
    use ingen_mod, only: sweet_spots, n_sweet_spots
    use gs2_main, only: initialize_gs2, initialize_equations, initialize_diagnostics
    use gs2_main, only: finalize_gs2, finalize_equations, finalize_diagnostics
    implicit none
    type(gs2_program_state_type), intent(inout) :: state
    integer :: i

    state%init%opt_ov%override_nproc = .false.
    ! First measure performance using all procs
    call optimise_fields(state)

    call init_ingen
    call initialize_gs2(state)
    call initialize_equations(state)
    call initialize_diagnostics(state)
    if (proc0) call report
    call finalize_diagnostics(state)
    call finalize_equations(state)
    call finalize_gs2(state)

    ! Loop through all sweet spots and measure performance
    do i = 1,n_sweet_spots
       if (sweet_spots(i)%nproc .gt. state%optim%nproc_max) exit
       ! If asked to check for inefficencies, check all proc numbers
       ! otherwise only check proc numbers that satisfy
       ! max_imbalance and max_unused_procs
       if (.not. (state%optim%min_efficiency .gt. 0)) then
          if ( state%optim%max_unused_procs .ge. 0 .and. &
               (state%optim%nproc_max - sweet_spots(i)%nproc) .gt.&
               state%optim%max_unused_procs ) cycle
          if ( state%optim%max_imbalance .gt. 0.0 .and. &
               (state%optim%nproc_max - sweet_spots(i)%nproc) / &
               state%optim%nproc_max .gt.&
               state%optim%max_imbalance ) cycle
       end if
       state%init%opt_ov%override_nproc = .true.
       state%init%opt_ov%nproc = sweet_spots(i)%nproc
       call optimise_fields(state)
    end do
    call finish_ingen
    !end if
  end subroutine optimise_nprocs