フィルターのクリア

Compare inv(X) Vs mex inv (X)

5 ビュー (過去 30 日間)
zohar
zohar 2012 年 7 月 8 日
Hi all
I wrote a simple program which calculates inverse matrix size (100*100).
function y = test_inv(x) %#codegen
% test inverse matrix
y = inv(x);
end
I created mex function test_inv_mex and tested running time.
x = randn(100);
tic;
for n = 1: 100
y = test_inv(x);
end
toc;
tic;
for n = 1: 100
y = test_inv_mex(x);
end
toc;
This is my resulte :
Elapsed time is 0.054418 seconds.
Elapsed time is 0.613990 seconds.
My question is :
Why the mex function run much slower than regular one ?
B.R
Zohar
  4 件のコメント
zohar
zohar 2012 年 7 月 8 日
Hi Yash,
I understand the disadvantage using inv(X).
Why the mex function run much slower than the regular one ?
zohar
zohar 2012 年 7 月 8 日
Hi Jan,
I am new with codegen, but I saw that if I unchecked everything under project setting general the mex function run faster but still slower than regular one! (but warnnings appears ).
Any help ?

サインインしてコメントする。

採用された回答

Mike Hosea
Mike Hosea 2012 年 7 月 9 日
編集済み: Mike Hosea 2012 年 7 月 10 日
I think it's rather likely with a difference of that magnitude that you have left memory integrity checks on. Try
>> cfg = coder.config('mex');
>> cfg.IntegrityChecks = false;
>> cfg.ResponsivenessChecks = false;
>> codegen test_inv -args {zeros(100)} -config cfg
>> x = randn(100);
tic;
for n = 1: 100
y = test_inv(x);
end
toc;
tic;
for n = 1: 100
y = test_inv_mex(x);
end
toc;
Elapsed time is 0.082537 seconds.
Elapsed time is 0.109494 seconds.
The remaining difference is not surprising since there is some overhead and we are essentially just comparing the compiled and optimized MATLAB implementation to the compiled MATLAB Coder implementation. MATLAB Coder is not intended to speed up MATLAB linear algebra. They are mostly compiled and highly optimized routines. If it could do much of that, we'd just speed up the MATLAB implementation. If you want to see it speed something up, you usually need to have a substantial amount of your code in there. Also, in this particular case there are some differences in the algorithms. MATLAB Coder is generating unblocked code, and here the matrix is large enough that I would rather use a blocked algorithm.
  1 件のコメント
zohar
zohar 2012 年 7 月 11 日
Hi Mike, Thanks. +1

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Algorithm Acceleration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by