Feature: improve memory handling in Kirchhoff operator #494
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
This PR is mainly aimed at improving the memory efficiency of the
Kirchhoff
operator.In the current implementation, we create an overall
trav
table (similar foramp
indynamic=True
mode) of sizenynxnz x nsnr
. Assumingns=nr
this scales quadratically with thens
.In the new implementation, we handle source and receiver tables independently (
trav_srcs
andtrav_recs
) and not merge them into a unique table. Assumingns=nr
this scales linearly with thens
.Changes
The following changes are introduced:
_travsrcrec_kirch_matvec
,_travsrcrec_kirch_rmatvec
,_amp_kirch_matvec
, and_amp_kirch_rmatvec
, which are the counterparts of_trav_kirch_matvec
,_trav_kirch_rmatvec
,_ampsrcrec_kirch_matvec
, and_ampsrcrec_kirch_rmatvec
which used full tablestrav
andamp
can now be provided as nd.arrays or tuples of 2 nd.arrays. In the second case, these Arte the src and rec tables. Internally the__init__
operator handles both cases to ensure backward compatibility._traveltime_table
is changed. However, being this a private method we should not expect users to use it (aka users should not expect us not to make changes), so I believe this is fine.Performance tests
I run the following two performance tests using this code:
and equivalent code with old version of Kirchoff.
dynamic=False
dynamic=True