Such is the task: you need to generate placements with repetitions from n to k. This will be n ^ k elements. If n = 2, k = 128, then the generation time will be, let's say, considerable) It is also well known that the standard program does not use all the power of the processor, but only loads it by 5-6 percent. So the actual question is: how can I use all the power of my dual-core processor and in turn reduce the generation time for placements?

    1 answer 1

    If the program only does that all the time something thinks, then ONE processor core will be loaded completely. In order to fully load both cores, it is necessary to make two threads, between which to divide the calculations and somehow synchronize them. This is the simplest example of parallel computing.

    You can program threads manually using the operating system API, you can use wrappers like Boost.Threads or C ++ 11 threads. You can apply some kind of framework. Especially useful for this OpenMP task.

    • one
      Only synchronization is not too carried away. Very expensive. Simply, the algorithm should naturally be parallelized into independent parts (without intersecting data). For posih threads in Linux (the others didn’t check in practice), a slight excess of their number over hardware resources (n CPU or 2 * n CPU with core hyperthreading) does not slow down the program. - avp