Skip to content

Commit cbe0d41

Browse files
authored
Merge pull request #368 from NCAR/get_close_caching
Removal of redundant caching in assim_tools_mod.f90
2 parents 9c7d829 + 6dc832c commit cbe0d41

File tree

3 files changed

+13
-37
lines changed

3 files changed

+13
-37
lines changed

CHANGELOG.rst

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ individual files.
2222

2323
The changes are now listed with the most recent at the top.
2424

25+
**July 14 2022 :: Performance improvement - removal of redundant caching. Tag: v10.0.3**
26+
- Reduces the runtime by removing redundant caching in the get_close_obs_cached and
27+
get_close_state_cached subroutines in assim_tools_mod.f90
28+
2529
**June 24 2022 :: Bug-fixes for MITgcm_ocean and Var obs converter. Tag: v10.0.2**
2630

2731
- MITgcm_ocean pert_model_copies routine fixed to use the correct variable clamping

assimilation_code/modules/assimilation/assim_tools_mod.f90

+8-36
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,6 @@ subroutine filter_assim(ens_handle, obs_ens_handle, obs_seq, keys, &
332332
real(r8) :: vertvalue_obs_in_localization_coord, whichvert_real
333333
real(r8), allocatable :: close_obs_dist(:)
334334
real(r8), allocatable :: close_state_dist(:)
335-
real(r8), allocatable :: last_close_obs_dist(:)
336-
real(r8), allocatable :: last_close_state_dist(:)
337335

338336
integer(i8) :: state_index
339337
integer(i8), allocatable :: my_state_indx(:)
@@ -351,8 +349,6 @@ subroutine filter_assim(ens_handle, obs_ens_handle, obs_seq, keys, &
351349
integer :: istatus, localization_unit
352350
integer, allocatable :: close_obs_ind(:)
353351
integer, allocatable :: close_state_ind(:)
354-
integer, allocatable :: last_close_obs_ind(:)
355-
integer, allocatable :: last_close_state_ind(:)
356352
integer, allocatable :: my_obs_kind(:)
357353
integer, allocatable :: my_obs_type(:)
358354
integer, allocatable :: my_state_kind(:)
@@ -376,19 +372,15 @@ subroutine filter_assim(ens_handle, obs_ens_handle, obs_seq, keys, &
376372

377373
! allocate rather than dump all this on the stack
378374
allocate(close_obs_dist( obs_ens_handle%my_num_vars), &
379-
last_close_obs_dist(obs_ens_handle%my_num_vars), &
380375
close_obs_ind( obs_ens_handle%my_num_vars), &
381-
last_close_obs_ind( obs_ens_handle%my_num_vars), &
382376
vstatus( obs_ens_handle%my_num_vars), &
383377
my_obs_indx( obs_ens_handle%my_num_vars), &
384378
my_obs_kind( obs_ens_handle%my_num_vars), &
385379
my_obs_type( obs_ens_handle%my_num_vars), &
386380
my_obs_loc( obs_ens_handle%my_num_vars))
387381

388382
allocate(close_state_dist( ens_handle%my_num_vars), &
389-
last_close_state_dist(ens_handle%my_num_vars), &
390383
close_state_ind( ens_handle%my_num_vars), &
391-
last_close_state_ind( ens_handle%my_num_vars), &
392384
my_state_indx( ens_handle%my_num_vars), &
393385
my_state_kind( ens_handle%my_num_vars), &
394386
my_state_loc( ens_handle%my_num_vars))
@@ -544,10 +536,6 @@ subroutine filter_assim(ens_handle, obs_ens_handle, obs_seq, keys, &
544536
last_base_states_loc = set_location_missing()
545537
last_num_close_obs = -1
546538
last_num_close_states = -1
547-
last_close_obs_ind(:) = -1
548-
last_close_state_ind(:) = -1
549-
last_close_obs_dist(:) = 888888.0_r8 ! something big, not small
550-
last_close_state_dist(:) = 888888.0_r8 ! ditto
551539
num_close_obs_cached = 0
552540
num_close_states_cached = 0
553541
num_close_obs_calls_made = 0
@@ -676,8 +664,8 @@ subroutine filter_assim(ens_handle, obs_ens_handle, obs_seq, keys, &
676664
! Do get_close_obs first, even though state space increments are computed before obs increments.
677665
call get_close_obs_cached(gc_obs, base_obs_loc, base_obs_type, &
678666
my_obs_loc, my_obs_kind, my_obs_type, num_close_obs, close_obs_ind, close_obs_dist, &
679-
ens_handle, last_base_obs_loc, last_num_close_obs, last_close_obs_ind, &
680-
last_close_obs_dist, num_close_obs_cached, num_close_obs_calls_made)
667+
ens_handle, last_base_obs_loc, last_num_close_obs, num_close_obs_cached, &
668+
num_close_obs_calls_made)
681669

682670
! set the cutoff default, keep a copy of the original value, and avoid
683671
! looking up the cutoff in a list if the incoming obs is an identity ob
@@ -697,8 +685,8 @@ subroutine filter_assim(ens_handle, obs_ens_handle, obs_seq, keys, &
697685
! Find state variables on my process that are close to observation being assimilated
698686
call get_close_state_cached(gc_state, base_obs_loc, base_obs_type, &
699687
my_state_loc, my_state_kind, my_state_indx, num_close_states, close_state_ind, close_state_dist, &
700-
ens_handle, last_base_states_loc, last_num_close_states, last_close_state_ind, &
701-
last_close_state_dist, num_close_states_cached, num_close_states_calls_made)
688+
ens_handle, last_base_states_loc, last_num_close_states, num_close_states_cached, &
689+
num_close_states_calls_made)
702690
!call test_close_obs_dist(close_state_dist, num_close_states, i)
703691

704692
! Loop through to update each of my state variables that is potentially close
@@ -811,20 +799,16 @@ subroutine filter_assim(ens_handle, obs_ens_handle, obs_seq, keys, &
811799

812800
! deallocate space
813801
deallocate(close_obs_dist, &
814-
last_close_obs_dist, &
815802
my_obs_indx, &
816803
my_obs_kind, &
817804
my_obs_type, &
818805
close_obs_ind, &
819-
last_close_obs_ind, &
820806
vstatus, &
821807
my_obs_loc)
822808

823809
deallocate(close_state_dist, &
824-
last_close_state_dist, &
825810
my_state_indx, &
826811
close_state_ind, &
827-
last_close_state_ind, &
828812
my_state_kind, &
829813
my_state_loc)
830814

@@ -2575,8 +2559,8 @@ end subroutine get_my_obs_loc
25752559

25762560
subroutine get_close_obs_cached(gc_obs, base_obs_loc, base_obs_type, &
25772561
my_obs_loc, my_obs_kind, my_obs_type, num_close_obs, close_obs_ind, close_obs_dist, &
2578-
ens_handle, last_base_obs_loc, last_num_close_obs, last_close_obs_ind, &
2579-
last_close_obs_dist, num_close_obs_cached, num_close_obs_calls_made)
2562+
ens_handle, last_base_obs_loc, last_num_close_obs, num_close_obs_cached, &
2563+
num_close_obs_calls_made)
25802564

25812565
type(get_close_type), intent(in) :: gc_obs
25822566
type(location_type), intent(inout) :: base_obs_loc, my_obs_loc(:)
@@ -2586,8 +2570,6 @@ subroutine get_close_obs_cached(gc_obs, base_obs_loc, base_obs_type, &
25862570
type(ensemble_type), intent(in) :: ens_handle
25872571
type(location_type), intent(inout) :: last_base_obs_loc
25882572
integer, intent(inout) :: last_num_close_obs
2589-
integer, intent(inout) :: last_close_obs_ind(:)
2590-
real(r8), intent(inout) :: last_close_obs_dist(:)
25912573
integer, intent(inout) :: num_close_obs_cached, num_close_obs_calls_made
25922574

25932575
! This logic could be arranged to make code less redundant
@@ -2598,8 +2580,6 @@ subroutine get_close_obs_cached(gc_obs, base_obs_loc, base_obs_type, &
25982580
else
25992581
if (base_obs_loc == last_base_obs_loc) then
26002582
num_close_obs = last_num_close_obs
2601-
close_obs_ind(:) = last_close_obs_ind(:)
2602-
close_obs_dist(:) = last_close_obs_dist(:)
26032583
num_close_obs_cached = num_close_obs_cached + 1
26042584
else
26052585
call get_close_obs(gc_obs, base_obs_loc, base_obs_type, &
@@ -2608,8 +2588,6 @@ subroutine get_close_obs_cached(gc_obs, base_obs_loc, base_obs_type, &
26082588

26092589
last_base_obs_loc = base_obs_loc
26102590
last_num_close_obs = num_close_obs
2611-
last_close_obs_ind(:) = close_obs_ind(:)
2612-
last_close_obs_dist(:) = close_obs_dist(:)
26132591
num_close_obs_calls_made = num_close_obs_calls_made +1
26142592
endif
26152593
endif
@@ -2622,8 +2600,8 @@ end subroutine get_close_obs_cached
26222600

26232601
subroutine get_close_state_cached(gc_state, base_obs_loc, base_obs_type, &
26242602
my_state_loc, my_state_kind, my_state_indx, num_close_states, close_state_ind, close_state_dist, &
2625-
ens_handle, last_base_states_loc, last_num_close_states, last_close_state_ind, &
2626-
last_close_state_dist, num_close_states_cached, num_close_states_calls_made)
2603+
ens_handle, last_base_states_loc, last_num_close_states, num_close_states_cached, &
2604+
num_close_states_calls_made)
26272605

26282606
type(get_close_type), intent(in) :: gc_state
26292607
type(location_type), intent(inout) :: base_obs_loc, my_state_loc(:)
@@ -2634,8 +2612,6 @@ subroutine get_close_state_cached(gc_state, base_obs_loc, base_obs_type, &
26342612
type(ensemble_type), intent(in) :: ens_handle
26352613
type(location_type), intent(inout) :: last_base_states_loc
26362614
integer, intent(inout) :: last_num_close_states
2637-
integer, intent(inout) :: last_close_state_ind(:)
2638-
real(r8), intent(inout) :: last_close_state_dist(:)
26392615
integer, intent(inout) :: num_close_states_cached, num_close_states_calls_made
26402616

26412617
! This logic could be arranged to make code less redundant
@@ -2646,8 +2622,6 @@ subroutine get_close_state_cached(gc_state, base_obs_loc, base_obs_type, &
26462622
else
26472623
if (base_obs_loc == last_base_states_loc) then
26482624
num_close_states = last_num_close_states
2649-
close_state_ind(:) = last_close_state_ind(:)
2650-
close_state_dist(:) = last_close_state_dist(:)
26512625
num_close_states_cached = num_close_states_cached + 1
26522626
else
26532627
call get_close_state(gc_state, base_obs_loc, base_obs_type, &
@@ -2656,8 +2630,6 @@ subroutine get_close_state_cached(gc_state, base_obs_loc, base_obs_type, &
26562630

26572631
last_base_states_loc = base_obs_loc
26582632
last_num_close_states = num_close_states
2659-
last_close_state_ind(:) = close_state_ind(:)
2660-
last_close_state_dist(:) = close_state_dist(:)
26612633
num_close_states_calls_made = num_close_states_calls_made +1
26622634
endif
26632635
endif

conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
author = 'Data Assimilation Research Section'
2222

2323
# The full version, including alpha/beta/rc tags
24-
release = '10.0.2'
24+
release = '10.0.3'
2525
master_doc = 'README'
2626

2727
# -- General configuration ---------------------------------------------------

0 commit comments

Comments
 (0)