comp.lang.ada
 help / color / mirror / Atom feed
From: Oxide Scrubber <jharriman@hatlop.de>
Subject: Re: Alternatives to C: ObjectPascal, Eiffel, Ada or Modula-3?
Date: Wed, 29 Jul 2009 00:46:25 -0400
Date: 2009-07-29T00:46:25-04:00	[thread overview]
Message-ID: <h4ok76$6s8$1@aioe.org> (raw)
In-Reply-To: 76d51f01-725b-4146-82f6-cd89bfcb90eb@v15g2000prn.googlegroups.com

fft1976 wrote:
> On Jul 28, 5:40 pm, Oxide Scrubber <jharri...@hatlop.de> wrote:
> 
> Clojure is kind of cool, but many corrections are in order

No, they are not.

>> fft1976 wrote:
>>> Java: 1.5x slower than C as a rule of thumb.
>> I think it can achieve parity.
> 
> I disagree. I don't think the JIT can do much about the memory layout
> of the data structures. Compare a vector of complex numbers or of 3D
> vectors (NOT of pointers to them) in C/C++ and Java. Run some tests. I
> did and I looked at others'.
> 
> For me, 1.5x is a good trade-off for safety though.

The JIT can't, but the coder can. If you want a vector of N 
double-precision complex numbers in Java that is contiguous in memory, 
for example, you could use a Java array of 2xN doubles and index into it 
appropriately.

This won't work with encapsulated-object bignums, but at that point 
you're probably spending most of your time in individual bignum ops, 
particularly multiplies, anyway, so traversal from one bignum to another 
becomes an insignificant factor in run-time.

>> With Java, in most cases you can slap "implements Cloneable" on a
>> class and make the clone method public,
> 
> Java's "clone" does a shallow copy only (check the docs).

True. If you want a deep copy you will have to implement it yourself. Or 
you can make a deepCopy static utility method that exploits 
"Serializable" to deep copy anything that's serializable simply by 
serializing and deserializing it (which can use memory, or a temp file, 
and not much memory if you make an auxiliary class implement both 
InputStream and OutputStream, with its OutputStream methods writing to a 
growable buffer and its InputStream methods consuming (possibly blocking 
if necessary) from same. Closing the OutputStream aspect EOFs the 
InputStream aspect. Then wrap in ObjectInput/OutputStream. You can use a 
BlockingQueue of byte arrays of length 8192 (or whatever), serialize to 
one end and deserialize from the other in concurrent threads, and it 
will tend to not use much memory. Limit the BlockingQueue length to 1 
item and it will never use much more than 8Kbyte (the OutputStream 
aspect will block until the InputStream aspect consumes from the queue).

>> or slap "implements
>> Serializable" on a class to make its instances marshallable.
> 
> Does this handle cycles and memory sharing among data structures?

It does.

>> (This doesn't, however,
>> interoperate with generic Java objects or Java serialization, and I'm
>> not sure it works with data structures with circularities. It won't work
>> with data structures with infinite sequences in them, but if you
>> represent such sequences symbolically it can.)
> 
> But you'll need Java's data structures and mutations on Java's arrays
> to compete with it in speed of numerical code

Not necessarily. It depends on what sort of numerical code.

If the bulk of the time is spent performing arithmetic operations on 
just a few values, these inner loops can be tightened up and use only 
local variables, no arrays or other structures at all.

If the arithmetic is bignum, the bulk of your time will be spent 
performing individual bignum operations. Algorithmic smartness 
(Karatsuba multiplication, memoizing or otherwise saving multiply-used 
intermediate values, and exploiting concurrency) will win big while 
speeding up the loops that invoke bignum operations won't.

If the arithmetic is on smallnums in arrays and the computations are 
mostly mutations, then you may want to use Java arrays, and you may want 
to use a Java method instead of a Clojure function to do the operation 
(and may still call this from Clojure easily enough). Note above about 
Java: if you want contiguous memory you'll have to give up using Java 
objects for things like complexes. But you can still make quasi-methods 
for quasi-objects (e.g. methods that take an array and an index and 
treat the two array elements starting at that index as real and 
imaginary parts of a complex numbers and perform a complex op on them).

With Clojure code, you can make macros that expand to complex operations 
on adjacent pairs of values in a Java primitive array. In practice, 
Clojure access to Java arrays, even primitive arrays, seems to be slow. 
This may be addressed in a future version. Alternatively, use Java for 
this. Macros can also be used to turn code that operates on notional 
vector-like data structures of lengths known at compile time into code 
that actually operates on large sequences of local variables. The 
"vectors" should then end up as contiguous data on the *stack*. If the 
lengths are not known until run-time, the same macros can be used along 
with "eval" to compile functions on the fly to perform efficient 
operations on them. In fact, if other aspects of the computations are 
also not known until run-time "eval" can be useful. If at compile time, 
for example, an unknown value will be added to the diagonal entries of 
lots of 1000x1000 matrices, and at run time that value is pure real, at 
run time "eval" can emit in this case specialized code that doesn't 
waste time adding thousands of zeros to imaginary parts of matrix entries.

Last but certainly not least, ask if any such algorithms can be 
rewritten to be based less on mutation and more on map-reduce type 
operations.

>> Clojure has strong support for parallelism and threading.
> 
> Clojure's support for multithreading is good only as long as your code
> is pure-functional. Let's see you add 1.0 to all diagonal elements of
> a 1000x1000 matrix.

Clojure has all of Java's support for multithreading too. You could on a 
dual-core machine get two threads each mutating 500 of those diagonal 
entries -- no locking required since the changes are independent of one 
another. Just as you could in Java. Or do it in Java and call this from 
Clojure.

>> You need to work a bit to get the most speed out of Clojure too, but you
>> can then get C-like performance out of it in tight loops.
> 
> In theory, imperative and Java array using Clojure can be made as fast
> as Java (which is slower than C)

See above: not if you lay out your data right, and in Clojure (unlike 
pure Java) you can use macros or similarly to emulate having object 
operations on the data despite it really being in a flat array.

> Aside: do you remember to add -O3 when you are compiling C/C++? I use
> "-server" when running the JVM.

I am assuming both. Without -server, Clojure and Java will be 
significantly slower than C/C++. With -server, I've seen numerical 
calculations in both run at tuned-assembly speeds.



  reply	other threads:[~2009-07-29  4:46 UTC|newest]

Thread overview: 285+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-18 14:19 Alternatives to C: ObjectPascal, Eiffel, Ada or Modula-3? Andrea Taverna
2009-07-18 14:42 ` Richard Harter
2009-07-18 14:53 ` Francois PIETTE
2009-07-18 15:23   ` Ludovic Brenta
2009-07-18 18:27     ` Andrea Taverna
2009-07-18 18:46       ` Pascal Obry
2009-08-04 20:09         ` Hendrik Boom
2009-08-04 21:35           ` Jon Harrop
2009-07-18 18:57       ` Andrea Taverna
2009-07-18 15:18 ` Pascal J. Bourguignon
2009-07-19 13:50   ` Andrea Taverna
2009-07-19 14:06     ` Pascal J. Bourguignon
2009-07-20 10:13   ` Nicholas Paul Collin Gloucester
2009-08-04 20:12     ` Hendrik Boom
2009-07-21 12:03   ` Jon Harrop
2009-07-21 13:25     ` Mark T.B. Carroll
2009-07-18 15:50 ` Ludovic Brenta
2009-07-18 16:31   ` Hibou57 (Yannick Duchêne)
2009-07-18 19:48   ` Georg Bauhaus
2009-07-20 10:34   ` Nicholas Paul Collin Gloucester
2009-07-23 22:58   ` A few Ada questions Andrea Taverna
2009-07-24  0:28     ` Ludovic Brenta
2009-07-24  9:07       ` AdaMagica
2009-07-28  9:48         ` Making a nonlimited type controlled by means of a controlled component Ludovic Brenta
2009-08-14 22:21           ` Randy Brukardt
2009-08-14 22:51             ` Adam Beneschan
2009-07-24  7:00     ` A few Ada questions Dmitry A. Kazakov
2009-07-24 15:26       ` Colin Paul Gloster
2009-07-24 15:01         ` Dmitry A. Kazakov
2009-07-18 16:27 ` Alternatives to C: ObjectPascal, Eiffel, Ada or Modula-3? BGB / cr88192
2009-07-18 17:41 ` Ben Bacarisse
2009-07-20 10:39   ` Nicholas Paul Collin Gloucester
2009-07-20 16:17     ` Ben Bacarisse
2009-07-21 12:10     ` Jon Harrop
2009-07-21 14:40       ` Colin Paul Gloster
2009-07-22  0:25         ` Andrew Reilly
2009-07-19  1:04 ` Andrew Reilly
2009-07-19 13:14   ` mockturtle
2009-07-19 13:35   ` Andrea Taverna
2009-07-19 15:28     ` Pascal J. Bourguignon
2009-07-19 17:30       ` Hibou57 (Yannick Duchêne)
2009-07-19 18:02       ` Georg Bauhaus
2009-07-19 19:09         ` Hibou57 (Yannick Duchêne)
2009-07-19 19:14         ` Pascal J. Bourguignon
2009-07-19 19:51           ` Georg Bauhaus
2009-07-19 19:52 ` tm
2009-07-20  9:57 ` Jean-Pierre Rosen
2009-07-20 13:42   ` Hibou57 (Yannick Duchêne)
2009-07-20 14:37   ` tm
2009-07-20 15:14     ` Jean-Pierre Rosen
2009-07-24  7:26       ` tm
2009-07-24  8:10         ` Dmitry A. Kazakov
2009-07-25 17:39           ` Frank J. Lhota
2009-07-25 18:12             ` Dmitry A. Kazakov
2009-07-24 21:15         ` Wolfgang Ehrhardt
2009-07-24 22:29           ` bartc
2009-07-26 10:55             ` tm
2009-07-26 12:14               ` bartc
2009-07-26 13:21                 ` Pascal J. Bourguignon
2009-07-26 15:43                   ` bartc
2009-07-20 15:46     ` Georg Bauhaus
2009-07-20 16:08     ` Ben Bacarisse
2009-07-20 19:48     ` Tetrahedral Quartz
2009-07-26  2:26   ` wwilson
2009-07-20 12:15 ` Nicholas Paul Collin Gloucester
2009-07-20 12:59   ` Mark T.B. Carroll
2009-07-20 13:18     ` Nicholas Paul Collin Gloucester
2009-07-20 13:21       ` Mark T.B. Carroll
2009-07-20 14:49         ` Nicholas Paul Collin Gloucester
2009-07-20 18:33   ` Cesar Rabak
2009-07-20 18:49     ` Hibou57 (Yannick Duchêne)
2009-07-20 19:35       ` Cesar Rabak
2009-07-20 21:54         ` Georg Bauhaus
2009-07-21  7:39         ` Dmitry A. Kazakov
2009-07-21 14:30           ` Cesar Rabak
2009-07-21 15:17             ` Martin
2009-07-20 19:23     ` Georg Bauhaus
2009-07-20 19:55       ` Cesar Rabak
2009-07-21 12:49       ` Colin Paul Gloster
2009-07-20 19:44     ` Nicholas Paul Collin Gloucester
2009-07-20 20:14       ` Cesar Rabak
2009-07-20 22:22         ` Ludovic Brenta
2009-07-21  1:33           ` Cesar Rabak
2009-07-21  7:54             ` Ludovic Brenta
2009-07-21  7:59             ` Dmitry A. Kazakov
2009-07-21 13:08               ` Colin Paul Gloster
2009-07-21 12:43                 ` Dmitry A. Kazakov
2009-07-21 14:48                 ` Cesar Rabak
2009-07-21 14:45               ` Cesar Rabak
2009-07-21 15:46                 ` Dmitry A. Kazakov
2009-07-21 17:34                   ` Colin Paul Gloster
2009-07-21  8:56             ` Jean-Pierre Rosen
2009-07-21  9:31               ` Georg Bauhaus
2009-07-21 15:02               ` Cesar Rabak
2009-07-21 16:42                 ` Georg Bauhaus
2009-07-21 18:00                   ` Cesar Rabak
2009-07-22 14:10                     ` Colin Paul Gloster
2009-07-22 14:54                       ` Cesar Rabak
2010-03-24  2:46                       ` Robert Love
2010-03-25 15:51                         ` Colin Paul Gloster
2009-07-21 17:37                 ` Colin Paul Gloster
2009-07-21 14:08             ` Hibou57 (Yannick Duchêne)
2009-07-21 13:38         ` Colin Paul Gloster
2009-07-21 15:25           ` Cesar Rabak
2009-07-21 17:48             ` Colin Paul Gloster
2009-07-23 18:47               ` Jon Harrop
2009-07-23 19:20                 ` Colin Paul Gloster
2009-07-23 21:51                   ` Jon Harrop
2009-07-24  1:08                   ` Cesar Rabak
2009-07-24  7:04                     ` Dmitry A. Kazakov
2009-07-22 19:29   ` sjw
2009-07-22 20:05     ` Dmitry A. Kazakov
2009-07-23 12:01     ` Colin Paul Gloster
2009-07-24  1:19       ` Cesar Rabak
2009-07-24  8:50         ` Georg Bauhaus
2009-07-24 15:56           ` Colin Paul Gloster
2009-07-24 16:52         ` Colin Paul Gloster
2009-07-24 18:36           ` Cesar Rabak
2009-07-24 21:46           ` Robert A Duff
2009-07-25 14:32             ` jimmaureenrogers
2009-07-25 17:31             ` Cesar Rabak
2009-07-21 12:25 ` Jon Harrop
2009-07-21 11:41   ` Martin
2009-07-21 14:09     ` Jon Harrop
2009-07-21 13:41       ` Martin
2009-07-21 13:45         ` Martin
2009-07-21 13:58         ` Dmitry A. Kazakov
2009-07-21 16:06         ` Jon Harrop
2009-07-21 15:54           ` Georg Bauhaus
2009-07-22  9:37             ` Jon Harrop
2009-07-22  9:19               ` Georg Bauhaus
2009-07-22  7:53           ` Martin
2009-07-22  9:18             ` Jon Harrop
2009-07-21 23:17         ` Robert A Duff
2009-07-21 14:12   ` Andrea Taverna
2009-07-21 14:14     ` Hibou57 (Yannick Duchêne)
2009-07-21 14:38     ` Hibou57 (Yannick Duchêne)
2009-07-21 15:29       ` Mark T.B. Carroll
2009-07-21 16:10     ` Jon Harrop
2009-07-22  8:16       ` Martin
2009-07-22 18:59         ` Jon Harrop
2009-07-24  8:15     ` tm
2009-07-24  9:31       ` Jon Harrop
2009-07-24  9:42         ` Georg Bauhaus
2009-07-24 13:03           ` Jon Harrop
2009-07-24 10:15         ` tm
2009-07-24 13:11           ` Jon Harrop
2009-07-24 13:01             ` tm
2009-07-24 14:42               ` Jon Harrop
2009-07-25  1:15         ` wwilson
2009-07-25  6:05           ` robertwessel2
2009-07-25  9:24             ` Dmitry A. Kazakov
2009-07-26  2:10             ` wwilson
2009-07-26  3:27               ` Andrew Reilly
2009-07-26 10:08                 ` bartc
2009-07-27 11:28               ` Colin Paul Gloster
2009-07-28  5:01                 ` wwilson
2009-07-28 10:13                   ` Colin Paul Gloster
2009-07-28 12:29                   ` Dave Seaman
2009-07-28 12:42                     ` Peter Hermann
2009-07-28 18:35                     ` wwilson
2009-07-21 13:09 ` parnell
2009-07-28 20:57 ` fft1976
2009-07-28 21:59   ` Georg Bauhaus
2009-07-28 22:01   ` Ludovic Brenta
2009-07-30  3:04     ` fft1976
2009-07-30  6:47       ` Martin
2009-07-28 23:14   ` Jon Harrop
2009-08-01 19:46     ` frankenstein
2009-08-01 21:56       ` Paul Rubin
2009-08-01 23:28         ` Jon Harrop
2009-08-02 10:07         ` frankenstein
2009-08-02 18:55           ` Jon Harrop
2009-08-02  9:48       ` frankenstein
2009-07-29  0:40   ` Oxide Scrubber
2009-07-29  2:52     ` fft1976
2009-07-29  4:46       ` Oxide Scrubber [this message]
2009-07-29  7:50   ` Elena
2009-07-29 15:06     ` Andrea Taverna
2009-07-29  8:11   ` Ray Blaak
2009-07-29  9:57     ` learn2code
2009-07-29 11:38       ` Oxide Scrubber
2009-07-29 14:03         ` learn2code
2009-07-29 14:35           ` Pascal J. Bourguignon
2009-07-29 17:02           ` Oxide Scrubber
2009-08-03 11:19             ` oxhiderubber
2009-07-29 21:10           ` Jon Harrop
     [not found]         ` <kctwcdo5pewe.1ut3dcff8axm0$.dlg@40tude.net>
2009-07-29 21:18           ` Jon Harrop
2009-07-29 16:36       ` Colin Paul Gloster
2009-07-29 17:22       ` Ray Blaak
2009-07-29 18:44     ` Martin
2009-07-29 20:58       ` Jon Harrop
2009-07-29 15:19   ` Andrea Taverna
2009-07-29 19:25     ` Jon Harrop
2009-07-30  2:11   ` tmoran
2009-07-30  2:34     ` fft1976
2009-07-30  2:48       ` Paul Rubin
2009-07-30  3:40         ` fft1976
2009-07-30  3:53           ` Paul Rubin
2009-07-30  6:51           ` Georg Bauhaus
2009-07-30  7:52             ` fft1976
2009-07-30  8:34               ` Ludovic Brenta
2009-07-30 16:10               ` Georg Bauhaus
2009-07-30 17:09                 ` fft1976
2009-07-30 17:20                   ` Pascal Obry
2009-07-30 17:28                     ` fft1976
2009-07-30 17:47                     ` Isaac Gouy
2009-07-31 10:48                       ` Georg Bauhaus
2009-07-30 17:23                 ` Ludovic Brenta
2009-07-30 17:59                 ` Isaac Gouy
2009-07-30 19:38                   ` fft1976
2009-07-30 21:44                     ` Isaac Gouy
2009-07-30 22:14                       ` Paul Rubin
2009-07-31 10:27                         ` Georg Bauhaus
2009-07-31 11:13                     ` Georg Bauhaus
2009-07-31 11:29                   ` Georg Bauhaus
2009-07-31 16:38                     ` Isaac Gouy
2009-07-30 16:25             ` Isaac Gouy
2009-07-30 12:28     ` Colin Paul Gloster
2009-07-30 11:49       ` Martin
2010-03-23 12:31 ` balson
2010-03-23 12:56 ` balson
2010-03-23 13:24   ` Georg Bauhaus
2010-03-23 15:05     ` Maciej Sobczak
2010-03-23 17:52       ` Georg Bauhaus
2010-03-24  6:33       ` Martin Krischik
2010-03-24  8:31         ` Maciej Sobczak
2010-03-23 16:50   ` Warren
2010-03-23 20:29     ` Patrick Scheible
2010-03-24 15:07       ` Warren
2010-03-24 21:11         ` Patrick Scheible
2010-03-24 21:27           ` Pascal J. Bourguignon
2010-03-24 22:14             ` Adam Beneschan
2010-03-24 23:15               ` Patrick Scheible
2010-03-24 23:24                 ` Adam Beneschan
2010-03-24 23:28                 ` Patricia Shanahan
2010-03-25  1:52                   ` John B. Matthews
2010-03-25 16:42               ` Andrew Haley
2010-03-26 23:54               ` Pascal J. Bourguignon
2010-03-24 21:36         ` Adam Beneschan
2010-03-26  7:58           ` Martin Krischik
2010-04-12 11:03           ` Ole-Hjalmar Kristensen
2010-03-24  6:28     ` Martin Krischik
2010-03-24 15:10       ` Warren
2010-03-25  2:19         ` Mike Sieweke
2010-03-25 13:48           ` Robert A Duff
2010-03-25 15:42       ` Colin Paul Gloster
2010-03-26 15:54     ` blmblm
2010-03-26 19:18       ` Warren
2010-03-27  0:03         ` Pascal J. Bourguignon
2010-03-23 17:12   ` J-P. Rosen
2010-03-23 17:41     ` Jim Balson
2010-03-23 17:54       ` Pascal Obry
2010-03-23 18:34         ` jpwoodruff
2010-03-23 20:34           ` Patrick Scheible
2010-03-23 20:33         ` Patrick Scheible
2010-03-23 20:39           ` Pascal Obry
2010-03-24  6:24           ` Martin Krischik
2010-03-23 19:33       ` Adam Beneschan
2010-03-23 22:02         ` Mensanator
2010-03-31  6:55         ` David Thompson
2010-03-31  8:08           ` Martin Krischik
2010-03-24 15:15       ` Warren
2010-03-25 15:46       ` Colin Paul Gloster
2010-03-27  0:53       ` Andrea Taverna
2010-03-27  6:19         ` Gautier write-only
2010-03-23 17:31   ` Patrick Scheible
  -- strict thread matches above, loose matches on Subject: below --
2010-03-23 18:57 cbcurl
2010-03-23 20:27 ` John B. Matthews
2010-03-23 21:34   ` Adam Beneschan
2010-03-24  2:08     ` John B. Matthews
2010-03-24 15:23       ` Warren
2010-03-24 16:57         ` Adam Beneschan
2010-03-24 20:00           ` Warren
2010-03-24 20:48             ` Adam Beneschan
2010-03-25 13:45               ` Warren
2010-03-26  8:20                 ` Martin Krischik
2010-03-26 19:21                   ` Warren
2010-03-28 15:07                     ` Martin Krischik
2010-03-29 13:28                       ` Warren
2010-03-26  8:05             ` Martin Krischik
2010-03-26  8:02           ` Martin Krischik
2010-03-26 19:24             ` Warren
2010-03-28 14:54               ` Martin Krischik
2010-03-29 13:31                 ` Warren
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox