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!
> 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.
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.
!! 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! )
> 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.
[email protected] wrote:
> In sci.physics [email protected] 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.
It doesn't matter how many threads there are. What matters is the number
of processor cycles that can be dedicated to the task in a given time.
Jerry
--
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
[email protected] wrote:
> 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.
What's more, inlining assembly code is an inherent part of the language.
Optimizing native-code Forth compilers are not available for many
embeddable processors, but there are some. Check http://www.forth.com/
and http://www.mpeltd.demon.co.uk/ for starters.
Jerry
--
Engineering is the art of making what you want from things you can get.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
On 26 juil, 20:46, Jerry Avins <j...@ieee.org> wrote:
> s...@microtec.net wrote:
> > 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.
>
> What's more, inlining assembly code is an inherent part of the language.
> Optimizing native-code Forth compilers are not available for many
> embeddable processors, but there are some. Checkhttp://www.forth.com/
> andhttp://www.mpeltd.demon.co.uk/for starters.
>
> Jerry
> --
> Engineering is the art of making what you want from things you can get.
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.
In sci.physics Jerry Avins <[email protected]> wrote:
> [email protected] wrote:
> > In sci.physics [email protected] 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.
> It doesn't matter how many threads there are. What matters is the number
> of processor cycles that can be dedicated to the task in a given time.
And for a multi-processor box you get processor cycles times the
number of CPUs assuming your OS is a true multi-processor OS.
A threaded application will run slower on a single CPU machine than
the same application none-threaded.
If one assumes the machine is dedicated to running the application,
the close to maximum performance will be when there is the same number
of CPUs as there are threads.
You may get a slight improvement if there are threads + 1 CPUs.
If you are doing other things, then you need a CPU per thread plus
enough CPUs to handle whatever else is going on to get max performance.
And, you need to have enough memory to keep everything in memory or
things slow down with disk swapping.
[email protected] 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.
"galathaea" <[email protected]> wrote in message
news:[email protected]..
> In article <[email protected] com>,
> [email protected] 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?
<[email protected]> wrote in message
news:[email protected]..
> In sci.physics [email protected] 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.
<[email protected]> wrote in message
news:[email protected]..
> In sci.physics [email protected] 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!
<[email protected]> wrote in message
news:[email protected] 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.
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.
"Chip Eastham" <[email protected]> wrote in message
news:[email protected] 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?
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.
> <[email protected]> wrote in message
> news:[email protected]..
> > In sci.physics [email protected] 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.
> <[email protected]> wrote in message
> news:[email protected]..
> > In sci.physics [email protected] 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.
> 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!
I usually do test to see where it is spending the most time.
It might be that you already know that is in function evaluation.
If so, you either have to simplify the function or get by with
fewer evaluations.
Without tests, I would not be so sure, though.
I sometimes, on intel processors, use the time stamp counter
available with the RDTSC instruction. For IA32 that usually
requires a two instruction assembly program that returns a
64 bit integer in EDX:EAX. It is a little more complicated
for x86-64.
> 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
I've seen a 500% boost just from adding a compiler option (-mfpmath).
With this option, gcc uses SSE1/2 units for floating point calculations
(SISD, not vector code) instead of traditional x87 code.
glen herrmannsfeldt schrieb:
> [email protected] wrote:
>
>> 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?
> I usually do test to see where it is spending the most time. [..]
> I sometimes, on intel processors, use the time stamp counter
> available with the RDTSC instruction.
I found the Intel VTune application to be very helpful. It can
run your program (with debug information), samples the CPU
performance counters and then gives you a list of all functions
and the CPU time (clocks) spend in each function. For each funtion,
you can see the CPU clocks spend per source line or per assembly
operation.
> 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.
There is no reason Linux should be faster, in general, for number
crunching. The numeric instructions take the same number of cycles
independent of the OS. For speedy number crunching one should minimize
the amount of paging, which could be OS dependent, as could I/O.
If one is doing a lot of paging or I/O, then I would say that one
is not doing number crunching. (That is, the task is I/O limited
and not CPU limited.)
(Not that I don't agree that Linux is a much better system to
use than the others under consideration.)
Regardless of the task the first thing to do is to use a profiler
to find out where the CPU spends most of its time. Usually
it spends 80% of its time in 20% of the code.
When you know where the time is spent you can either optimize
the existing code manually (you got enough hints already) or use
a faster algorithm or program design.
Usually you trade memory and/or precision for speed, for example:
- if you have a function which consumes a lot of time you can
replace it with an approximation table (more memory, less precision)
- if a function often calculates the same result you can cache its
results for later reuse (more memory).