<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168169</link>
    <title>MATLAB Central Newsreader - very slow vectorized code</title>
    <description>Feed for thread: very slow vectorized code</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 24 Apr 2008 06:50:04 -0400</pubDate>
      <title>very slow vectorized code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168169#428562</link>
      <author>Julian Reichl</author>
      <description>Hi all,&lt;br&gt;
I have a problem that I can't figure out.  I have two&lt;br&gt;
versions of some code, one vectorised, the other not. The&lt;br&gt;
vectorised version runs WAY slower for single repeats - ~17&lt;br&gt;
seconds cf. 0.3 seconds.&lt;br&gt;
&lt;br&gt;
The profiler tells me that pretty much every line of the&lt;br&gt;
code is a lot slower in the vectorised version. Even simple&lt;br&gt;
things like &lt;br&gt;
&lt;br&gt;
e=repmat(1,1);&lt;br&gt;
for i=1:28305&lt;br&gt;
e(:,:)=0;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
(the 1:28305 is a time-stepping loop and can't be removed)&lt;br&gt;
takes 0.39 s inside the vectorised code (not including the&lt;br&gt;
repmat), whereas in the command line it takes less than a&lt;br&gt;
10th of that time.&lt;br&gt;
if, in the same code (the vectorised version), I replace it&lt;br&gt;
with &lt;br&gt;
&lt;br&gt;
for i=1:28305&lt;br&gt;
e=0;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
(which is fine for this example because it's a 1x1, but not&lt;br&gt;
for my application), the time for that function drops,&lt;br&gt;
again, to ~ a 10th. &lt;br&gt;
&lt;br&gt;
I really hope someone has an idea!!!&lt;br&gt;
&lt;br&gt;
thanks&lt;br&gt;
&lt;br&gt;
Julian&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Thu, 24 Apr 2008 07:07:02 -0400</pubDate>
      <title>Re: very slow vectorized code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168169#428565</link>
      <author>Julian Reichl</author>
      <description>I just tried commenting out all the other code within the loop &lt;br&gt;
i=1:28305&lt;br&gt;
...&lt;br&gt;
end&lt;br&gt;
and it bought that e(:,:)=0;&lt;br&gt;
statement back to 0.04s. So could this mean that there is&lt;br&gt;
some memory issue?&lt;br&gt;
&lt;br&gt;
"Julian Reichl" &amp;lt;julesreichl@yahoo.co.uk&amp;gt; wrote in message&lt;br&gt;
&amp;lt;fupais$8av$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi all,&lt;br&gt;
&amp;gt; I have a problem that I can't figure out.  I have two&lt;br&gt;
&amp;gt; versions of some code, one vectorised, the other not. The&lt;br&gt;
&amp;gt; vectorised version runs WAY slower for single repeats - ~17&lt;br&gt;
&amp;gt; seconds cf. 0.3 seconds.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The profiler tells me that pretty much every line of the&lt;br&gt;
&amp;gt; code is a lot slower in the vectorised version. Even simple&lt;br&gt;
&amp;gt; things like &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; e=repmat(1,1);&lt;br&gt;
&amp;gt; for i=1:28305&lt;br&gt;
&amp;gt; e(:,:)=0;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; (the 1:28305 is a time-stepping loop and can't be removed)&lt;br&gt;
&amp;gt; takes 0.39 s inside the vectorised code (not including the&lt;br&gt;
&amp;gt; repmat), whereas in the command line it takes less than a&lt;br&gt;
&amp;gt; 10th of that time.&lt;br&gt;
&amp;gt; if, in the same code (the vectorised version), I replace it&lt;br&gt;
&amp;gt; with &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for i=1:28305&lt;br&gt;
&amp;gt; e=0;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; (which is fine for this example because it's a 1x1, but not&lt;br&gt;
&amp;gt; for my application), the time for that function drops,&lt;br&gt;
&amp;gt; again, to ~ a 10th. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I really hope someone has an idea!!!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; thanks&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Julian&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 25 Apr 2008 15:26:17 -0400</pubDate>
      <title>Re: very slow vectorized code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168169#428860</link>
      <author>Bill Nell</author>
      <description>Julian Reichl wrote:&lt;br&gt;
&amp;gt; I just tried commenting out all the other code within the loop &lt;br&gt;
&amp;gt; i=1:28305&lt;br&gt;
&amp;gt; ...&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; and it bought that e(:,:)=0;&lt;br&gt;
&amp;gt; statement back to 0.04s. So could this mean that there is&lt;br&gt;
&amp;gt; some memory issue?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; "Julian Reichl" &amp;lt;julesreichl@yahoo.co.uk&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;lt;fupais$8av$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; Hi all,&lt;br&gt;
&amp;gt;&amp;gt; I have a problem that I can't figure out.  I have two&lt;br&gt;
&amp;gt;&amp;gt; versions of some code, one vectorised, the other not. The&lt;br&gt;
&amp;gt;&amp;gt; vectorised version runs WAY slower for single repeats - ~17&lt;br&gt;
&amp;gt;&amp;gt; seconds cf. 0.3 seconds.&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; The profiler tells me that pretty much every line of the&lt;br&gt;
&amp;gt;&amp;gt; code is a lot slower in the vectorised version. Even simple&lt;br&gt;
&amp;gt;&amp;gt; things like &lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; e=repmat(1,1);&lt;br&gt;
&amp;gt;&amp;gt; for i=1:28305&lt;br&gt;
&amp;gt;&amp;gt; e(:,:)=0;&lt;br&gt;
&amp;gt;&amp;gt; end&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; (the 1:28305 is a time-stepping loop and can't be removed)&lt;br&gt;
&amp;gt;&amp;gt; takes 0.39 s inside the vectorised code (not including the&lt;br&gt;
&amp;gt;&amp;gt; repmat), whereas in the command line it takes less than a&lt;br&gt;
&amp;gt;&amp;gt; 10th of that time.&lt;br&gt;
&amp;gt;&amp;gt; if, in the same code (the vectorised version), I replace it&lt;br&gt;
&amp;gt;&amp;gt; with &lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; for i=1:28305&lt;br&gt;
&amp;gt;&amp;gt; e=0;&lt;br&gt;
&amp;gt;&amp;gt; end&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; (which is fine for this example because it's a 1x1, but not&lt;br&gt;
&amp;gt;&amp;gt; for my application), the time for that function drops,&lt;br&gt;
&amp;gt;&amp;gt; again, to ~ a 10th. &lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; I really hope someone has an idea!!!&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; thanks&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; Julian&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Julian,&lt;br&gt;
If you are just trying to set the contents of e to 0 then just use&lt;br&gt;
e(:) = 0 instead of e(:,:) = 0.&lt;br&gt;
&lt;br&gt;
Bill&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Fri, 25 Apr 2008 19:18:01 -0400</pubDate>
      <title>Re: very slow vectorized code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168169#428898</link>
      <author>Yi Cao</author>
      <description>"Julian Reichl" &amp;lt;julesreichl@yahoo.co.uk&amp;gt; wrote in message &lt;br&gt;
&amp;lt;fupbim$hs6$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I just tried commenting out all the other code within the &lt;br&gt;
loop &lt;br&gt;
&amp;gt; i=1:28305&lt;br&gt;
&amp;gt; ...&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; and it bought that e(:,:)=0;&lt;br&gt;
&amp;gt; statement back to 0.04s. So could this mean that there is&lt;br&gt;
&amp;gt; some memory issue?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; "Julian Reichl" &amp;lt;julesreichl@yahoo.co.uk&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;lt;fupais$8av$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; Hi all,&lt;br&gt;
&amp;gt; &amp;gt; I have a problem that I can't figure out.  I have two&lt;br&gt;
&amp;gt; &amp;gt; versions of some code, one vectorised, the other not. &lt;br&gt;
The&lt;br&gt;
&amp;gt; &amp;gt; vectorised version runs WAY slower for single repeats - &lt;br&gt;
~17&lt;br&gt;
&amp;gt; &amp;gt; seconds cf. 0.3 seconds.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; The profiler tells me that pretty much every line of the&lt;br&gt;
&amp;gt; &amp;gt; code is a lot slower in the vectorised version. Even &lt;br&gt;
simple&lt;br&gt;
&amp;gt; &amp;gt; things like &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; e=repmat(1,1);&lt;br&gt;
&amp;gt; &amp;gt; for i=1:28305&lt;br&gt;
&amp;gt; &amp;gt; e(:,:)=0;&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; (the 1:28305 is a time-stepping loop and can't be &lt;br&gt;
removed)&lt;br&gt;
&amp;gt; &amp;gt; takes 0.39 s inside the vectorised code (not including &lt;br&gt;
the&lt;br&gt;
&amp;gt; &amp;gt; repmat), whereas in the command line it takes less than &lt;br&gt;
a&lt;br&gt;
&amp;gt; &amp;gt; 10th of that time.&lt;br&gt;
&amp;gt; &amp;gt; if, in the same code (the vectorised version), I &lt;br&gt;
replace it&lt;br&gt;
&amp;gt; &amp;gt; with &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; for i=1:28305&lt;br&gt;
&amp;gt; &amp;gt; e=0;&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; (which is fine for this example because it's a 1x1, but &lt;br&gt;
not&lt;br&gt;
&amp;gt; &amp;gt; for my application), the time for that function drops,&lt;br&gt;
&amp;gt; &amp;gt; again, to ~ a 10th. &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I really hope someone has an idea!!!&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; thanks&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Julian&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
I guess this is because JIT accelerator, i.e. your &lt;br&gt;
vectorized code is quite complicated, hence the JIT &lt;br&gt;
accelerator is not able to accelerate it, while your simple &lt;br&gt;
loop version is in favour for the JIT to accelerate. When &lt;br&gt;
you remove all other lines in the loop, the vectorized &lt;br&gt;
version becomes simple as well, hence the JIT can &lt;br&gt;
accelerate it now. That is why you see speed improvement. &lt;br&gt;
To demonstrate this, you can try run your code with JIT on &lt;br&gt;
and off by using the command:&lt;br&gt;
&lt;br&gt;
feature accel on&lt;br&gt;
&lt;br&gt;
or&lt;br&gt;
&lt;br&gt;
feature accel off&lt;br&gt;
&lt;br&gt;
to see if this is the case.&lt;br&gt;
&lt;br&gt;
hth&lt;br&gt;
Yi Cao &lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Tue, 29 Apr 2008 03:24:01 -0400</pubDate>
      <title>Re: very slow vectorized code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/168169#429291</link>
      <author>Julian Reichl</author>
      <description>Thanks Bill and Yi Cao for your replies...&lt;br&gt;
I'll check out the JIT thing and let you know how I go,&lt;br&gt;
&lt;br&gt;
cheers&lt;br&gt;
Julian&lt;br&gt;
&lt;br&gt;
"Yi Cao" &amp;lt;y.cao@cranfield.ac.uk&amp;gt; wrote in message&lt;br&gt;
&amp;lt;futap9$f0d$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "Julian Reichl" &amp;lt;julesreichl@yahoo.co.uk&amp;gt; wrote in message &lt;br&gt;
&amp;gt; &amp;lt;fupbim$hs6$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; I just tried commenting out all the other code within the &lt;br&gt;
&amp;gt; loop &lt;br&gt;
&amp;gt; &amp;gt; i=1:28305&lt;br&gt;
&amp;gt; &amp;gt; ...&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; and it bought that e(:,:)=0;&lt;br&gt;
&amp;gt; &amp;gt; statement back to 0.04s. So could this mean that there is&lt;br&gt;
&amp;gt; &amp;gt; some memory issue?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; "Julian Reichl" &amp;lt;julesreichl@yahoo.co.uk&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;gt; &amp;lt;fupais$8av$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Hi all,&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I have a problem that I can't figure out.  I have two&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; versions of some code, one vectorised, the other not. &lt;br&gt;
&amp;gt; The&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; vectorised version runs WAY slower for single repeats - &lt;br&gt;
&amp;gt; ~17&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; seconds cf. 0.3 seconds.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; The profiler tells me that pretty much every line of the&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; code is a lot slower in the vectorised version. Even &lt;br&gt;
&amp;gt; simple&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; things like &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; e=repmat(1,1);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; for i=1:28305&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; e(:,:)=0;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; (the 1:28305 is a time-stepping loop and can't be &lt;br&gt;
&amp;gt; removed)&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; takes 0.39 s inside the vectorised code (not including &lt;br&gt;
&amp;gt; the&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; repmat), whereas in the command line it takes less than &lt;br&gt;
&amp;gt; a&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; 10th of that time.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; if, in the same code (the vectorised version), I &lt;br&gt;
&amp;gt; replace it&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; with &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; for i=1:28305&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; e=0;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; (which is fine for this example because it's a 1x1, but &lt;br&gt;
&amp;gt; not&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; for my application), the time for that function drops,&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; again, to ~ a 10th. &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I really hope someone has an idea!!!&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; thanks&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Julian&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I guess this is because JIT accelerator, i.e. your &lt;br&gt;
&amp;gt; vectorized code is quite complicated, hence the JIT &lt;br&gt;
&amp;gt; accelerator is not able to accelerate it, while your simple &lt;br&gt;
&amp;gt; loop version is in favour for the JIT to accelerate. When &lt;br&gt;
&amp;gt; you remove all other lines in the loop, the vectorized &lt;br&gt;
&amp;gt; version becomes simple as well, hence the JIT can &lt;br&gt;
&amp;gt; accelerate it now. That is why you see speed improvement. &lt;br&gt;
&amp;gt; To demonstrate this, you can try run your code with JIT on &lt;br&gt;
&amp;gt; and off by using the command:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; feature accel on&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; or&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; feature accel off&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; to see if this is the case.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; hth&lt;br&gt;
&amp;gt; Yi Cao &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
