How does the compiler determine how long each task will take without running the code so that the CPU can schedule them more efficiently?
@grarawr, typically if work assignment is left up to the compiler, the compiler will not attempt to statically assign tasks to worker threads by trying to predict how long each task is going to take. Instead, it will implement dynamic assignment with a pool of worker threads and a work queue.
Static assignment, when it occurs, is typically done by the programmer where the programmer has a much better knowledge than the compiler about the nature of the work distribution of the program and can provide to the compiler an optimal distribution of work.
Adding on to that, is the dynamic assignment greedy then? Or is there a more intelligent mechanism that optimizes the assignment?
@taylor128 Of course, there are more intelligent ways to assign the tasks. You can refer to this paper. Basically, the paper uses instructions per cycle (IPC) as a metric to determine the assignment.