MBrace.Core and MBrace.Azure

Your First 'Hello World' Computation with MBrace

This tutorial is from the MBrace Starter Kit.

A guide to creating a cluster is here.

Start F# Interactive in your editor. Highlight the text below and press "Alt-Enter" (Visual Studio) or the other appropriate execution command for your editor. This connects to the cluster. If you are using a locally simulated cluster it also creates the cluster.

let cluster = Config.GetCluster()

Next, get details of the workers in your cluster. Again, highlight the text below and execute it in your scripting client:


Now execute your first cloud workflow, returning a handle to the running job:

let task = 
    cloud { return "Hello world!" } 
    |> cluster.CreateProcess

This submits a task to the cluster. To get details for the task, execute the following in your scripting client:


Your task is likely complete by now. To get the result returned by your task, execute the following in your scripting client:

let text = task.Result

Alternatively we can do this all in one line:

let quickText = 
    cloud { return "Hello world!" } 
    |> cluster.Run

To check that you are running in the cloud, compare a workflow running locally with one using cloud execution. (Note, if using an MBrace.Thespian locally simulated cluster, these will be identical.)

let localResult =
    cloud { printfn "hello, world" ; return Environment.MachineName }
    |> cluster.RunLocally

let remoteResult =
    cloud { printfn "hello, world" ; return Environment.MachineName }
    |> cluster.Run

Controlling the Cluster

To view the history of processes, execute the following line from your scriptin


In case you run into trouble, you can clear all process records in the cluster by executing the following from your scripting client:


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.


namespace System
namespace System.IO
namespace MBrace
namespace MBrace.Core
namespace MBrace.Flow
val cluster : MBrace.Thespian.ThespianCluster

Full name: 1-hello-world.cluster
module Config
val GetCluster : unit -> MBrace.Thespian.ThespianCluster

Full name: Config.GetCluster

 Gets or creates a new Thespian cluster session.
member MBrace.Runtime.MBraceClient.ShowWorkers : unit -> unit
val task : MBrace.Runtime.CloudProcess<obj>

Full name: 1-hello-world.task
member MBrace.Runtime.MBraceClient.CreateProcess : workflow:MBrace.Core.Cloud<'T> * ?cancellationToken:MBrace.Core.ICloudCancellationToken * ?faultPolicy:MBrace.Core.FaultPolicy * ?target:MBrace.Core.IWorkerRef * ?additionalResources:MBrace.Core.Internals.ResourceRegistry * ?taskName:string -> MBrace.Runtime.CloudProcess<'T>
member MBrace.Runtime.CloudProcess.ShowInfo : unit -> unit
val text : obj

Full name: 1-hello-world.text
property MBrace.Runtime.CloudProcess.Result: obj
val quickText : obj

Full name: 1-hello-world.quickText
member MBrace.Runtime.MBraceClient.Run : workflow:MBrace.Core.Cloud<'T> * ?cancellationToken:MBrace.Core.ICloudCancellationToken * ?faultPolicy:MBrace.Core.FaultPolicy * ?target:MBrace.Core.IWorkerRef * ?additionalResources:MBrace.Core.Internals.ResourceRegistry * ?taskName:string -> 'T
val localResult : obj

Full name: 1-hello-world.localResult
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
type Environment =
  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
property Environment.MachineName: string
member MBrace.Runtime.MBraceClient.RunLocally : workflow:MBrace.Core.Cloud<'T> * ?cancellationToken:MBrace.Core.ICloudCancellationToken * ?memoryEmulation:MBrace.Core.MemoryEmulation -> 'T
val remoteResult : obj

Full name: 1-hello-world.remoteResult
member MBrace.Runtime.MBraceClient.ShowProcesses : unit -> unit
member MBrace.Runtime.MBraceClient.ClearAllProcesses : unit -> unit
Fork me on GitHub