Specifying optimization flags in mex

28 views (last 30 days)
I know that -O is implemented by default when I use the mex command
mex file.cpp
However, I have two questions related to that
(1) Is -O the same as -O when compile c++ files with g++ (i.e. when I'm not using mex)
(2) How can I implement -O3 without a makefile?

Accepted Answer

Walter Roberson
Walter Roberson on 3 Jan 2018
"(1) Is -O the same as -O when compile c++ files with g++ (i.e. when I'm not using mex)"
Yes. However, -O for mex is treated as -O2 instead of bare -O
"(2) How can I implement -O3 without a makefile?"
Use
mex -v YourFileName.c
and look through the output for COPTIMFLAGS . Copy the flags there changing -O2 to -O3 and insert that into
mex COPTIMFLAGS="THOSE GO HERE" YourFileName.c
for example,
mex -v COPTIMFLAGS="-O3 -fwrapv -DNDEBUG" tt.c
  2 Comments
Royi Avital
Royi Avital on 23 Apr 2020
Isn't there a dedicated command for Macros?
Walter Roberson
Walter Roberson on 23 Apr 2020
There is a series of functions for adjusting various aspects of the toolchain, and it is plausible that you might be able to use the functions to request a copy of the current toolchain, and modify that, and save it, after which there would be a command to activate it. Or perhaps that only applies to MATLAB Compiler or Coder; I am not sure.
There is no simple command along the lines of
mexconfig optimize -O3 %does not exist

Sign in to comment.

More Answers (0)

Categories

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!