Previous | Next --- Slide 16 of 59
Back to Lecture Thumbnails
aravisha

If you don't know how long any arbitrary "task" would take e.g. how long a specific loop iteration would take, how would you dynamically assign tasks to threads in a way that is smart?

anon

One possible method of assigning work is just letting each task take an element off the work queue whenever it is finished with its current task. This would have the benefit of leaving no threads idle while there are tasks to complete, but there are still problems that are going to be difficult to navigate regardless of algorithm. For example if you have 4 cores and 5 tasks, where each takes time t, but the last task is time 2t, ideally you would give the 2t task to one core, and let the other cores handle the remaining 4, giving 2t total time. But just greedily assigning would leave the 2t for last, giving 3t total time.