Specifying optimization flags in mex

28 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2018-1-3
"(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 个评论
Royi Avital
Royi Avital 2020-4-23
Isn't there a dedicated command for Macros?
Walter Roberson
Walter Roberson 2020-4-23
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by