home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!timbuk.cray.com!hemlock.cray.com!dsf
- From: dsf@cray.com (Dan Frankowski)
- Subject: Re: destruction of temporaries
- Message-ID: <1992Aug21.171756.29083@hemlock.cray.com>
- Lines: 63
- Organization: Cray Research, Inc.
- References: <1992Aug17.073500.24115@ericsson.se> <TMB.92Aug20142610@arolla.idiap.ch> <4095@seti.UUCP>
- Date: 21 Aug 92 17:17:56 CDT
-
- In article <4095@seti.UUCP> Daniel R. Edelson <daniel.edelson@inria.fr> writes:
-
- >In article <TMB.92Aug20142610@arolla.idiap.ch>, tmb@arolla.idiap.ch
- (Thomas M. Breuel) writes:
-
- >|> In article <23487@alice.att.com> ark@alice.att.com (Andrew Koenig) writes:
-
- >A previous poster mentioned quality of implementation.
- >I couldn't agree more. Scientific computation is a problem
- >for C++ operator overloading. Are we even certain that destroying
- >temporaries immediately makes C++ suitable for scientific
- >computation? At the the Usenix C++ conference advanced topics
- >workshop, we saw a presentation by a person from Boeing (I'm sorry,
- >my material is at home and I don't remember his name) who pointed
- >out some of the difficulties with scientific computations. One problem
- >is using the chaining capability of a cray.
- >
- >Assume you have a matrix expression like
- > D = A * B + C;
- >Assume further that the compiler figures out how to vectorize
- >the multiplication. The next step is to chain the multiplication
- >to the addition. But this is very difficult because the functions
- >that implement the overloaded operators hide the fact that the loops
- >chain.
-
- I don't know how destroying temporaries any sooner or later would make
- it possible to chain such operations. As I posted earlier, the
- problem is that it is expanded into
-
- D.operator=(A.operator*(B.operator+(C)))
-
- and no part of the program expresses the fact that both addition and
- multiplication are taking place at the same time.
-
- In the style of the matrix package newmat (by Dr. R. B. Davies), the
- solution would be to make operator+ return an AddedMatrix, and make
- operator* with an AddedMatrix return an AddMultMatrix:
-
- AddMultMatrix GeneralMatrix::operator*(AddedMatrix& am);
-
- Finally, structure the program such that when the AddMultMatrix is
- actually evaluated, there is a procedure that implements addition
- and multiplication in one (chained) loop.
-
- IMHO, the catch is "when the AddMultMatrix is actually evaluated"--
- this means that all code using a general matrix must at one time or
- another explicitly invoke an Evaluate() function, which seems contrary
- to the spirit of C++. Not that I know of a better way. :-)
-
- >The point is, scientific computing is difficult. What are the
- >ramifications of dictating that temporaries get destroyed
- >very quickly. Does that suffice to make C++ acceptable in
- >numerical computing? Does that, on the other hand, make C++
- >a more difficult language for the general user?
-
- If that was the point you were making, I agree. I was just noting
- that I don't see the relation between chaining and garbage collection.
-
- >Daniel.Edelson@inria.fr
-
- DISCLAIMER: This ain't official Cray business.
- --
- Dan Frankowski Dan.Frankowski@cray.com (612) 683-5099
-