Skip to content

Reduce usage of pow() and log()#92

Open
coco-yeung wants to merge 3 commits intoMIT-LAE:mainfrom
coco-yeung:main
Open

Reduce usage of pow() and log()#92
coco-yeung wants to merge 3 commits intoMIT-LAE:mainfrom
coco-yeung:main

Conversation

@coco-yeung
Copy link

@coco-yeung coco-yeung commented Feb 16, 2026

In the current version of the code running the issl_rhi140 example, around 20% of computational time is spent on the pow() function when running on 1 thread: see perf profiling below
image

Changes have been made to the code to reduce the reliance on pow(). The most notable changes were:

  • Aerosol.cpp: implemented a switch case in the Moment functions as the power n is only ever 0, 1, 2, or 3, and saving log() results in the loop to prevent repeated calculations
  • Aerosol.hpp: bypassing pow() as it is only called by LAGRIDPlumeModel.cpp where the power n is 0; it also returns the value before it is multiplied by the logBinRatio since the loop which calls it also calculates it.

Other changes made are to compute pow(x, 2) as x*x or pow(x, 1/3) as cbrt(x) instead, although I believe that made minimal difference as the compiler could already make those optimisations.

This resulted in a decrease in % time spent in the functions pow() and log(): see perf profiling below
image
image

The real time decrease for the different weather conditions are below:

<style> </style>
version default (issl_rhi140) shear * 1.1 rhi 120 temperature - 5 w - 0.1
main (seconds) 967 1028 1671 1157 796
feature (seconds) 710 767 1257 849 587
decrease (%) -26.58 -25.39 -24.75 -26.62 -26.26

The changes are also zero-diff with the current main branch, verified by taking the difference between the ice mass over time and the number of ice particles at each output time.

coco-yeung and others added 3 commits January 22, 2026 10:47
* Adds profiling tags, standardise seed and set num threads to 1 in issl_rhi140 example

Co-authored-by: Coco Yeung <coco.yeung22@imperial.ac.uk>
Add input files for different weather conditions

---------

Co-authored-by: Coco Yeung <coco.yeung22@imperial.ac.uk>
* Add profiling flags

* Replaced pow()

* Aerosol

* Added more optimisations

* Code clean-up

---------

Co-authored-by: Coco Yeung <coco.yeung22@imperial.ac.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant