Scenario:
Given a set of resources R:
Given a set of threads T, which will run in parallel:
Each thread needs to access a list of n resources. Each list is a sample of R, meaning that each resource is unique within each list:
But since the access lists are sampled randomly, there can be conflicts:
The random resource lists will be initialized once in the beginning. After that, each thread will do an atomicAdd operation on each resource in the list, subsequently. The access order of the resources in each list is irrelevant.
Question:
Is there an algorithm which sorts the scheduling lists, so that the number of writing conflicts gets minimized? So the final result would look like this:
My insights so far:
Possible approaches:
I am looking for an analytical solution for this problem. Could it be np-complete? If this is the case, I am thinking about designing a genetic algorithm to solve this problem.
Edit 1: Added diagrams.
I think the question is asking "can we sort the lists to reduce the conflicts."
I think an optimum solution is NP complete, but I would look for the number of occurances in the set for each resource.
The most commonly used resource is the hardest one to schedule. Thus I would place in each of the threads this resource in position 1, 2, 3, 4, ... Until conflict occurs (which may be unavoidable) e.g. 1,2,3,4,..., n, 1, 2,... .
These are the "big stones". These should be placed first.
The next most commonly used resource should then be tried. This should identify which slots (1 => n) have been used recently and search through that list for a slice which is both unallocated and not recently used.
Whichever slot is chosen, it moves to the top of the recently used queue to be avoided for a while.
This favours distributing the resource, but allows duplicates. These duplicates will become recently used, and not favoured again for scheduling until no valid choices are available.
Step 2 is repeated for each of the resources in order of their occurances.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With