compile a scilab function

  • Follow


hi,

could someone explain me how to compile a scilab function to speed up
its execution time ?

is it possible? how?

thanks a lot
0
Reply bruno.donati (2) 1/23/2010 10:19:59 PM

On Jan 24, 6:19=A0am, bubu <bruno.don...@hotmail.fr> wrote:
> hi,
>
> could someone explain me how to compile a scilab function to speed up
> its execution time ?
>
> is it possible? how?
>
> thanks a lot

I don't think that will do because the scilab is just a script
language. Perhaps someone can make some changes as Matlab does( it is
said that Matlab uses a compiler to speed up )
0
Reply workaholic 1/24/2010 12:25:05 PM


Le 23/01/2010 23:19, bubu a �crit :
> hi,
> 
> could someone explain me how to compile a scilab function to speed up
> its execution time ?
> 
> is it possible? how?
> 
> thanks a lot
You cannot compile a scilab function.
You can code it as a fortran or C function, with suitable
conventions, compile it and link it in scilab.
This is not for novices !
most of the intrinsic functions of scilab are programmed
in this way.
Look at the help for the scilab   "fort"   function

Clever use of the vector and matrix primitives in scilab
will often give you similar efficiency with much less work.
0
Reply Jean 1/24/2010 3:12:19 PM

On Sun, 24 Jan 2010 16:12:19 +0100, Jean-Pierre Vial wrote:

> Le 23/01/2010 23:19, bubu a écrit :
>> hi,
>> 
>> could someone explain me how to compile a scilab function to speed up
>> its execution time ?
>> 
>> is it possible? how?
>> 
>> thanks a lot
> You cannot compile a scilab function. You can code it as a fortran or C
> function, with suitable conventions, compile it and link it in scilab.
> This is not for novices !

It takes some work to puzzle it out, and I'd only recommend it if you're 
already conversant with C, but it does work, and well.

> most of the intrinsic functions of scilab are programmed in this way.
> Look at the help for the scilab   "fort"   function
> 
> Clever use of the vector and matrix primitives in scilab will often give
> you similar efficiency with much less work.

If the problem is amenable to this, you should try it first.  I only get 
significant speedup if the problem just cannot be vectorized (e.g. I'm 
doing some seriously nonlinear filtering right now that benefits greatly 
from having the core parts of the algorithm coded in C).

-- 
www.wescottdesign.com
0
Reply Tim 1/24/2010 9:49:05 PM

On 24 jan, 22:49, Tim Wescott <t...@seemywebsite.com> wrote:
> On Sun, 24 Jan 2010 16:12:19 +0100, Jean-Pierre Vial wrote:
> > Le 23/01/2010 23:19, bubu a =E9crit :
> >> hi,
>
> >> could someone explain me how to compile a scilab function to speed up
> >> its execution time ?
>
> >> is it possible? how?
>
> >> thanks a lot
> > You cannot compile a scilab function. You can code it as a fortran or C
> > function, with suitable conventions, compile it and link it in scilab.
> > This is not for novices !
>
> It takes some work to puzzle it out, and I'd only recommend it if you're
> already conversant with C, but it does work, and well.
>
> > most of the intrinsic functions of scilab are programmed in this way.
> > Look at the help for the scilab =A0 "fort" =A0 function
>
> > Clever use of the vector and matrix primitives in scilab will often giv=
e
> > you similar efficiency with much less work.
>
> If the problem is amenable to this, you should try it first. =A0I only ge=
t
> significant speedup if the problem just cannot be vectorized (e.g. I'm
> doing some seriously nonlinear filtering right now that benefits greatly
> from having the core parts of the algorithm coded in C).
>
> --www.wescottdesign.com

thanks.

i thought it was simple to produce C or Fortran code since it's
possible to substitute scilab function by its source code (wich is
open source).

0
Reply bubu 1/26/2010 12:40:39 PM

On Tue, 26 Jan 2010 04:40:39 -0800, bubu wrote:

> On 24 jan, 22:49, Tim Wescott <t...@seemywebsite.com> wrote:
>> On Sun, 24 Jan 2010 16:12:19 +0100, Jean-Pierre Vial wrote:
>> > Le 23/01/2010 23:19, bubu a écrit :
>> >> hi,
>>
>> >> could someone explain me how to compile a scilab function to speed
>> >> up its execution time ?
>>
>> >> is it possible? how?
>>
>> >> thanks a lot
>> > You cannot compile a scilab function. You can code it as a fortran or
>> > C function, with suitable conventions, compile it and link it in
>> > scilab. This is not for novices !
>>
>> It takes some work to puzzle it out, and I'd only recommend it if
>> you're already conversant with C, but it does work, and well.
>>
>> > most of the intrinsic functions of scilab are programmed in this way.
>> > Look at the help for the scilab   "fort"   function
>>
>> > Clever use of the vector and matrix primitives in scilab will often
>> > give you similar efficiency with much less work.
>>
>> If the problem is amenable to this, you should try it first.  I only
>> get significant speedup if the problem just cannot be vectorized (e.g.
>> I'm doing some seriously nonlinear filtering right now that benefits
>> greatly from having the core parts of the algorithm coded in C).
>>
>> --www.wescottdesign.com
> 
> thanks.
> 
> i thought it was simple to produce C or Fortran code since it's possible
> to substitute scilab function by its source code (wich is open source).

It is and it isn't.  You have to learn a bit about the inner workings of 
Scilab (mostly function argument passing, which is _not_ done in a 
'native' way for Fortran or C), and you have to have the correct build 
environment on your machine (Gnu C under Linux, which is nice, the 
correct version of Microsoft Visual C under Windows, which isn't).  You 
_can_ struggle along under windows with Cygwin's version of Gnu C, but 
that complicates the process.

I probably spent a couple of man-days for each platform before I had my 
own version of "Hello World" running, and probably about a man-week of 
slowdown as I stubbed my toes on less well-documented features figuring 
it all out.

But now that I know how to do it it's certainly a powerful tool.

-- 
www.wescottdesign.com
0
Reply Tim 1/26/2010 4:43:47 PM

On 26 jan, 17:43, Tim Wescott <t...@seemywebsite.com> wrote:
> On Tue, 26 Jan 2010 04:40:39 -0800, bubu wrote:
> > On 24 jan, 22:49, Tim Wescott <t...@seemywebsite.com> wrote:
> >> On Sun, 24 Jan 2010 16:12:19 +0100, Jean-Pierre Vial wrote:
> >> > Le 23/01/2010 23:19, bubu a =E9crit :
> >> >> hi,
>
> >> >> could someone explain me how to compile a scilab function to speed
> >> >> up its execution time ?
>
> >> >> is it possible? how?
>
> >> >> thanks a lot
> >> > You cannot compile a scilab function. You can code it as a fortran o=
r
> >> > C function, with suitable conventions, compile it and link it in
> >> > scilab. This is not for novices !
>
> >> It takes some work to puzzle it out, and I'd only recommend it if
> >> you're already conversant with C, but it does work, and well.
>
> >> > most of the intrinsic functions of scilab are programmed in this way=
..
> >> > Look at the help for the scilab =A0 "fort" =A0 function
>
> >> > Clever use of the vector and matrix primitives in scilab will often
> >> > give you similar efficiency with much less work.
>
> >> If the problem is amenable to this, you should try it first. =A0I only
> >> get significant speedup if the problem just cannot be vectorized (e.g.
> >> I'm doing some seriously nonlinear filtering right now that benefits
> >> greatly from having the core parts of the algorithm coded in C).
>
> >> --www.wescottdesign.com
>
> > thanks.
>
> > i thought it was simple to produce C or Fortran code since it's possibl=
e
> > to substitute scilab function by its source code (wich is open source).
>
> It is and it isn't. =A0You have to learn a bit about the inner workings o=
f
> Scilab (mostly function argument passing, which is _not_ done in a
> 'native' way for Fortran or C), and you have to have the correct build
> environment on your machine (Gnu C under Linux, which is nice, the
> correct version of Microsoft Visual C under Windows, which isn't). =A0You
> _can_ struggle along under windows with Cygwin's version of Gnu C, but
> that complicates the process.
>
> I probably spent a couple of man-days for each platform before I had my
> own version of "Hello World" running, and probably about a man-week of
> slowdown as I stubbed my toes on less well-documented features figuring
> it all out.
>
> But now that I know how to do it it's certainly a powerful tool.
>
> --www.wescottdesign.com- Masquer le texte des messages pr=E9c=E9dents -
>
> - Afficher le texte des messages pr=E9c=E9dents -

thanks

another question.

could you explain me what do genlib command ? It's explained in
documentation that it compile functions in a directory. This command
produce .bin files. So, is it a compilation ?
0
Reply bubu 2/1/2010 7:52:01 AM

bubu a �crit :
> On 26 jan, 17:43, Tim Wescott <t...@seemywebsite.com> wrote:
>> On Tue, 26 Jan 2010 04:40:39 -0800, bubu wrote:
>>> On 24 jan, 22:49, Tim Wescott <t...@seemywebsite.com> wrote:
>>>> On Sun, 24 Jan 2010 16:12:19 +0100, Jean-Pierre Vial wrote:
>>>>> Le 23/01/2010 23:19, bubu a �crit :
>>>>>> hi,
>>>>>> could someone explain me how to compile a scilab function to speed
>>>>>> up its execution time ?
>>>>>> is it possible? how?
>>>>>> thanks a lot
>>>>> You cannot compile a scilab function. You can code it as a fortran or
>>>>> C function, with suitable conventions, compile it and link it in
>>>>> scilab. This is not for novices !
>>>> It takes some work to puzzle it out, and I'd only recommend it if
>>>> you're already conversant with C, but it does work, and well.
>>>>> most of the intrinsic functions of scilab are programmed in this way.
>>>>> Look at the help for the scilab   "fort"   function
>>>>> Clever use of the vector and matrix primitives in scilab will often
>>>>> give you similar efficiency with much less work.
>>>> If the problem is amenable to this, you should try it first.  I only
>>>> get significant speedup if the problem just cannot be vectorized (e.g.
>>>> I'm doing some seriously nonlinear filtering right now that benefits
>>>> greatly from having the core parts of the algorithm coded in C).
>>>> --www.wescottdesign.com
>>> thanks.
>>> i thought it was simple to produce C or Fortran code since it's possible
>>> to substitute scilab function by its source code (wich is open source).
>> It is and it isn't.  You have to learn a bit about the inner workings of
>> Scilab (mostly function argument passing, which is _not_ done in a
>> 'native' way for Fortran or C), and you have to have the correct build
>> environment on your machine (Gnu C under Linux, which is nice, the
>> correct version of Microsoft Visual C under Windows, which isn't).  You
>> _can_ struggle along under windows with Cygwin's version of Gnu C, but
>> that complicates the process.
>>
>> I probably spent a couple of man-days for each platform before I had my
>> own version of "Hello World" running, and probably about a man-week of
>> slowdown as I stubbed my toes on less well-documented features figuring
>> it all out.
>>
>> But now that I know how to do it it's certainly a powerful tool.
>>
>> --www.wescottdesign.com- Masquer le texte des messages pr�c�dents -
>>
>> - Afficher le texte des messages pr�c�dents -
> 
> thanks
> 
> another question.
> 
> could you explain me what do genlib command ? It's explained in
> documentation that it compile functions in a directory. This command
> produce .bin files. So, is it a compilation ?
In a sense yes. when a function is defined using the function ...
endfunction, the given code is parsed and transformed into a "pseudo
code" (a sort of reverse polish notation). The bin files are nothing
else than a save of this "pseudo code".

The pseudo code is more efficient than the user written one, because of
a simpler grammar. but it is not CPU code...

The main reason of the relative slowness of interpreted language like
Scilab , Matlab is the  lack of typing. for each operation or function
call the sofware has to realize a lot of run time tests.

example

for the addition a+b

- does a exists
- does b exists
- get the type of a
- get the type of b
- check if the types match and select the appropriate addition
- get the size of a
- get the size of b
- check if the size match and select the appropriate addition
- allocate memory for the result
- perform the addition

now suppose that a=1 and b=2, the computations involved by all these
tests are much more expensive than performing 1+2

Conversely if a is a 100 by 100 matrix and b a scalar or a 100 by 100
matrix, the cost of the tests are neglectable..

This explains why the programmer should write vectorized code if he
wants efficient execution.
0
Reply Serge 2/1/2010 8:48:35 AM

7 Replies
572 Views

(page loaded in 0.135 seconds)

Similiar Articles:













7/23/2012 2:26:53 AM


Reply: