Introduction to Cloud Combinators
This tutorial is from the MBrace Starter Kit.
You now perform a very simple parallel distributed job on your MBrace cluster.
You now use Cloud.Parallel to run 10 cloud workflows in parallel using fork-join pattern.
1: 2: 3: 4: 5: 6: |
|
Get the results
1:
|
|
Cloud.Parallel is not the only combinator for parallelism and for some
items doesn't use all multi-core capacity on machines.
The Cloud.ParallelBalanced
combinator defined in lib/utils.fsx
is
designed for use when you have many single-machine, single-core items to run on multiple
machines using multi-core capacity.
When specifying individual work items that are constrained
to only execute on a single machine you use local { ... }
. These work
items must commonly be used as inputs to parallelism combinators that
use particular multi-core aware scheduling strategies.
1: 2: 3: 4: 5: 6: |
|
Get the results
1:
|
|
Again, in shorthand
1: 2: 3: 4: |
|
Next you use Cloud.Choice: the first cloud workflow to return "Some" wins.
1: 2: 3: 4: 5: 6: |
|
Await the result of the search:
1:
|
|
Like Cloud.ParallelBalanced
, you can also use Cloud.ChoiceBalanced, which is multi-core aware.
1: 2: 3: 4: 5: 6: |
|
Await the result of the search:
1:
|
|
Summary
In this tutorial, you've learned about Cloud.Parallel
and Cloud.Choice
as ways of composing cloud workflows. You've also learned about Cloud.ParallelBalanced
and Cloud.ChoiceBalanced
defined in lib/utils.fsx
which utlize the multi-code capacity off your cluster.
Continue with further samples to learn more about the MBrace programming model.
Note, you can use the above techniques from both scripts and compiled projects. To see the components referenced by this script, see ThespianCluster.fsx or AzureCluster.fsx.
Full name: 2-cloud-parallel.cluster
Full name: Config.GetCluster
Gets or creates a new Thespian cluster session.
Full name: 2-cloud-parallel.parallelTask
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
Full name: 2-cloud-parallel.results
Full name: 2-cloud-parallel.parallelTask2
Full name: 2-cloud-parallel.results2
Full name: 2-cloud-parallel.quickResults
Full name: 2-cloud-parallel.searchTask
type Choice<'T1,'T2> =
| Choice1Of2 of 'T1
| Choice2Of2 of 'T2
Full name: Microsoft.FSharp.Core.Choice<_,_>
--------------------
type Choice<'T1,'T2,'T3> =
| Choice1Of3 of 'T1
| Choice2Of3 of 'T2
| Choice3Of3 of 'T3
Full name: Microsoft.FSharp.Core.Choice<_,_,_>
--------------------
type Choice<'T1,'T2,'T3,'T4> =
| Choice1Of4 of 'T1
| Choice2Of4 of 'T2
| Choice3Of4 of 'T3
| Choice4Of4 of 'T4
Full name: Microsoft.FSharp.Core.Choice<_,_,_,_>
--------------------
type Choice<'T1,'T2,'T3,'T4,'T5> =
| Choice1Of5 of 'T1
| Choice2Of5 of 'T2
| Choice3Of5 of 'T3
| Choice4Of5 of 'T4
| Choice5Of5 of 'T5
Full name: Microsoft.FSharp.Core.Choice<_,_,_,_,_>
--------------------
type Choice<'T1,'T2,'T3,'T4,'T5,'T6> =
| Choice1Of6 of 'T1
| Choice2Of6 of 'T2
| Choice3Of6 of 'T3
| Choice4Of6 of 'T4
| Choice5Of6 of 'T5
| Choice6Of6 of 'T6
Full name: Microsoft.FSharp.Core.Choice<_,_,_,_,_,_>
--------------------
type Choice<'T1,'T2,'T3,'T4,'T5,'T6,'T7> =
| Choice1Of7 of 'T1
| Choice2Of7 of 'T2
| Choice3Of7 of 'T3
| Choice4Of7 of 'T4
| Choice5Of7 of 'T5
| Choice6Of7 of 'T6
| Choice7Of7 of 'T7
Full name: Microsoft.FSharp.Core.Choice<_,_,_,_,_,_,_>
Full name: 2-cloud-parallel.searchResult
Full name: 2-cloud-parallel.searchTask2
Full name: 2-cloud-parallel.searchResult2