TopCoder problem "ParallelSpeedup" used in SRM 165 (Division I Level One , Division II Level Two)



Problem Statement

    

Your boss thinks you can speed up an application you are writing by running it on multiple processors in parallel. Your application performs k independent tasks that each take 1 millisecond to run on a single processor. Distributing a task across several processors does not make it run faster, but running different tasks on different processors may indeed make your application faster.

Unfortunately, when your application runs on more than one processor, communication overheads between processors become a significant factor. In particular, every pair of processors spends overhead milliseconds communicating with each other before work on the tasks can begin. Worse, because the processors share a single bus for communications, different pairs of processors cannot communicate in parallel. For example, if overhead is 2 milliseconds and you run your application on 3 processors, there will be a 6 millisecond delay before the actual computations begin: 2 milliseconds for processors 1 and 2 to communicate, 2 milliseconds for processors 1 and 3 to communicate, and 2 milliseconds for processors 2 and 3 to communicate. Note that, once the initial communications phase has completed, no further communications are required, even if each processor is executing multiple tasks.

Your task is to determine the number of processors that will run the k tasks in the minimum amount of time, assuming overhead milliseconds of communication overhead per pair of processors. If several configurations of processors will achieve the minimum amount of time, prefer the configuration with the smallest number of processors.

 

Definition

    
Class:ParallelSpeedup
Method:numProcessors
Parameters:int, int
Returns:int
Method signature:int numProcessors(int k, int overhead)
(be sure your method is public)
    
 

Constraints

-k is between 1 and 1000000, inclusive.
-overhead is between 1 and 10, inclusive.
 

Examples

0)
    
12
1
Returns: 2
The application runs in 7 milliseconds on 2 processors (1 millisecond of communication and 6 milliseconds for the actual tasks). It also runs in 7 milliseconds on 3 processors (3 milliseconds of communication and 4 milliseconds for the actual tasks). However, we prefer the smaller number of processors.
1)
    
50
3
Returns: 3
The application runs in 26 milliseconds on 3 processors (9 milliseconds of communication and 17 milliseconds for the tasks). One of the processors actually finishes one millisecond early, after a total of 25 milliseconds, but the application is not considered complete until the last task is finished.
2)
    
9
10
Returns: 1
3)
    
3333
2
Returns: 12
4)
    
1000000
4
Returns: 63

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=1866

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4630&pm=1866

Writer:

vorthys

Testers:

lbackstrom , brett1479

Problem categories:

Brute Force, Simple Search, Iteration