[Scilab-Dev] New xcos blocks executing scilab primitive functions

Clément David Clement.David at esi-group.com
Mon Apr 23 11:44:45 CEST 2018


Hello Eric, (answered inline)

> Regarding Scifunc blocks, in sciblk4, createblklist() uses vartosci(..) to reshape the inptr, yet
> it does only copy the adresses in a new table of pointers, not the actual data, isn't it? Do you
> thing this address copying is the time consumming operation ?

Yep exactly, allocating the ScilabList and ScilabDouble scalars for each inputs and on each time
step is a big overhead comparing to passing pointers around as in the C interface.
 
> I found 2 stranges things:
> 1) vartosci(..) creates a List with appends in a for loop, and the data is stored in a vector
> m_plData. That means each time the vector capacity is reached, it "reallocates it in order to grow
> in size when new elements are inserted, which implies allocating a new array and moving all
> elements to it".
> Is a memory allocation strategy defined somewhere in Scilab for TList, List and Typed_list.

That part should not be the issue as, after being cached, the TList will not be resized not
reallocated. 

> 2) createblklist(...) creates a TList whose values are also stored in a vector container m_plData,
> which is also dynamically allocated and may be recreated each time capacity is reached, by the
> append method.
>  
> Thus, in sciblk4, could we call static types::InternalType* pIT = createblklist(...) and
> in.push_back(pIT) only when flag is on initialization, so that all Lists are created once and only
> updated at each iteration ? Would it help ? That would require to rewrite vartosci() and
> createblklist() with a iterator approach instead of append.

Yep this will slightly increase the performance ; for example, the TList returned by createblklist()
could be stored on the work opaque pointer at the "Initialization" and deleted at the "Ending" phase
(before and after calling the Scilab function).

And then before calling the function, cast the work pointer back to a TList, sync the incomes
(inptr, z and x variables) call the function, sync the outcomes.

Regards,

--
Clément


> > Message du 09/04/18 09:37
> > De : "Clément David" <Clement.David at esi-group.com>
> > A : "dev at lists.scilab.org" <dev at lists.scilab.org>
> > Copie à : 
> > Objet : Re: [Scilab-Dev] New xcos blocks executing scilab primitive functions
> > 
> 
> 
> > To call Scilab script within the sciblk2 [1] and sciblk4 [2] blocks we are indeed using the
> Scilab
> > C++ API, the performance overhead is quiet clear as we are currently allocating Scilab
> types::Double
> > or a types::MList through createblklist() for each output on each simulation step.
> _______________________________________________
> dev mailing list
> dev at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/dev


More information about the dev mailing list