home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12747 < prev    next >
Encoding:
Text File  |  1992-08-21  |  3.1 KB  |  74 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!timbuk.cray.com!hemlock.cray.com!dsf
  3. From: dsf@cray.com (Dan Frankowski)
  4. Subject: Re: destruction of temporaries
  5. Message-ID: <1992Aug21.171756.29083@hemlock.cray.com>
  6. Lines: 63
  7. Organization: Cray Research, Inc.
  8. References: <1992Aug17.073500.24115@ericsson.se> <TMB.92Aug20142610@arolla.idiap.ch> <4095@seti.UUCP>
  9. Date: 21 Aug 92 17:17:56 CDT
  10.  
  11. In article <4095@seti.UUCP> Daniel R. Edelson <daniel.edelson@inria.fr> writes:
  12.  
  13. >In article <TMB.92Aug20142610@arolla.idiap.ch>, tmb@arolla.idiap.ch
  14.  (Thomas M. Breuel) writes:
  15.  
  16. >|> In article <23487@alice.att.com> ark@alice.att.com (Andrew Koenig) writes:
  17.  
  18. >A previous poster mentioned quality of implementation.
  19. >I couldn't agree more. Scientific computation is a problem 
  20. >for C++ operator overloading. Are we even certain that destroying
  21. >temporaries immediately makes C++ suitable for scientific
  22. >computation? At the the Usenix C++ conference advanced topics
  23. >workshop, we saw a presentation by a person from Boeing (I'm sorry,
  24. >my material is at home and I don't remember his name) who pointed
  25. >out some of the difficulties with scientific computations. One problem
  26. >is using the chaining capability of a cray.
  27. >
  28. >Assume you have a matrix expression like 
  29. >    D =  A * B + C;
  30. >Assume further that the compiler figures out how to vectorize
  31. >the multiplication. The next step is to chain the multiplication
  32. >to the addition. But this is very difficult because the functions
  33. >that implement the overloaded operators hide the fact that the loops
  34. >chain.
  35.  
  36. I don't know how destroying temporaries any sooner or later would make
  37. it possible to chain such operations.  As I posted earlier, the
  38. problem is that it is expanded into
  39.  
  40. D.operator=(A.operator*(B.operator+(C)))
  41.  
  42. and no part of the program expresses the fact that both addition and
  43. multiplication are taking place at the same time.
  44.  
  45. In the style of the matrix package newmat (by Dr. R. B. Davies), the
  46. solution would be to make operator+ return an AddedMatrix, and make
  47. operator* with an AddedMatrix return an AddMultMatrix:
  48.  
  49. AddMultMatrix GeneralMatrix::operator*(AddedMatrix& am);
  50.  
  51. Finally, structure the program such that when the AddMultMatrix is
  52. actually evaluated, there is a procedure that implements addition
  53. and multiplication in one (chained) loop.
  54.  
  55. IMHO, the catch is "when the AddMultMatrix is actually evaluated"--
  56. this means that all code using a general matrix must at one time or
  57. another explicitly invoke an Evaluate() function, which seems contrary
  58. to the spirit of C++.  Not that I know of a better way.  :-)
  59.  
  60. >The point is, scientific computing is difficult. What are the
  61. >ramifications of dictating that temporaries get destroyed
  62. >very quickly. Does that suffice to make C++ acceptable in
  63. >numerical computing? Does that, on the other hand, make C++
  64. >a more difficult language for the general user?
  65.  
  66. If that was the point you were making, I agree.  I was just noting
  67. that I don't see the relation between chaining and garbage collection.
  68.  
  69. >Daniel.Edelson@inria.fr
  70.  
  71. DISCLAIMER: This ain't official Cray business.
  72. -- 
  73. Dan Frankowski            Dan.Frankowski@cray.com     (612) 683-5099
  74.