Welcome to Questionaries, where you can ask questions and receive answers from other members of the community.

Let us know at info@questionaries.org

Speedup C++ code.............!

11 like 0 dislike
Hi,

    I am writing a C++ number crunching application, where the bottleneck is a function that has to calculate for double:

 template<class T> inline T sqr(const T& x){return x*x;}

and another one that calculates

Base   dist2(const Point& p) const
       { return sqr(x-p.x) + sqr(y-p.y) + sqr(z-p.z); }

These operations take 80% of the computation time. I wonder if you can suggest approaches to make it faster, even if there is some sort of accuracy loss

Thanks.........................
asked 2 years ago by biswaskeran (70,430 points)

1 Answer

0 like 0 dislike
If you have a number of these to do, and you're doing graphics or "graphic like" tasks (thermal modeling, almost any 3d modeling) you might consider using OpenGL and offloading the tasks to a GPU. This would allow the computations to run in parallel, with highly optimized operational capacity. After all, you would expect something like distance or distancesq to have its own opcode on a GPU.

A researcher at a local univeristy offload almost all of his 3d-calculations for AI work to the GPU and achieved much faster results.
answered 2 years ago by tulip (12,960 points)

Related questions

8 like 0 dislike
1 answer
asked 2 years ago by pollard (41,990 points)
12 like 0 dislike
1 answer