Skip to content

Refactors to improve performance#257

Merged
DrPaulSharp merged 9 commits intoRascalSoftware:masterfrom
DrPaulSharp:issues
Aug 22, 2024
Merged

Refactors to improve performance#257
DrPaulSharp merged 9 commits intoRascalSoftware:masterfrom
DrPaulSharp:issues

Conversation

@DrPaulSharp
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@StephenNneji StephenNneji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Paul, please this PR needs clarification. I can kind of see the attempt to improve memory by changing the array sizes on the input array but I am not sure where the new values come from and I think there is now a mismatch between the input values in makeCompileArgs and the result values you've set.

I don't fully understand the reasons behind the refactors to callReflectivity and if or how they improve performance

@DrPaulSharp
Copy link
Collaborator Author

DrPaulSharp commented Aug 15, 2024

Good point about the limit in makeCompileArgs - there's not much point limiting the values on the way out but not the way in! I'm hopeful that reducing the limit will improve the memory issues we have encountered, and it's probably best now to grasp the nettle and make sure we do it in all places. The code does build correctly with the reduced limit, but leave it with me and I'll see if we find any improvement in memory/performance as the limit is reduced.

@DrPaulSharp DrPaulSharp force-pushed the issues branch 2 times, most recently from 0078d1e to b3e7783 Compare August 20, 2024 08:51
@DrPaulSharp DrPaulSharp changed the title Improves performance and memory usage Refactors to improve performance Aug 20, 2024
%% Define argument types for entry-point 'reflectivityCalculation'.
%% Define argument types for entry-point 'RATMain'.
maxArraySize = 10000;
maxDataSize = 10000;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these bounds are needed. Theses values should just be Inf except where we actually have a bound, to the best of my knowledge the memory is allocated as needed so not sure the reason for the artificial handicap. @arwelHughes do you remember the original reason for the max size?

Is it possible that something like the data (problemCells{2} = inputStruct.data) can exceed our artificial limit of 10000 rows maybe someone doing a simulation or something?

sldXDataCell = [1 1 1; 1 1 1];
coder.varsize('sldXDataCell',[2 1e4],[1 1]);
domainSldXDataCell = [1 1 1; 1 1 1];
coder.varsize('domainSldXDataCell',[2 1e4],[0 1]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is meant to be the other way around

coder.varsize('domainSldXDataCell',[2 1e4],[1 0]);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? I've written that the fixed dimension has size 2 since there are always two domains, and the variable size dimension has size up to 1e4: https://uk.mathworks.com/help/coder/ref/coder.varsize.html

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I was looking at the size of sldXData.

Please have a look at refPercentileConfidenceIntervals it does not have separate dimensions for the domains. is this a bug?

coder.varsize('rowVals',[1 1e4],[0 1]);

@arwelHughes
Copy link
Collaborator

arwelHughes commented Aug 20, 2024 via email

@StephenNneji
Copy link
Collaborator

@arwelHughes The link you shared says

Whenever the upper bounds are fixed variables can be still allocated in stack, so the dynamic memory alloaction may not be required (not always true !) .

Stack allocation is not guaranteed which makes sense as the stack can be as small as 1MB on some machines. From my look at the generated code we are already using the heap a lot even when we set an upper bound, it seems as longer as both dimension are not fixed it used the heap array so for example

coder.varsize('outlierChains',[1e3 1e3],[1 1]); used a bounded array on stack because both dimensions are fixed whereas coder.varsize('percentile65',[2 1e3],[0 1]) uses heap memory so we are not getting any benefit from setting the upper bound on variable sized arrays

end
end

fitParams = zeros(1,nParams);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this match the other fitParams that is now a row array?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing as it's a simple change, yes!

@DrPaulSharp DrPaulSharp merged commit 113a952 into RascalSoftware:master Aug 22, 2024
@DrPaulSharp DrPaulSharp deleted the issues branch August 22, 2024 14:17
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.

3 participants