I think I was mistaken in my earlier post. I think recursion works just fine for async workflows.

My limited brain has been struggling to come up with an algorithm where nested data parallelism would be useful. Instead, I've modified this algorithm ([link:vernagus.blogspot.com]) to use async workflows.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
type Elem = int

type Tree =
    | E
    | T of Tree * Elem * Tree

let empty = E

let rec mem a t =
    async {
        match a, t with
        | x, E -> return false
        | x, T(a, y, b) when x < y ->
            let! contains = mem x a
            return contains
        | x, T(a, y, b) when y < x ->
            let! contains = mem x b
            return contains
        | _ -> return true
    }

let rec insert a t =
    match a, t with
    | x, E -> T(E, x, E)
    | x, T(a, y, b) when x < y -> T((insert x a), y, b)
    | x, T(a, y, b) when y < x -> T(a, y, (insert x b))
    | _, s -> s

Again, I don't know about the utility of this translation.

By on 4/16/2009 9:32 AM ()

If you're talking about doing an async operation inside of another, it appears so:

1
2
3
4
5
6
7
8
9
10
11
12
#light

let matrix = [|1..100|] |> Array.map (fun x -> [|1..x|])

let sumrow (row:int array) = 
    let task = async { return row |> Array.sum }
    Async.Run(Async.Parallel[task])
    
let summatrix (matrix:int array array) =
    async { return matrix |> Array.map sumrow }
    
printfn "%A" (Async.Run(Async.Parallel[summatrix matrix]))
By on 3/17/2009 10:03 AM ()

I think he's talking about the Haskell construct:

[link:www.cs.cmu.edu]

As I understand it (which is to say, not much), nested data parallelism allows the compiler to parallelize divide-and-conquer algorithms transparently to the developer.

So, async workflows work great with looped constructs. But, it would be more difficult to use async workflows with recursive functions.

My naive instinct thinks that it wouldn't be too difficult to build nested data parallel constructs into async workflows. But, as far as I know, such a thing does not exist currently in f#.

By on 3/17/2009 2:10 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper