Re: OON: Comparison between Fortran & C++

From: Brad Lucier (lucier@math.purdue.edu)
Date: Fri Mar 24 2000 - 12:30:22 EST


<good analysis deleted>

> So, to clarify: Scheme can be almost as fast as C for a sparse
> matrix-vector multiply, if you
> 1. introduce nonstandard extensions such as f64vector to
> give Scheme C-like arrays
> 2. compile in unsafe mode, which reintroduces the dangerous
> C array semantics which functional programmers loathe.
> 3. change the semantics of the language to disable the un C-like
> ability to rebind primitives.

And, if you look at all.scm, which includes linear-elements.scm, you'll
find:

(declare (standard-bindings) ; +, *, etc., have standard meanings
         (extended-bindings) ; f64vector, etc., have standard meanings
         (block) ; if a function is not redefined in this
                                   ; file, it is never redefined
         (not safe) ; assume the programmer didn't make any
                                   ; mistakes, and remove safety checks
         (not interrupts-enabled))

(not interrupts-enabled) means, roughly, that I guarantee that there
will be no stack overflow (my nontail-recursive call chain is small),
so Gambit-C does not have to insert stack overflow checks.

> If you compile according to the standard semantics of Scheme, your
> code will be much much much slower. (I've benchmarked things running
> 10-100 times slower than C).

To be somewhat pedantic, specifying (not safe) does not change the
semantics of a standard-compliant (i.e., correct) program; it may
change what happens when a non--standard-compliant program is run.
The other declarations generally can change the semantics of otherwise
standard-compliant programs.

The next version of Gambit-C will compile safe code in the following way:
it will put the checks that +, *, f64vector, etc., have the standard
meanings inline (it's two loads of globals and a compare), and do the
arithmetic checks inline, too. Overall, the performance penalty is
<50% for typical Scheme code; I suspect it will be somewhat higher for
numerical code.

Until then, if you want C speed, you need to specify C semantics.
(I suggested a few programming language projects to my students that
would fix this somewhat, but no student in the class had the background
or inclination to take me up on it.)

Brad

PS: Say hi to Dennis Gannon for me, if he's around.

--------------------- Object Oriented Numerics List --------------------------
* To subscribe/unsubscribe: use the handy web form at
http://oonumerics.org/oon/
* If this doesn't work, please send a note to owner-oon-list@oonumerics.org



This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:11 EST