Click here to Skip to main content
15,943,477 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Implement a prototype of a resource allocation system in a distributed parallel computing infrastructure.

There are n resources and m tasks to schedule on them where the ith task has a processing time of burst Time[i]. The total load time of a resource is the sum of the total burst times of the jobs assigned to the resources. However, a particular resource can be allocated jobs in a contiguous segment only i.e. from some index x to some index yor [x, x + 1, x + 2, ..., y].

Find the minimum possible value of the maximum total load time of the servers if resources are allocated optimally.

What I have tried:

#include <stdio.h>

int canAllocate(int tasks[], int n, int m, int maxLoad) {
    int resourceIdx = 0; // Index of the current resource
    int currentLoad = 0; // Load of the current resource

    for (int i = 0; i < m; i++) {
        if (currentLoad + tasks[i] <= maxLoad) {
            currentLoad += tasks[i];
        } else {
            resourceIdx++;  // Move to the next resource
            currentLoad = tasks[i];

            if (resourceIdx >= n) {
                return 0; // Cannot allocate tasks optimally
            }
        }
    }

    return 1; // Tasks can be allocated optimally
}

int minMaxTotalLoadTime(int resources, int tasks[], int m) {
    int low = 0;
    int high = 0;

    // Calculate the total load and maximum task time
    for (int i = 0; i < m; i++) {
        high += tasks[i];
    }

    // Perform binary search to find the minimum possible maximum load time
    while (low < high) {
        int mid = (low + high) / 2;
        if (canAllocate(tasks, resources, m, mid)) {
            high = mid;
        } else {
            low = mid + 1;
        }
    }

    return high; // Minimum possible maximum total load time
}

int main() {
    int resources = 3;
    int tasks[] = {2, 4, 6, 8, 10};
    int m = sizeof(tasks) / sizeof(tasks[0]);

    int result = minMaxTotalLoadTime(resources, tasks, m);
    printf("Minimum possible maximum total load time: %d\n", result);

    return 0;
}
Posted
Updated 15-Sep-23 22:47pm
v2
Comments
Dave Kreskowiak 16-Sep-23 1:11am    
You seem to have forgotten to describe a problem you're having or even ask a question.
OriginalGriff 16-Sep-23 1:17am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
Patrice T 16-Sep-23 2:04am    
And you have question ?
Rick York 16-Sep-23 12:48pm    
Except for loop indexes, you should avoid using single letters for variable names. They are detrimental to readability.

1 solution

As already noted several times, no specific questions were asked. Generally answered, the problem must first be analyzed as precisely as possible in order to model a software design on the basis of it. Simply programming away is not a sensible approach.

The source code shown does not seem to cover the requirements of the problem completely.

According to the description tasks are to be distributed parallel on several resources. The resources are divided into resource sections with a fixed time span. A task may only ever occupy contiguous resource sections.

Obviously, tasks and resources must be defined with their properties. If one assumes for the sake of simplicity that one defines the tasks temporally as the number of resource slots to be occupied one after the other and manages only the number of these resource slots for the resources, questions remain open or unresolved.

Since it was not specified that tasks have an order or a fixed start time, one could assume that all tasks can be distributed directly to one of the resources.

Since not otherwise indicated each resource pool is unrestricted, the total utilization time of the system should now be minimized by optimally allocated resources.

Currently, the program does not take care of parallel tasks, nor does it remember which tasks were distributed to which resource sections.

Perhaps a possible approach would be to first model all the details of the tasks and resources.
The search for the solution is then an optimization problem for which there are many strategies. Which strategy should be used to find the solution?

In C you could solve resources and tasks with a combination of arrays and structures. If the number is not known, a linked list would be a possible solution.
But the complete solution would be your task. Without own effort the learning effect would be missing.Here you can ask and get hints and if necessary hints to solutions, if it hangs somewhere.
A description as exact as possible where a concrete problem occurs as well as at least one concrete question to it would be necessary.
 
Share this answer
 
v3
Comments
CPallini 18-Sep-23 3:13am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900