C/C++ speed optimization bible/resources/pointers needed!

This is a discussion on C/C++ speed optimization bible/resources/pointers needed! within the Other Technologies forums in category; srp@microtec.net wrote: > On 26 juil, 17:19, lunamoonm...@gmail.com wrote: .... > Your best bet with C/C++ is to get a fast computer. Optimization > is only nominal with these compilers. "nominal"? It's critical. I have no idea what you're alluding to but if you're trying to say that the optimizer is not one of the critical parts of a C++ compiler when it comes to performance, you're very mistaken....

Go Back   Application Development Forum > Other Technologies

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #11  
Old 07-26-2007, 11:46 PM
Gianni Mariani
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!

srp@microtec.net wrote:
> On 26 juil, 17:19, lunamoonm...@gmail.com wrote:

....
> Your best bet with C/C++ is to get a fast computer. Optimization
> is only nominal with these compilers.


"nominal"? It's critical.

I have no idea what you're alluding to but if you're trying to say that
the optimizer is not one of the critical parts of a C++ compiler when it
comes to performance, you're very mistaken.
Reply With Quote
  #12  
Old 07-26-2007, 11:55 PM
Luna Moon
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!


"galathaea" <galathaea@veawb.coop> wrote in message
news:galathaea-3B5E95.16354826072007@news.veawb.coop...
> In article <1185484775.445904.137740@g4g2000hsf.googlegroups. com>,
> lunamoonmoon@gmail.com wrote:
>
> !! C/C++ speed optimization bible/resources/pointers needed!
> !!
> !! Hi all,
> !!
> !! I am in the middle of programming to solve an engineering problem
> !! where the speed is huge concern. The project involving lots of
> !! numerical integration and then there are several loops/levels of
> !! optimization on top of the function evaluation engine. As you probably
> !! know, the key to a successful optimization is a fast underlying
> !! objective function evaluator. The faster it is, the more promising the
> !! optimization result(perhaps global optimal). However our project
> !! requires many numerical integrations which prohibits us from making it
> !! super fast. At the heart of the numerical integration is a smart
> !! integrator and a super-fast integrand function evaluator. Even worse,
> !! our function evaluation is in complex-domain. So the kay point is how
> !! to arrange our C/C++ code to make it highly efficient in every aspect.
> !! Could anybody give some advice/pointers on how to improve the speed of
> !! C/C++ program? How to arrange code? How to make it highly efficient
> !! and super fast? What options do I have if I don't have luxury to use
> !! multi-threaded, multi-core or distributed computing? But I do have a
> !! P4 at least. Please recommend some good bibles and resources! Thank
> !! you!
>
> your best friend is a good optimising compiler
>
> in my experience
> codewarrior was top dog when metrowerks owned it
> but now it looks like intel has the best reputation
>
> you have to run benchmarks and profile code execution paths
> but just choosing the right compiler has increased code speed 40% in
> tight loops for me in the past
>
> ( in fact - always verify with profiling what needs work
> otherwise you will almost certainly waste time "optimising" nonessential
> areas )
>
> avoid unnecessary copies
>
> that may seem obvious
> but that means all nonfundamental types should be passed as a const
> reference for inputs
> and you may need to use "expression templates" to prevent certain
> intermediate copies in looped evaluations
>
> see "c++ templates" by vandevoorde and josuttis for a description of
> expression templates
> as applied to matrix computations and related problems
>
> experiment with unrolling loops
> you don't want to unroll too much and have your code walking all over
> your cache
> but too little wastes unnecessary time messing with the iterator
> there is usually a sweet spot
>
> in general
> any calculation that can be done during translationtime
> saves you runtime
>
> the compiler can usually do much of this
> but look at other techniques like metaprogramming if profiling shows you
> are still wasting a lot of time here
>
> cf. abrahams and gurtovoy's "c++ template metaprogramming"
> or czarnecki and eisenecker's "generative programming" for similar methods
>
> use the bit width of your processor
> if you have (as you mention with p4) a 32-bit processor
> be wary of data structures that use 8-bit chars (if they are that on your
> architecture)
>
> i found once that a cryptographic routine that looped over chars for
> encryption
> began running 10x faster (not just 4!) when i 32-bitised all the
> operations
> because address space alignment is precious at the hardware level
>
> also
> you may benefit from branch prediction hints
> compilers like gcc have hints you can add to if statements
> (likely/unlikely)
> that can optimise the most used branches
>
> i have not found that as useful in my work but it is used extensively in
> the linux kernel
>
> and ask the right groups for help
> fortran users are less likely to know c++ tricks than c++ users
> ( probably because they still think its faster despite the optimisations
> that expression templates allow over it! )
>



Indeed, it is very helpful! Thank you!

I am dealing with double and floating points most of the time, since I am
doing numerical programming. Do you and the other experts on these boards
have more to say and more pointers along those lines?

Thanks!


Reply With Quote
  #13  
Old 07-26-2007, 11:56 PM
Luna Moon
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!


<jimp@specsol.spam.sux.com> wrote in message
news:jtpnn4-ras.ln1@mail.specsol.com...
> In sci.physics lunamoonmoon@gmail.com wrote:
>> C/C++ speed optimization bible/resources/pointers needed!

>
>> Hi all,

>
>> I am in the middle of programming to solve an engineering problem
>> where the speed is huge concern. The project involving lots of
>> numerical integration and then there are several loops/levels of
>> optimization on top of the function evaluation engine. As you probably
>> know, the key to a successful optimization is a fast underlying
>> objective function evaluator. The faster it is, the more promising the
>> optimization result(perhaps global optimal). However our project
>> requires many numerical integrations which prohibits us from making it
>> super fast. At the heart of the numerical integration is a smart
>> integrator and a super-fast integrand function evaluator. Even worse,
>> our function evaluation is in complex-domain. So the kay point is how
>> to arrange our C/C++ code to make it highly efficient in every aspect.
>> Could anybody give some advice/pointers on how to improve the speed of
>> C/C++ program? How to arrange code? How to make it highly efficient
>> and super fast? What options do I have if I don't have luxury to use
>> multi-threaded, multi-core or distributed computing? But I do have a
>> P4 at least. Please recommend some good bibles and resources! Thank
>> you!

>
> One more thought, both the OS and the compiler can make a big difference.
>
> Some years ago I did some benchmarking on a customer's application
> on windows, Linux, SCO Unix, Solaris X86, and Unixware both with
> the vendors compiler and GNU all on the same hardware.
>
> I lost the numbers long ago, but windows was the absolute slowest.
>
> Linux, Solaris X86, and the Sun compiler are all free for the download.
>
> It might not hurt to run some benchmarks on your app.
>
> --
> Jim Pennino
>
> Remove .spam.sux to reply.


Thanks! But I cannot ask our head to give me a linux box. I am confined
within what I have now. I have to do whatever I can and use whatever I have
from my part only.


Reply With Quote
  #14  
Old 07-26-2007, 11:57 PM
Luna Moon
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!


<jimp@specsol.spam.sux.com> wrote in message
news:2fhnn4-oq7.ln1@mail.specsol.com...
> In sci.physics lunamoonmoon@gmail.com wrote:
>> C/C++ speed optimization bible/resources/pointers needed!

>
>> Hi all,

>
>> I am in the middle of programming to solve an engineering problem
>> where the speed is huge concern. The project involving lots of
>> numerical integration and then there are several loops/levels of
>> optimization on top of the function evaluation engine. As you probably
>> know, the key to a successful optimization is a fast underlying
>> objective function evaluator. The faster it is, the more promising the
>> optimization result(perhaps global optimal). However our project
>> requires many numerical integrations which prohibits us from making it
>> super fast. At the heart of the numerical integration is a smart
>> integrator and a super-fast integrand function evaluator. Even worse,
>> our function evaluation is in complex-domain. So the kay point is how
>> to arrange our C/C++ code to make it highly efficient in every aspect.
>> Could anybody give some advice/pointers on how to improve the speed of
>> C/C++ program? How to arrange code? How to make it highly efficient
>> and super fast? What options do I have if I don't have luxury to use
>> multi-threaded, multi-core or distributed computing? But I do have a
>> P4 at least. Please recommend some good bibles and resources! Thank
>> you!

>
> If the problem is ameniable to being multi-threaded, you are dismissing
> what would probably be the easiest to implement and biggest speed
> improvement.
>
> Multi-processor Linux boxes aren't all that expensive, expecially
> when you start looking at labor cost to hand optimize.
>
> --
> Jim Pennino
>
> Remove .spam.sux to reply.


Thanks! But I cannot ask our head to give me a linux box. I am confined
within what I have now. I have to do whatever I can and use whatever I have
from my part only. Let's focus on what I can do, coding good C++ code.
Thanks!


Reply With Quote
  #15  
Old 07-26-2007, 11:57 PM
Luna Moon
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!


<srp@microtec.net> wrote in message
news:1185490398.938753.40390@g4g2000hsf.googlegrou ps.com...
On 26 juil, 17:19, lunamoonm...@gmail.com wrote:
> C/C++ speed optimization bible/resources/pointers needed!
>
> Hi all,
>
> I am in the middle of programming to solve an engineering problem
> where the speed is huge concern. The project involving lots of
> numerical integration and then there are several loops/levels of
> optimization on top of the function evaluation engine. As you probably
> know, the key to a successful optimization is a fast underlying
> objective function evaluator. The faster it is, the more promising the
> optimization result(perhaps global optimal). However our project
> requires many numerical integrations which prohibits us from making it
> super fast. At the heart of the numerical integration is a smart
> integrator and a super-fast integrand function evaluator. Even worse,
> our function evaluation is in complex-domain. So the kay point is how
> to arrange our C/C++ code to make it highly efficient in every aspect.
> Could anybody give some advice/pointers on how to improve the speed of
> C/C++ program? How to arrange code? How to make it highly efficient
> and super fast? What options do I have if I don't have luxury to use
> multi-threaded, multi-core or distributed computing? But I do have a
> P4 at least. Please recommend some good bibles and resources! Thank
> you!


Your best bet with C/C++ is to get a fast computer. Optimization
is only nominal with these compilers.

If you have the option, the fastest language all around, due to
structurally built in low level code optimization would be get
a Forth language interpreter/compiler.

Short of going to straight assembly language, nothing is faster.

André Michaud

---------------

thanks! It's good to know Forth is the fastest.

But I cannot ask our head to let me switch to Forth. I am confined within
what I have now. I have to do whatever I can and use whatever I have from my
part only.


Reply With Quote
  #16  
Old 07-26-2007, 11:59 PM
shalayka@gmail.com
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!

On Jul 26, 3:19 pm, lunamoonm...@gmail.com wrote:
> C/C++ speed optimization bible/resources/pointers needed!
>
> Hi all,
>
> I am in the middle of programming to solve an engineering problem
> where the speed is huge concern. The project involving lots of
> numerical integration and then there are several loops/levels of
> optimization on top of the function evaluation engine. As you probably
> know, the key to a successful optimization is a fast underlying
> objective function evaluator. The faster it is, the more promising the
> optimization result(perhaps global optimal). However our project
> requires many numerical integrations which prohibits us from making it
> super fast. At the heart of the numerical integration is a smart
> integrator and a super-fast integrand function evaluator. Even worse,
> our function evaluation is in complex-domain. So the kay point is how
> to arrange our C/C++ code to make it highly efficient in every aspect.
> Could anybody give some advice/pointers on how to improve the speed of
> C/C++ program? How to arrange code? How to make it highly efficient
> and super fast? What options do I have if I don't have luxury to use
> multi-threaded, multi-core or distributed computing? But I do have a
> P4 at least. Please recommend some good bibles and resources! Thank
> you!


Use the inline keyword when possible, don't use function pointers,
unroll your loops, avoid division if possible, and get Intel's
compiler.

Reply With Quote
  #17  
Old 07-27-2007, 12:00 AM
Luna Moon
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!


"Chip Eastham" <hardmath@gmail.com> wrote in message
news:1185498567.079147.230700@19g2000hsx.googlegro ups.com...
> On Jul 26, 5:19 pm, lunamoonm...@gmail.com wrote:
>> C/C++ speed optimization bible/resources/pointers needed!
>>
>> Hi all,
>>
>> I am in the middle of programming to solve an engineering problem
>> where the speed is huge concern. The project involving lots of
>> numerical integration and then there are several loops/levels of
>> optimization on top of the function evaluation engine. As you probably
>> know, the key to a successful optimization is a fast underlying
>> objective function evaluator. The faster it is, the more promising the
>> optimization result(perhaps global optimal). However our project
>> requires many numerical integrations which prohibits us from making it
>> super fast. At the heart of the numerical integration is a smart
>> integrator and a super-fast integrand function evaluator. Even worse,
>> our function evaluation is in complex-domain. So the kay point is how
>> to arrange our C/C++ code to make it highly efficient in every aspect.
>> Could anybody give some advice/pointers on how to improve the speed of
>> C/C++ program? How to arrange code? How to make it highly efficient
>> and super fast? What options do I have if I don't have luxury to use
>> multi-threaded, multi-core or distributed computing? But I do have a
>> P4 at least. Please recommend some good bibles and resources! Thank
>> you!

>
> You haven't described the problem in sufficient detail
> to make specific recommendations. You should look for
> ways to to reuse function evaluations. At one level
> the numerical integrator should be (probably is) doing
> this, and it isn't clear what you mean by saying "our
> function evaluation is in complex-domain". You may
> have some opportunities if you are carrying out line
> integrations in the complex plane to pick up several
> of the function values you need in one pass of the
> line integration, or to pick up a line integration
> from a nearby point at which a previous pass left
> off.
>
> regards, chip
>


Thanks Chip. By "complex-domain" I meant the integrand numbers are
complex-valued. Any more thoughts?


Reply With Quote
  #18  
Old 07-27-2007, 12:01 AM
shalayka@gmail.com
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!

On Jul 26, 9:59 pm, shala...@gmail.com wrote:
> On Jul 26, 3:19 pm, lunamoonm...@gmail.com wrote:
>
>
>
> > C/C++ speed optimization bible/resources/pointers needed!

>
> > Hi all,

>
> > I am in the middle of programming to solve an engineering problem
> > where the speed is huge concern. The project involving lots of
> > numerical integration and then there are several loops/levels of
> > optimization on top of the function evaluation engine. As you probably
> > know, the key to a successful optimization is a fast underlying
> > objective function evaluator. The faster it is, the more promising the
> > optimization result(perhaps global optimal). However our project
> > requires many numerical integrations which prohibits us from making it
> > super fast. At the heart of the numerical integration is a smart
> > integrator and a super-fast integrand function evaluator. Even worse,
> > our function evaluation is in complex-domain. So the kay point is how
> > to arrange our C/C++ code to make it highly efficient in every aspect.
> > Could anybody give some advice/pointers on how to improve the speed of
> > C/C++ program? How to arrange code? How to make it highly efficient
> > and super fast? What options do I have if I don't have luxury to use
> > multi-threaded, multi-core or distributed computing? But I do have a
> > P4 at least. Please recommend some good bibles and resources! Thank
> > you!

>
> Use the inline keyword when possible, don't use function pointers,
> unroll your loops, avoid division if possible, and get Intel's
> compiler.


.... trying to port your code to run on GPU is also worth a shot.

Reply With Quote
  #19  
Old 07-27-2007, 12:35 AM
jimp@specsol.spam.sux.com
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!

In sci.physics Luna Moon <lunamoonmoon@gmail.com> wrote:

> <jimp@specsol.spam.sux.com> wrote in message
> news:2fhnn4-oq7.ln1@mail.specsol.com...
> > In sci.physics lunamoonmoon@gmail.com wrote:
> >> C/C++ speed optimization bible/resources/pointers needed!

> >
> >> Hi all,

> >
> >> I am in the middle of programming to solve an engineering problem
> >> where the speed is huge concern. The project involving lots of
> >> numerical integration and then there are several loops/levels of
> >> optimization on top of the function evaluation engine. As you probably
> >> know, the key to a successful optimization is a fast underlying
> >> objective function evaluator. The faster it is, the more promising the
> >> optimization result(perhaps global optimal). However our project
> >> requires many numerical integrations which prohibits us from making it
> >> super fast. At the heart of the numerical integration is a smart
> >> integrator and a super-fast integrand function evaluator. Even worse,
> >> our function evaluation is in complex-domain. So the kay point is how
> >> to arrange our C/C++ code to make it highly efficient in every aspect.
> >> Could anybody give some advice/pointers on how to improve the speed of
> >> C/C++ program? How to arrange code? How to make it highly efficient
> >> and super fast? What options do I have if I don't have luxury to use
> >> multi-threaded, multi-core or distributed computing? But I do have a
> >> P4 at least. Please recommend some good bibles and resources! Thank
> >> you!

> >
> > If the problem is ameniable to being multi-threaded, you are dismissing
> > what would probably be the easiest to implement and biggest speed
> > improvement.
> >
> > Multi-processor Linux boxes aren't all that expensive, expecially
> > when you start looking at labor cost to hand optimize.
> >
> > --
> > Jim Pennino
> >
> > Remove .spam.sux to reply.


> Thanks! But I cannot ask our head to give me a linux box. I am confined
> within what I have now. I have to do whatever I can and use whatever I have
> from my part only. Let's focus on what I can do, coding good C++ code.
> Thanks!


If you have the box, all you need to do is install Linux on it.

Linux is a free download.

You aren't actually going to use Windows are you?

--
Jim Pennino

Remove .spam.sux to reply.
Reply With Quote
  #20  
Old 07-27-2007, 12:44 AM
jimp@specsol.spam.sux.com
Guest
 
Default Re: C/C++ speed optimization bible/resources/pointers needed!

In sci.physics Luna Moon <lunamoonmoon@gmail.com> wrote:

> <jimp@specsol.spam.sux.com> wrote in message
> news:jtpnn4-ras.ln1@mail.specsol.com...
> > In sci.physics lunamoonmoon@gmail.com wrote:
> >> C/C++ speed optimization bible/resources/pointers needed!

> >
> >> Hi all,

> >
> >> I am in the middle of programming to solve an engineering problem
> >> where the speed is huge concern. The project involving lots of
> >> numerical integration and then there are several loops/levels of
> >> optimization on top of the function evaluation engine. As you probably
> >> know, the key to a successful optimization is a fast underlying
> >> objective function evaluator. The faster it is, the more promising the
> >> optimization result(perhaps global optimal). However our project
> >> requires many numerical integrations which prohibits us from making it
> >> super fast. At the heart of the numerical integration is a smart
> >> integrator and a super-fast integrand function evaluator. Even worse,
> >> our function evaluation is in complex-domain. So the kay point is how
> >> to arrange our C/C++ code to make it highly efficient in every aspect.
> >> Could anybody give some advice/pointers on how to improve the speed of
> >> C/C++ program? How to arrange code? How to make it highly efficient
> >> and super fast? What options do I have if I don't have luxury to use
> >> multi-threaded, multi-core or distributed computing? But I do have a
> >> P4 at least. Please recommend some good bibles and resources! Thank
> >> you!

> >
> > One more thought, both the OS and the compiler can make a big difference.
> >
> > Some years ago I did some benchmarking on a customer's application
> > on windows, Linux, SCO Unix, Solaris X86, and Unixware both with
> > the vendors compiler and GNU all on the same hardware.
> >
> > I lost the numbers long ago, but windows was the absolute slowest.
> >
> > Linux, Solaris X86, and the Sun compiler are all free for the download.
> >
> > It might not hurt to run some benchmarks on your app.
> >
> > --
> > Jim Pennino
> >
> > Remove .spam.sux to reply.


> Thanks! But I cannot ask our head to give me a linux box. I am confined
> within what I have now. I have to do whatever I can and use whatever I have
> from my part only.


Sigh, Linux is free; all you have to do is download and install it.

Linux will be a LOT faster than Windows when doing number crunching.

--
Jim Pennino

Remove .spam.sux to reply.
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 12:42 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.