i got a bit of a problem.
I've got an input: "/0-9/0-9/0-9/0-9". in this case its 10^4 possibilities.
my program analyze it and calculate all the permutations, and prints the output. in our case the output is: 0001 0002 . . . 9999
the problem is th开发者_StackOverflowat i have a server application (written in c#) that receives this input, and suppose to split the task of the calculation evenly between the connected clients. in the end each client need to print his part.
the limitation is that the format of the task sent by the server to the client must be in the format "/#-#/#-#/#-#/#-#/" server can send more then one task to each client providing all the clients get same number of tasks.
one more example: i got two connected clients. and my input is /0-9/0-9/0-9/0-9/ so i'll send:
clinet1: /0-4/0-9/0-9/0-9/
clinet2: /5-9/0-9/0-9/0-9/
how do i split evenly between n clients?
tnx
I would approach this by figuring out how many of the 10^4
possibilities each client needs to solve if you were to distribute the items evenly:
Items per client = 10^4 / N
Say N = 20
, then Items per client = 500
. So now you need to break up the input into groups of 500
0-0/0-4/0-9/0-9 (0 - 499)
0-0/5-9/0-9/0-9 (500 - 999)
1-1/0-4/0-9/0-9 (1000 - 1499)
1-1/5-9/0-9/0-9 (1500 - 1999)
2-2/0-4/0-9/0-9 (2000 - 2499)
etc etc
This becomes a little messier when N does not divide evenly into 10^4 but you can simply round the # of jobs to send to each client up so that clients occasionally overlap on jobs at the endpoints of the intervals
Edit: Example if N = 3 then Items per client = 3333.333. Then round this down to 3000 each and have the last one do 4000
Client 1: 0-2/0-9/0-9/0-9
Client 2: 3-5/0-9/0-9/0-9
Client 3: 6-9/0-9/0-9/0-9
You could generalize this algorithm to split up the items evenly. If N is between 1-10 then you will be splitting the first interval. If N is between 11-100 then you will be splitting the 2nd interval. If N is between 101 - 1000 you will be splitting on the 3rd interval
精彩评论