open-AIMS / ADRIA_matlab

Repository for the development of ADRIA: Adaptive Dynamic Reef Intervention Algorithms. ADRIA is a multi-criteria decision support tool set particularly useful for informing reef restoration and adaptation interventions.
1 stars 0 forks source link

Runtime and memory use #107

Closed ConnectedSystems closed 2 years ago

ConnectedSystems commented 2 years ago

I have vectorized most of the calculations in growthODE4_KA() (see the currently very messy version here: https://github.com/open-AIMS/ADRIA_repo/blob/main/ADRIAfunctions/growthODE4_KA.m)

The changes have reduced overall runtime by ~36% when running single core simulations, and between 40-50% when running in parallel batches. I suspect more could be done.

@veroniquelago @Rosejoycrocker when you have the time, would you care to have another look? I've scanned over the code many times now and I can only pick out one or two minor changes that could be done, and I am not sure how much of an improvement they would be.

My other idea was to move this core function to C, possibly via MATLAB Coder (https://au.mathworks.com/help/coder/) In my initial attempt with MATLAB Coder I got an error due to the element-wise operations. Maybe I'm missing an setting or option somewhere...

Rosejoycrocker commented 2 years ago

Hi @ConnectedSystems, I'll have another look and see what I can do but it seems we may have reached a limit as you say. The matlab coder idea sounds good. Would you make the core function C and then have the run function be a mex file to call the C code from matlab? or would it be pure C?

ConnectedSystems commented 2 years ago

I think mex as a first attempt is best. I can try a pure C version later if needed but I think that would require a lot more effort.

@veroniquelago do you have any experience with this (either using MATLAB Coder or interfacing with a pure C function)?

veroniquelago commented 2 years ago

Not in Matlab. I coded in pure C++ at uni (undergrad) a long time ago, but I've never put it in Matlab.

Vero

On Mon, 28 Feb 2022, 10:17 am Takuya Iwanaga, @.***> wrote:

I think mex as a first attempt is best. I can try a pure C version later if needed but I think that would require a lot more effort.

@veroniquelago https://github.com/veroniquelago do you have any experience with this (either using MATLAB Coder or interfacing with a pure C function)?

— Reply to this email directly, view it on GitHub https://github.com/open-AIMS/ADRIA_repo/issues/107#issuecomment-1053716930, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVNNPQJOEWRX6E7MEKOMMJLU5KWHZANCNFSM5PJGZ4OQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

ConnectedSystems commented 2 years ago

Additional changes made (implemented in the Brick modelling branch) which brought runtime back down to ~0.7 seconds per simulation.

Implementing a mex file does help a little, but deploying and supporting a variety of different platforms (linux/mac/windows) will be a bit of a headache so am avoiding this path for now.

I've found some additional modifications that may reduce runtime and memory further, but will raise a new issue for this., so closing this issue in favour of that one. Thanks all for your input.