-
Notifications
You must be signed in to change notification settings - Fork 1
Mex codegen #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mex codegen #162
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds MATLAB Coder MEX compilation support to enable performance optimization of the upscale function and related computations. The changes prepare the codebase for MEX code generation by adding proper type annotations, pre-allocating arrays, refactoring iteration patterns, and introducing a CodeGenMex class to manage the compilation process.
Key Changes:
- Added MEX compilation configuration class (CodeGenMex.m) with optimization settings for C++ code generation
- Pre-allocated arrays throughout the codebase for MEX compatibility (idx_adj, map_to_cond, lin_to_sub, h, etc.)
- Added argument blocks with type constraints to multiple functions for better type inference during compilation
- Refactored loop patterns from implicit column iteration to explicit indexing for MATLAB Coder compatibility
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| src/CodeGenMex.m | New class for managing MEX compilation with optimization settings (contains syntax errors) |
| src/upscale.m | Added arguments block, early return for scalar case, helper functions, and variable pre-allocation for MEX |
| src/upscale_permeability.m | Pre-allocated arrays (idx_adj, map_to_cond, lin_to_sub, A_ndiag) for MEX compatibility |
| src/strata_trapper.m | Added krw monotonization in reverse direction and removed trailing whitespace |
| src/calc_percolation.m | Pre-allocated h array and refactored loop from column iteration to explicit indexing |
| src/Options.m | Updated validation function from mustBeOfClass to mustBeA |
| src/CapPressure.m | Added explicit type constraints for perm arguments and refactored transform_perm with explicit return |
| src/export/opm_export.m | Added named arguments, default_poro/default_perm support, RUNSPEC file generation, and FIPMIP region |
| src/export/common/write_perm.m | Added default_perm parameter with initialization support |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
08dda3a to
2476669
Compare
00b27f0 to
337842e
Compare
Introduce `CodeMexGen` class that can compile the `upscale` function into MEX-file to accelerate the toolkit. How to use: ```matlab % 1. compile MEX functions codegen_mex = CodeGenMex().config().build(); % 2. use strata_trapper normally ... % 3. recompile MEX functions when the source code changes codegen_mex.build(); % 4. delete MEX functions to use the original codegen_mex.clear(); ```
No description provided.