Specifying optimization flags in mex

31 ビュー (過去 30 日間)
jh2011
jh2011 2018 年 1 月 3 日
コメント済み: Walter Roberson 2020 年 4 月 23 日
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 Center および File ExchangeWrite 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