[Prev][Next][Index][Thread]

Re: performance for scientific computing



"Sébastien de Menten" wrote:
> 
> Hi,
> 
> I was wondering if Dylan is fast (compared to C/C++) on such operations:
> 
> define a tridimensional array A(M,N,P) initialised with
>         A(i,j,k) = i + j / k (or any other function of i,j,k)

If (and only if) limited (size- and type-wise) higher-rank arrays are
implemented in the compiler, this should be just as fast as Blitz++
(i.e. faster than C). I fear Gwydion only implements limited vectors.
Note that "limited" in the above sentence does not mean "crippled" but
a way to trade flexibility for performance. By restricting element type
and/or collection size (array dimensions) the compiler is able to perform
much more optimizations.

Sadly there is no "initialize by calling a function with the collection key"
feature in standard dylan. I have loudly thought about it some time ago and
the syntax
   make(<some-limited-array>, init-function: method(i, j, k) i + j / k end);
was found pretty by some people, but it is not implemented anywhere (yet).
Current dylan only offers an init-value: keyword, which is not what you want.


> compute
>         C = A*A+cos(A)     (to understand as C(i,j,k) = A(i,j,k)*A(i,j,k) +
> cos(A(i,j,k)))

It is not recommended to add methods to the generic functions \+ and \* as
defined in the dylan library, although it is possible on user defined types.
However you could define your array lib to exclude (or rename) them from the
dylan lib and define your own. This would allow the above idiomatic style.

> or
>         d = Tr(A) (trace of the matrix = Sum(A(i,i,i) for i = 0 to M and
> M=N=P)

This one is easy to define, limited array would make it fast too.

> 
> More specifically:
> - which implementation of Dylan is faster

Dunno.

> - is it possible to "allocate" an array and at the same time initialise the
> elements

See above.

> - if a map function is used, is it fast compared to C loops

If the compiler can inline \map and your transform, it should be.

> - are there unnecessary array creations (for instance if I want to compute
> A=A*A+cos(A), there should not be any allocation of new arrays for
> efficiency or for low memory)

init-function: could do this.

> 
> In fact, I want to work with Dylan for intensive scientific computing
> (MonteCarlo simulations, dynamic programming, etc...). Currently, it is done
> in C++ with blitz++ as array templates. However, it is not very flexible and
> I loose a lot of time in compilation (templates compilation are very slow
> with gcc). So maybe, Dylan with its macros and functional features could
> help me if it compiles in a fast enough program.
> 
> Thank you in advance for your expertise!
> 
> Sébastien de Menten
> 
> BTW: it is very hard to find any comprehensive tutorial on Dylan or example
> of Dylan scientific code... So welcome to any reference on the topic

I guess you are the first to request it :-)

	Gabor



Follow-Ups: References: