Try to speed up init_interp
- Dominant language
- Fortran
- Stars
- 352
- Forks
- 361
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
This issue is mainly for the benefit of testing: A lot of our test time / cost is spent interpolating initial conditions. This is especially true for short, high-resolution test cases. Our test suite could be significantly less expensive (in core-hour cost) if we could speed up init_interp.
A few initial ideas on things we could do:
- Optimize the logic in `set_mindist` (which is where a lot of the time is spent, if I remember correctly); for example:
- Rearranging conditionals so that we decide that each given source point is not the closest match with as little work as possible
- Avoiding unnecessary math (e.g., the multiplication by the earth's radius is unnecessary)
- Avoiding the redundant string match checks in `is_sametype` (on both subgridi and subgrido): this redundancy is done for the sake of defensive programming, but we can do that checking outside of the loop
- A bigger change but one that could significantly speed things up would be: ensure all of the source grid cells are ordered by landunit type. Then we could determine the starting and ending index for each landunit type, and only loop over the matching landunit type (or, in some cases, matching landunit types, plural, because we may need to search all of the vegetated landunits). I'm guessing that we could roughly cut the search time in half this way, at the cost of a bit more complexity.
- There may be ways to be smarter about how we do the spatial nearest neighbor search, too, rather than doing an exhaustive search of all points. This may require an initial ordering of points, which may not work with the above bullet point about ordering by landunit, but could give a bigger benefit if it works.
Contributor guide
Assessment
This issue has not been assessed yet.