Using all available streams of bad practice?

I recently started working with C ++ again and wrote a simple test application that finds the best way through the matrix of integer values. To improve the performance of this application, I implemented multithreading using C ++ 11 std :: thread.

unsigned int threadCount = std::thread::hardware_concurrency(); std::vector<std::thread> threads; for (unsigned int threadIndex = 0; threadIndex < threadCount; threadIndex++) { threads.push_back(std::thread(&AltitudeMapPath::bestPath, this, threadCount, threadIndex)); } for (auto& thread : threads) { thread.join(); } 

As of now, I simply determine the total number of threads available and run my test for each thread. It worked fantastic, but it made me think ...

Is it a good idea to try to use all available threads for this system? Besides this simple example, are multi-threaded performance-level applications trying to capture as many threads as they can (or, it might seem, a problem), or shouldn't I be so greedy?

Thanks,

+5
source share
1 answer

I don’t think that there is one correct good practice, how many kernels the application should use depends on the user's preferences. There will be times when the user wants the application to run as fast as possible, and there will be times when the user prefers multitasking and the application does not run on the machine.

I had a similar problem and decided to adjust the number of threads so that the user could choose between speed and availability of processor resources. I can come up with at least one application that uses a similar configuration, so I do not think that it is rarely possible to let the user choose.

If you are forced to choose for the user, I would suggest using the number of hardware cores - 1 to free up the thread so that the user can do other work.

Also keep in mind that std::thread::hardware_concurrency() is for help and is allowed to return 0 if it cannot make a determination.

+6
source

All Articles