Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!samsung!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: why is this program slow? Message-ID: <60395@microsoft.UUCP> Date: 10 Jan 91 18:32:51 GMT References: <1991Jan9.002244.23398@news.cs.indiana.edu> <1991Jan9.101212@Pkg.Mcc.COM> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 40 In article <1991Jan9.101212@Pkg.Mcc.COM> steve@Pkg.Mcc.COM (Steve Madere) writes |This is a problem with C++ that I have known about for some time. |The lure of simplified notation leads one to try to implement |vector and matrix operations with special classes that will hide |the complexity. Unfortunately, all of those temporary variables |that must be created to realize any mathematical operations really |waste CPU time. It takes a finite amount of time to allocate space, |copy data, and free up the space again. In many cases it is a |significant percentage of the total run time of the program. | |A friend of mine at UCSD has worked on this problem for some time |and concluded that what one needs is some kind of matrix awareness |in the compiler to recognize when operations can be somehow |combined. Clearly this is not the kind of thing that C++ was designed |to do. It is appropriate to add matrix awareness to a computational |language like FORTRAN but C++ is not a scientific computation |language. (no flames please, I just mean that its PRIMARY purpose |is not scientific computation). | |Any suggestions from the peanut gallery? My claim would be that if one is serious about working with large objects -- say large matrices and/or large vectors, then one can afford to "do the job right" in C++ -- which means probably using reference counting on the internal storage of the vectors and/or matrices, while maintaining an external polymorphic wrapper over those guts which represents the exact form of the vector or matrix: is this matrix a "plain old matrix", tridiagonal, identity, .... [In fact, probably some vendors already provide such libraries] If you have a parallel computer, and a highly parallelizing fortran compiler, you might want to write some of the guts of the internal representation of these matrices in fortran -- but better yet, you'll probably find that your vendor already provides highly optimized routines for performing those guts -- linpack-type stuff. There's no reason why you can't have both the nice syntax of C++, and the speed of fortran -- if you're willing to do a little serious work. On the other hand, if you don't care, well, then you don't care.