open Microsoft.ParallelArrays
|
type P = ParallelArrays
|
|
type Row = IntParallelArray
|
type Tree = Row list
|
|
let row2row (a: Row) (b: Row) : Row =
|
let sa = a.GetLength(0)
|
let bL = P.Section(b, new SectionSpecifier(0, sa))
|
let bR = P.Section(b, new SectionSpecifier(1, sa))
|
P.Add(a, P.Min(bL, bR))
|
|
let rec costsTree (t: Tree) : Row * Tree =
|
match t with
|
| x::[] -> (x, [x])
|
| x::xs -> let (y, ys) = costsTree xs
|
let z = row2row x y
|
(z, z::ys)
|
|
let randomRow (rnd: System.Random) (w: int) : Row = new IntParallelArray(Array.map (fun _ -> rnd.Next(10)) [|1 .. w|])
|
|
let randomTree (w: int) (r: int) : Tree =
|
let rnd = System.Random(1)
|
List.map (randomRow rnd) [w .. w + r]
|
|
// para testear
|
let tree1 : Tree = [ new IntParallelArray([| 3;0 |])
|
; new IntParallelArray([| 3;1;0 |])
|
; new IntParallelArray([|3;5;0;9|])
|
]
|
|
[<EntryPoint>]
|
let main argv =
|
printfn "Generando árbol..."
|
let (w, r) = (System.Int32.Parse(argv.[0]), System.Int32.Parse(argv.[1]))
|
let tree = randomTree w r
|
printfn "Total rows: %A" (List.length tree)
|
printfn "Calculando rutas mínimas..."
|
let t0 = System.DateTime.UtcNow
|
let (s, _) = costsTree tree
|
let res = (new MulticoreTarget()).ToArray1D(s)
|
let t1 = System.DateTime.UtcNow
|
printfn "%A" res
|
printfn "%A" ((t1 - t0).TotalSeconds)
|
0 // devolver un código de salida entero
|