Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Multithreading Problem

Hey guys,

I'm facing a problem: I want to generate multiple oversegmented images. To reduce the time consumption, I want to do this in parallel. My code looks like the following:

int main(){
//Initialization Stuff
pFileHandler = new cFileHandler();
pPreProcessing = new cPreProcessing();
pSegmentation = new cSegmentation();
//Read Images
pFileHandler->m_read_images();
//Start Threads
for (int i = 0; i < number_of_threads; i++)
{
    thread_arr.push_back(new boost::thread(threadFunc, i));
}
//Wait for all threads to finish
for (int i = 0; i < number_of_threads; i++)
{
    thread_arr.at(i)->join();
}
   }

void threadFunc(int thread_ID){

std::cout << "ID: " << thread_ID << std::endl;
pSegmentation->segment_image(thread_ID, pFileHandler->getRGB(), segmented_images_arr);
    }

In the moment all segmentation processes are identical and each image is segmented by one thread. Problem: The more threads I use, the more execution time it needs. E.g. only using one thread (segment one image) needs about 3 seconds, using 2 threads needs about 4 seconds and using 4 threads about 7 seconds. I am very confused, because I expect that it wont make such a different in using 1,2,3,4 or 6 threads. Does anybody know why this happens? For clarity I am using the SLIC algorithm from the opencv extra modules. I appreciate any hint.

Thanks in advance

Horsti

Multithreading Problem

Hey guys,

I'm facing a problem: I want to generate multiple oversegmented images. images (images with multiple superpixels). To reduce the time consumption, I want to do this in parallel. My code looks like the following:

int main(){
//Initialization Stuff
pFileHandler = new cFileHandler();
pPreProcessing = new cPreProcessing();
pSegmentation = new cSegmentation();
//Read Images
pFileHandler->m_read_images();
//Start Threads
for (int i = 0; i < number_of_threads; i++)
{
    thread_arr.push_back(new boost::thread(threadFunc, i));
}
//Wait for all threads to finish
for (int i = 0; i < number_of_threads; i++)
{
    thread_arr.at(i)->join();
}
   }

void threadFunc(int thread_ID){

std::cout << "ID: " << thread_ID << std::endl;
pSegmentation->segment_image(thread_ID, pFileHandler->getRGB(), segmented_images_arr);
    }

In the moment all segmentation processes are identical and each image is segmented by one thread. Problem: The more threads I use, the more execution time it needs. E.g. only using one thread (segment one image) needs about 3 seconds, using 2 threads needs about 4 seconds and using 4 threads about 7 seconds. I am very confused, because I expect that it wont make such a different in using 1,2,3,4 or 6 threads. Does anybody know why this happens? For clarity I am using the SLIC algorithm from the opencv extra modules. I appreciate any hint.

Thanks in advance

Horsti