From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c4cb2c432feebd9d X-Google-Thread: 1094ba,c4cb2c432feebd9d X-Google-Attributes: gid103376,gid1094ba,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Ada vs Fortran for scientific applications Newsgroups: comp.lang.ada,comp.lang.fortran User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <0ugu4e.4i7.ln@hunter.axlog.fr> <447355C4.30306@cits1.stanford.edu> Date: Wed, 24 May 2006 09:15:07 +0200 Message-ID: NNTP-Posting-Date: 24 May 2006 09:14:54 MEST NNTP-Posting-Host: 8d91caaa.newsread4.arcor-online.net X-Trace: DXC=\EfBdOG8TKT\6[GEd:nl>[:ejgIfPPldTjW\KbG]kaMX]kI_X=5KeaVka?A`3G=`TW[6LHn;2LCV^[ On Tue, 23 May 2006 11:34:44 -0700, Brooks Moses wrote: > Dmitry A. Kazakov wrote: >> On Tue, 23 May 2006 17:09:03 GMT, Dick Hendrickson wrote: >>>Fortran 2003 has polymorphic variables which might make it >>>easier to write a complete set of units and operators. That >>>probably would lose some compile time checking. >> >> That depends on which kind of polymorphism it is. Ada provides three forms >> of: >> >> 1. generics (like C++ templates) and overloading >> 2. tagged types (like C++ classes) >> 3. discriminated types. > [...] >> Then there is a problem of constraint propagation. Developing a matrix >> library you surely would like to have dimensioned vectors and matrices all >> constrained in a "coherent" way rather than on per-element basis. I doubt >> that either 1. or 2. would be able to do it in an easy way. > > For what it's worth, the OpenFOAM CFD program that I've been working > with (written in C++) has dimensioned variables, with dimension > checking. It's all run-time, though; they've only got one type of > "dimensioned variable" (a class with the variable value and a > length-seven array containing the exponents of the dimensions) and then > assignments and arithmetic operators check to make sure the dimensions > agree. Yes, this is also the variant 3, but without an ability to have subtypes, because the discriminant is not exposed. I implemented a commercial C++ library (used for data acquisition an control) in a similar way. The problem is that one can change both value and dimension of a variable, which is a safety breach. GPL Ada version, I wrote allows things like: subtype Speed is Measure (Velocity); Car_Speed : Speed; -- Only velocities are allowed . . . Car_Speed := 10.0 * km / h; -- OK Car_Speed := A; -- Ampere is illegal, Constraint_Error > What they've done for their array library is to define a dimensioned > array by adding dimension information to an array of undimensioned > scalars, rather than constructing it directly as an array of dimensioned > individual numbers. Yes, so did I for similar things (dimensioned fuzzy numbers, linguistic variables etc.) > In practice, it seems to work quite well, and I suspect the run-time > checking is generally of negligible cost since it's happening only once > per array operation. (Of course, in code where it does happen once per > scalar operation, it's rather more expensive.) Overhead exists, and it is relatively high when you do something like: forall Matrix do some per-element operation involving dimensions. To get rid of this overhead one should manually fold dimension checks in all cross-typed operations: like [Dimensioned] Matrix x [Dimensioned] Scalar, [Dimensioned] Matrix x [Dimensioned] Vector. If there are many types, many operations and many arguments, this quickly brings the problem of geometrical explosion back. Basically, this all is a consequence of lacking a constraint propagation mechanism capable to move dimension checks out of bodies. Theoretically the compiler could do it when all operations were inlined, but practically, I saw no compiler that does it. Then one cannot inline everything. I think the language should provide something for this, in particular, separation of a subroutine body into inlined (dimension checks) and not inlined (numeric semantics) parts. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de