[Scilab-users] repmat() slow compared to .* and .*. <= Re: More rapid calculation

Stéphane Mottelet stephane.mottelet at utc.fr
Fri Feb 16 08:24:06 CET 2018


Hello Samuel,

It is a good initiative. Looking at your proposed code, I see that you 
use "execstr" on strings which are forged on the fly. Although the 
obtained expression will be faster (this was the goal), AFAIK such 
constructs are not "compilable" the same way as the straight expression. 
For the time being, Scilab does not use JIT compilation, but I think 
that such  constructs are typically not optimal and that it/then/else 
constructs should be used instead.

S.


Le 16/02/2018 à 07:48, Samuel Gougeon a écrit :
> Le 15/02/2018 à 11:45, Stéphane Mottelet a écrit :
>> Le 15/02/2018 à 00:02, fujimoto2005 a écrit :
>>> .../...
>>
>> Hello,
>>
>> In your code, most of the cpu time is spent between lines 40-54 
>> (random generation of big matrices), then between lines 54-60, where 
>> one of the bottlenecks is the use of repmat (and you use it twice) 
>> and the "cumsum".In previous posts of Heinz Nabielek related to code 
>> optimization, you may have noticed that using matrix multiplication 
>> by a vector of ones gives the same result BUT uses the BLAS ! For 
>> example, compare these timings, with size(timePoints_V)=[1 25000] and 
>> sample=5000) :
>>
>> tic;repmat(timePoints_V,2*sample,1);disp(toc())
>>
>>    12.372273
>>
>> tic;ones(2*sample,1)*timePoints_V;disp(toc())
>>
>>    1.823105
>>
>> On my machine (MacPro, OSX, Scilab 6.0.0), this last piece of code 
>> uses 100% cpu (four cores).
>
> Thank you Stéphane for having pointed out the repmat() slowness.
>
> Additional tests show that the Kronecker product is even slightly 
> faster than .*
>
> A new version of repmat() is proposed on review: 
> https://codereview.scilab.org/19782
> It is rewritten mainly using .*., which simplifies a lot the code.
>
> This version is more than 7x faster than the current one, and uses 
> both CPU of my PC.
> It is roughly the ratio 12.37/1.82 ~ 6.8 that you give here-above.
>
> Best regards
> Samuel
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users




More information about the users mailing list