Introduction to CPU-intensive Cloud Parallelism
This tutorial is from the MBrace Starter Kit.
In this tutorial you learn how to perform CPU-intensive cloud-parallel workload on your MBrace cluster. The work will be computing prime numbers, though you can easily replace this with any code of your own.
First, you run some work on your local machine (single-threaded). Performance will depend on the spec of your machine.
Note that it is possible that your client scripting machine is more efficient than each individual machine in the cluster.
1: 2: 3: 4: |
|
Next, you run the work on the cluster, on multiple workers. This exploits the the multiple machines (workers) in the cluster.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: |
|
Starting multiple jobs
The previous example used Cloud.Parallel
to compose jobs into one combined job.
Alternatively, you could have started 30 independent jobs. This can be handy if you want to track each one independently:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: |
|
For example, you might want to track the exectuion time of each job:
1: 2: |
|
Tracking and controlling job failures
Jobs can fail for all sorts of reasons, normally by raising exceptions. For example, let's simulate this by injecting failures into our jobs:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: |
|
If you now attempt to access the results of the job, you will get the exception propagated back to your client scripting session:
1: 2: 3: |
|
When this happens, it is useful to protect your jobs by a wrapper that captures information about the failing work:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: |
|
The results will now show the success and failure of each job:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: |
|
You can then re-create adjusted versions of failing jobs and re-run them:
1:
|
|
Summary
In this tutorial, you've learned how to do simple CPU-intensive work using MBrace.Azure. 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: 3-cloud-parallel-cpu-intensive.cluster
Full name: Config.GetCluster
Gets or creates a new Thespian cluster session.
Full name: 3-cloud-parallel-cpu-intensive.locallyComputedPrimes
Full name: Sieve.getPrimes
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
Full name: 3-cloud-parallel-cpu-intensive.clusterPrimesTask
static member CommandLine : string
static member CurrentDirectory : string with get, set
static member Exit : exitCode:int -> unit
static member ExitCode : int with get, set
static member ExpandEnvironmentVariables : name:string -> string
static member FailFast : message:string -> unit + 1 overload
static member GetCommandLineArgs : unit -> string[]
static member GetEnvironmentVariable : variable:string -> string + 1 overload
static member GetEnvironmentVariables : unit -> IDictionary + 1 overload
static member GetFolderPath : folder:SpecialFolder -> string + 1 overload
...
nested type SpecialFolder
nested type SpecialFolderOption
Full name: System.Environment
Full name: 3-cloud-parallel-cpu-intensive.clusterPrimes
Full name: 3-cloud-parallel-cpu-intensive.jobs
Full name: 3-cloud-parallel-cpu-intensive.jobResults
Full name: 3-cloud-parallel-cpu-intensive.jobTimes
Full name: 3-cloud-parallel-cpu-intensive.makeJob
Full name: Microsoft.FSharp.Core.Operators.failwith
Full name: 3-cloud-parallel-cpu-intensive.jobs2
Full name: cloudparallelcpuintensive.jobResults2
| Success of 'T
| Failure of 'Info * exn
Full name: 3-cloud-parallel-cpu-intensive.Result<_,_>
union case Result.Failure: 'Info * exn -> Result<'T,'Info>
--------------------
active recognizer Failure: exn -> string option
Full name: Microsoft.FSharp.Core.Operators.( |Failure|_| )
Full name: Microsoft.FSharp.Core.exn
Full name: 3-cloud-parallel-cpu-intensive.protectJob
Full name: 3-cloud-parallel-cpu-intensive.jobs3
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = String
Full name: Microsoft.FSharp.Core.string
Full name: 3-cloud-parallel-cpu-intensive.jobResults3
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string
Full name: Microsoft.FSharp.Collections.list<_>
val Failure : message:string -> exn
Full name: Microsoft.FSharp.Core.Operators.Failure
--------------------
active recognizer Failure: exn -> string option
Full name: Microsoft.FSharp.Core.Operators.( |Failure|_| )
type Exception =
new : unit -> Exception + 2 overloads
member Data : IDictionary
member GetBaseException : unit -> Exception
member GetObjectData : info:SerializationInfo * context:StreamingContext -> unit
member GetType : unit -> Type
member HelpLink : string with get, set
member InnerException : Exception
member Message : string
member Source : string with get, set
member StackTrace : string
...
Full name: System.Exception
--------------------
System.Exception() : unit
System.Exception(message: string) : unit
System.Exception(message: string, innerException: exn) : unit