Here you will find the easiest explanation for max max algorithm in grid computing.
Let us first know why this algorithm is needed?
This is a static task scheduling algorithm used for load balancing.
The Max-Max algorithm first finds the maximum execution time of all tasks. Then it chooses the task with the maximum execution time among all the tasks. The algorithm proceeds by assigning the task to the resource that produces the maximum completion time. The same procedure is repeated by Max-Max until all tasks are scheduled.
Let us take an example before moving to the code
Here Task 1 will execute in 140ms in VM1 and in 100 ms in VM2. Task 2 will execute for 20ms in VM1 and in 100ms in VM2 . Task 3 will run for 60 ms in VM1 and for 70 ms in VM2.
What is a Task ?
Let’s take an example. Suppose you have developed a social media app called fakebook. Now user one wants to change her DP , another user wants to create her account and the third user wants to like a picture.
All these are the tasks and involve manipulation in the database. The entity responsible for that change is the backend server. For effective use of the server you have made virtual partitions of the server making some virtual machines good for light computation and some virtual machines for heavy computation.
Now for sure you will not let a weak virtual machine to do heavy computation and a strong machine to do a trivial task, but this is the optimal condition, therefore we need task scheduling algorithm to make this decision for us.
Algorithm to solve the problem
- Find maximum time for each task , in the above image maximum time for each task is (140 ms ,T1 ,VM1), (100 ms, T2, VM2) ,(70 ms, T3, VM2)
- Now find the set with maximum time and that is (140 ms, T1, VM1)
- Execute T1 in VM1 for 140ms
- Since 140ms has been elapsed we need to update our data. New data is:
5. Here we impute T1 as INT_MIN to let our code know that this task is over and it denotes negative infinite. Now repeat step 1
6. Find maximum time for each task , in the above image maximum time for each task is (160 ms ,T2 ,VM1), (200 ms, T3, VM1)
7. Now find the set with maximum time and that is (200 ms, T3, VM1)
8. Execute T3 in VM1 for 200ms
9. Since 200ms has been elapsed we need to update our data. New data is:
10. Find maximum time for each task , in the above image maximum time for each task is (360 ms ,T2 ,VM1)
11. Exit Since all task has been scheduled.
Makespan produced by any algorithm for a schedule can be calculated as follows:
makespan = max (CT (ti, mj))
CTij = Rj+ETij
Where CT completion time of machines ,ETij expected execution time of job i on resource j , Rj ready time or availability time of resource j after completing the previously assigned jobs.
Here makespan = max(140,200,360) = 360 ms
Finally the Code
int nT,nM;//number of tasks , number of machines
printf(“\nEnter number of machines and tasks\n”);
Declare a 2d-array of size nM x nT
Data should be in the following format :
T1 T2 T3
M1 | 140 | 20 | 60 |
M2 | 100 | 100 | 70 |
// visualise data
//This array will hold the answer
int ptr=-1; //Indicates if result set is full or not
int time[nT],machine[nT]; //stores maximum time w.r.t machine of each task
int maximum = INT_MIN;
// Now we find task with maximum time
// resetting states
else if(i==resultMachine[ptr] && maxMax[i][j]!=INT_MIN)
printf(“\nScheduled Task are :\n”);
printf(“\nTask %d Runs on Machine %d with Time %d units\n”,resultTask[i]+1,resultMachine[i]+1,resultTime[i]);
printf(“\nMakespan time : %d units\n”,makespan);
As you can make it out it is not that efficient a algorithm but it is not the worst, although the makespan is very high.