Re: Optimizing the Speed / Design tradeoff in numeric applications



Randy wrote:
> Jonathan Bartlett wrote:
>
>> I'm working on a program that is fairly numerically intense.
>> Most of my work to date has been mostly business data processing,
>> so scientific processing is somewhat new to me.
>>
>> The application is a multivariate analysis technique. Anyway, I
>> got the program done, but my solutions left me with questions I
>> thought I'd ask you all regarding mathematical applications.
>>
>> The program took three points from n-dimensional space and did
>> calculations to arrive at three values, named d2, t0 and theta.
>> Each value is a function of the three points. However, many of
>> the subcalculations for each value are shared.
>>
>> So, the design side of me says that I should separate each
>> calculation into it's own function/module, so that we have:
>>
>> d2 = calc_d2(p1, p2, p3);
>> t0 = calc_t0(p1, p2, p3);
>> theta = calc_theta(p1, p2, p3);
>>
>> What I like about this method is that it truly separates
>> concerns. However, many of the subcalculations for d2, t0, and
>> theta are shared. Thus, separating the calculations in this way
>> is bad for speed, as the same pieces will have to be continually
>> recalculated.
>>
>> An alternate way would be to do:
>>
>> subcalc1 = perform_subcalc1(p1, p2, p3);
>> subcalc2 = perform_subcalc2(p1, p2, p3);
>> ...
.... snip ...
>
> I agree with Pete that whenever possible, design should trump
> speed.
>
> However, in general, I've found that a clean design that
> emphasizes simplicity is usually faster than a convoluted design
> that emphasizes speed. This is because modern compilers are
> often very good at deducing your intent from your code and
> maximizing optimizations on your behalf, especially when your
> coding style is clean and straightforward.

I think you are trusting compiler optimization too far.

My attitude would be to first separate the external world
interface. The gazinta is p1, p2, p3. The gazouta is d2, t0,
theta. At least define the gazouta as a structure in C, or as a
record in better languages.

typedef struct gazouta {
int d2; /* or whatever */
int t0;
double theta;
} gazouta;

for example. Now you can define:

gazouta transform(int p1, int p2, int p3)
{
gazouta returnvalue;

...
return returnvalue;
} /* transform */

and worry about the details later, secure in the knowledge that
they are confined to the transform function. Pascal and Ada can be
helpful here in that they can have local functions and procedures
that can reference the inputs to transform as needed. In C you
will have to pass those values about with specific parameters.

My inclination, strictly within transform, would be to define some
locals and execute

localone = makevalue(p1, p2, p3);

etc. The makevalue functions will be static, which is about as
close to a local function as you can get in C.

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html

.



Relevant Pages

  • Re: Design for historical data
    ... > types of visits are really that, 3 separate types of visits, which store ... billion rows of page delivery history in a system I helped build (I know ... Good design is important, decent, well balanced hardware (disk, ... Pro SQL Server 2000 Database Design - ...
    (microsoft.public.sqlserver.programming)
  • RE: "Module" option does not show up when setting permissions.
    ... It's by design. ... Access 2000 introduced the separate VBA ... Project for handling the code (notice the separate code window (VB Editor) ... an MDE database file out of it if you want to hide the source code from ...
    (microsoft.public.access.security)
  • Re: Forest, Domain, OU design question
    ... It seemed that the exam was more focused on GPO, NT 4 DNS situations and RIS then any real situations regarding AD design. ... >> they wanted separate schemas or keep administration separate. ... > Domains are REQUIRED for "diffferent security> ACCOUNT policies" > although sloppiness is possible on any particular> question. ... > Domains may be required/desired if you need "complete> control" of resources, mirroring NT domain structures>, and for either/both "massive> number of objects" and to "control replication" in WANS. ...
    (microsoft.public.win2000.active_directory)
  • Re: Site design
    ... The beauty of sites is that they allow you to separate your physical design ... from your logical data requirements. ... > Application server, Exchange,ISA, File and Print Server. ...
    (microsoft.public.windows.server.setup)
  • Re: Optimizing the Speed / Design tradeoff in numeric applications
    ... calculations to arrive at three values, named d2, t0 and theta. ... it's obvious in intent and can share common subcalculations. ... Only if you want to calculate any one of d2, t0 and theta in isolation from the other two does it really make sense to have separate functions for each. ...
    (comp.programming)