Optimal Resource Allocation for Batched Jobs
Nvidia GPUs are powerful, but efficient resource allocation is crucial for maximizing throughput in data centers. Imagine you're managing a cluster of GPU nodes, each with a specific memory capacity. You have a queue of compute jobs, each requiring a certain amount of memory. To maximize the number of jobs run on any given node, it's a common strategy to prioritize smaller jobs. This problem asks you to determine, for various GPU node capacities, the maximum number of jobs that can be simultaneously allocated.
Implement the allocateJobs function. Given an array of memory requirements for all available jobs and an array of memory capacities for various GPU nodes, your task is to return an array where each element corresponds to a GPU node's capacity and indicates the maximum number of jobs that can be allocated to it. Assume that jobs are always allocated optimally: by picking jobs with the smallest memory requirements first until the GPU node's capacity is reached or no more jobs can fit.
allocateJobs(jobMemoryRequirements: number[], gpuCapacities: number[]): number[]jobMemoryRequirements: An array of positive integers, where jobMemoryRequirements[i] represents the memory (in MB) required by the i-th job.gpuCapacities: An array of positive integers, where gpuCapacities[j] represents the total available memory (in MB) on the j-th GPU node.The function should return an array of integers results, where results[j] is the maximum number of jobs that can be allocated to the GPU node with capacity gpuCapacities[j].
jobMemoryRequirements and gpuCapacities will not be empty.jobMemoryRequirements does not imply any priority. You should determine the optimal allocation strategy yourself.gpuCapacities[j].Examples
Example 1
Input:
jobMemoryRequirements = [20, 10, 30, 15], gpuCapacities = [30, 60]
Output:
[2, 3]
Note:
Example 2
Input:
jobMemoryRequirements = [5, 10, 15], gpuCapacities = [4, 5, 20, 30]
Output:
[0, 1, 2, 3]
Note:
Example 3
Input:
jobMemoryRequirements = [1000000000, 1000000000, 1000000000], gpuCapacities = [1, 2500000000]
Output:
[0, 2]
Note:
Constraints
1 <= jobMemoryRequirements.length <= 10^51 <= gpuCapacities.length <= 10^51 <= jobMemoryRequirements[i] <= 10^91 <= gpuCapacities[j] <= 10^15Loading editor...