[erlang-questions] Vector instructions

Zvi <>
Sun Apr 6 23:16:42 CEST 2008


With generic tuples it's impossible to implement efficient SIMD operations.
Also there is many undefined/confusing behaiviors, when elements of tuple
are not numeric.

This is the same kind of mistakes, like 2 bad design decisions made in
1. "Ohh, record looks just like a tuple!",  so let's throw in some syntactic
sugar for this, instead of real immutable structs/dictionaries.
2. "Ohh, string looks just like a list of integers!", so let's throw in some
syntactic sugar for this, instead of implementing real Unicode-aware
immutable string datatype.

In my opinion Erlang might be a good match, not only for High Availability
(HA) applications, but also High Performance Computing (HPC) applications,
and it might wipe out MPI as de-facto standard, by additing highly optimized
Matlab-like "matrix of double"/"multidimensional array of double" datatype.
Array Programming is also such a good fit for FP, since you may naturaly
extend map and fold/reduce for this datatype.
Also, vector math, even if not implemented efficiently, makes you much more
productive and allows you to prototype with one-liners from shell. Combining
this with Erlang's built-in concurrency and distrition primitives it makes
it Super-High-level language. Unlike other Array programming languages, I
propose that Erlang matrix datatype will be immutable.

So, in my view Erlang should be  H^3 (read as H-cube) language:

Highly Available

For the start maybe it's possible to take some code from PyNum
(unfortunately Octave has GNU license).


BTW, I somewhat disappointed with vector math implemented in Matlab and
kdb+/Q. It's not much faster than serial Erlang code (and much much slower
than parallel Erlang code). You can see it in my little PI calculation


>> tic; N=1000000; Step = 1/N; PI = Step*sum(4./(1+(((1:N)-0.5)*Step).^2));
>> toc 
Elapsed time is 0.125428 seconds. 


q)PI: {[]; Step*((4f % (1f + ((Step*((1+ til N)-0.5)) xexp 2))) +/)}
q)\t do[1000;PI()]

i.e. 264 ms

on my dual CPU workstation I getting ~ 200 ms.


Serial tail-recursuive Erlang version takes ~ 170 ms - 300 ms (on different
Parallel Erlang version on 16 cores takes 15 ms 


James Hague wrote:
>>  Has anyone given any thought to adding vector instructions or otherwise
>>  adding support for vectors to Erlang?
> I've proposed adding APL-style vector operations on tuples:
> {1,2,3} + 1 ==> {2,3,4}
> {1,2,3) * 2 ==> {2,4,6}
> 2 * {1,2,3} ==> {2,4,6}
> {1,2,3} + {3,2,1} ==> {4,4,4}
> The operations apply to the top level only; they're not recursive.
> This would make vector math style code a lot simpler to write in
> Erlang.  One of the points raised in response to this was that we
> shouldn't be overloading tuple operations like this, but have a
> special "vector of float" type.  I'm not sure I agree with that.
> _______________________________________________
> erlang-questions mailing list
> http://www.erlang.org/mailman/listinfo/erlang-questions

View this message in context: http://www.nabble.com/Vector-instructions-tp16468138p16529946.html
Sent from the Erlang Questions mailing list archive at Nabble.com.

More information about the erlang-questions mailing list