Created
July 30, 2012 14:18
-
-
Save dungpa/3207237 to your computer and use it in GitHub Desktop.
Parallelism bits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Preassign the divider with some configurations. | |
member x.preassignBB(level, threadId) = | |
for l in 1..level do | |
if threadId &&& (pown 2 l) <> 0 then | |
path.[depth] <- 1uy | |
totalValues.[1] <- totalValues.[1] + itemValues.[depth] | |
totalUnassigned <- totalUnassigned - itemValues.[depth] | |
depth <- depth + 1 | |
else | |
path.[depth] <- 0uy | |
totalValues.[0] <- totalValues.[0] + itemValues.[depth] | |
totalUnassigned <- totalUnassigned - itemValues.[depth] | |
depth <- depth + 1 | |
let solveBB(itemValues) = | |
let bd = new BootyDivider(itemValues) | |
bd.divideBB() | |
let solveBBParallel(itemValues, level) = | |
let count = pown 2 level | |
// Setup different booty dividers with different configurations. | |
let bds = Array.init count (fun _ -> new BootyDivider(itemValues)) | |
for i in 0..count-1 do | |
bds.[i].preassignBB(level, i) | |
let solutions = Array.zeroCreate count | |
Parallel.For(0, count, | |
fun i -> solutions.[i] <- bds.[i].divideBB()) |> ignore | |
Array.min solutions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment