1

We have a list of tasks with different length, a number of cpu cores and a Context Switch time. We want to find the best scheduling of tasks among the cores to maximize processor utilization. How could we find this? Isn't it like if we choose the biggest available tasks from the list and give them one by one to the current ready cores, it's going to be best or you think we must try all orders to find out which is the best?

I must add that all cores are ready at the time unit 0 and the tasks are supposed to work concurrently.

Mahdi
  • 251
  • 2
  • 12
  • 1
    This sounds very similar to [an NP-complete problem](http://en.wikipedia.org/wiki/Partition_problem). – svick Dec 22 '12 at 17:29
  • Are you implying that all the tasks need to be worked on at the same time? Because if not, I don't see how the result would be affected by optimization(just assign any task to any free processor whenever a processor becomes available). – goat Dec 22 '12 at 18:13
  • @svick +1 for interpretation – Rubens Dec 22 '12 at 19:15
  • @rambocoder Imagine you have 2 CPUs, 1 task that takes 10 s and 2 tasks, each taking 5 s. If you schedule them correctly, you will be done in 10 s. But if you schedule them incorrectly, it might take 15 s. I think that's big enough difference to figure a better algorithm than “assign any task to any free processor”. – svick Dec 22 '12 at 20:10

1 Answers1

1

The idea here is that there's no silver bullet, for what you must consider what are the types of tasks being executed, and try to schedule them as nicely as possible.

  • CPU-bound tasks don't use much communication (I/O), and thus, need to be continuously executed, and interrupted only when necessary -- according to the policy being used;

  • I/O-bound tasks may be continuously put aside in the execution, allowing other processes to work, since it will be sleeping for many periods, waiting for data to be retrieved to primary memory;

  • interative tasks must be continuously executed, but needs not to be executed without interruptions, as it will generate interruptions, waiting for user inputs, but it needs to have a high priority, in order not to let the user notice delays in the execution.

Considering this, and the context switch costs, you must evaluate what types of tasks you have, choosing, thus, one or more policies for your scheduler.

Edit:

I thought this was a simply conceptual question. Considering you have to implement a solution, you must analyze the requirements.

Since you have the length of the tasks, and the context switch times, and you have to maintain the cores busy, this becomes an optimization problem, where you must keep the minimal number of cores idle when it reaches the end of the processes, but you need to maintain the minimum number of context switches, so that your overall execution time does not grow too much.

As pointed by svick, this sounds like a partition problem, which is NP-complete, and in which you need to divide a sequence of numbers into a given number of lists, so that the sum of each list is equal to each other.

In your problem you'd have a relaxation on the objective, so that you no longer need all the cores to execute the same amount of time, but you want the difference between any two cores execution time to be as small as possible.

In the reference given by svick, you can see a dynamic programming approach that you may be able to map onto your problem.

Rubens
  • 14,478
  • 11
  • 63
  • 92
  • Thanks for your reply. Unfortunately we are not told the type of tasks to be executed. The only thing that we know is the length of each task for some time unit. Maybe we must consider them as CPU bound tasks. How do you think I can solve this? I'm supposed to implement this in java. – Mahdi Dec 22 '12 at 18:02
  • @mahdisaeedi I've added an edit, but I do not have an algorithm to your problem. – Rubens Dec 22 '12 at 19:16