Code acceleration by mex-file
2 ビュー (過去 30 日間)
I'am new to the mex-section, but I wanted to accelerate my code, more a very specific time consuming function.
To start with I wrote a little funtction to see how much faster this function as mex is. The same is done in a tutorial, bot somehow my mex code isn't as fast as the one in the tutorial. So my question is on what exactly does the speed up with mex functions depends on?
Above is my function, that I run in Matlab as you see it above, and as mex-function.
Here on my Laptop Matlab needs fpr N=10^8 about 9 seconds (same as in the tutorial). My mex function needs about 7 seconds, whereas it needs only 1 second in the tutorial. So what am I doing different?
Its not a function where memory should be the bootleneck. And on my much faster desktop pc I can run the MatLab code for same N in only 4 seconds, mex also needs 4sec here.
Why would my Laptop take the same time for the matlab code, but 7 times longer for the mex code??
Where is the secret?
Maybe somebody coukld help me with this.
Many thanks in advance
Raghu Boggavarapu 2020 年 12 月 3 日
mod(counter,2) is an expensive function when dealing with floating point inputs. Please modify the code as follows to see speed up in MEX execution time :
- Avoid floating point arithmetic where unnecessary to speed up the execution.
- Additionally turn off "Integrity Checks" and "Responsiveness Checks" in MEX configuration to speed up the execution time.
その他の回答 (0 件)
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!