Ask Your Question
1

How to speed up this code implemented OpenCV

asked 2013-02-08 13:19:50 -0600

wolvican gravatar image

updated 2013-02-08 13:42:44 -0600

I need an advice for sample below code that requires lots of time for processing. I am developing project on OpenCV and have code blocks like this ( some of them are pictures ). What should I use for more speed? Like, OpenMP or TBB ( that's new in OpenCV and more complex, maybe some examples more helpful ) or GPU ( implementing entire project ) or Boost library or another I don't know 3rd party libraries.

i didn't write multithread on c++ before

thanks for helping now

sample code snippet:

for( int i = 0; i < 3000; i++ )
    for( int j = 0; j < 3000; j++ )
        for ( int index = 0; index < 3000; index++ )
           // float point operations
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-02-08 13:37:45 -0600

sammy gravatar image

This is the fastest way to solve your mystery:

int n = 9000;
int a = n*(n-1)/2;

By the way, while this is not what you are looking for, it proves a point: the best optimizations are algorithm simplifications, not brute-force calculations.

And if you want an example code for OpenMP or TBB, please have a look in their documentation.

edit flag offensive delete link more

Comments

thank you, but in here calculation of a is not an issue. I asked question wrongly. how can handle like double or triple for?

wolvican gravatar imagewolvican ( 2013-02-08 13:44:58 -0600 )edit

The answer is the same: focus on getting rid of double for loops. Then, for parallel processing, read OpenMP/TBB docs.

sammy gravatar imagesammy ( 2013-02-09 00:18:50 -0600 )edit

Question Tools

Stats

Asked: 2013-02-08 13:19:50 -0600

Seen: 1,523 times

Last updated: Feb 08 '13