/// <summary> /// Returns a cloud computation that will execute the given computation on every available worker /// possibly in parallel and will return when any of the supplied computations /// have returned a successful value or if all of them fail to succeed. /// If a computation succeeds the rest of them are canceled. /// The success of a computation is encoded as an option type. /// This operator may create distribution. /// </summary> /// <typeparam name="TResult">Computation return type.</typeparam> /// <param name="workflow">Input workflow to be executed nondeterministically everywhere.</param> /// <returns>The result of the first computation to complete in the positive.</returns> public static Cloud <Option <TResult> > Choice <TResult>(Cloud <Option <TResult> > workflow) { Func <Option <TResult>, MBrace.Cloud <FSharpOption <TResult> > > transform = option => Builder.Return(option.AsFSharpOption()); var fsTransform = transform.AsFSharpFunc(); var x = Builder.Bind(workflow, fsTransform); var choice = MCloud.Choice(x); Func <FSharpOption <TResult>, MBrace.Cloud <Option <TResult> > > transformRev = fsOption => Builder.Return(Option <TResult> .FromFSharpOption(fsOption)); var fsTransformRev = transformRev.AsFSharpFunc(); var result = Builder.Bind(choice, fsTransformRev); return(result); }
/// <summary> /// Performs a nondeterministic computation in parallel. /// </summary> /// <typeparam name="TResult">Computation return type.</typeparam> /// <param name="workflows">Input workflows to be executed nondeterministically.</param> /// <returns>The result of the first computation to complete in the positive.</returns> public static Cloud <Option <TResult> > Choice <TResult>(this IEnumerable <Cloud <Option <TResult> > > workflows) { Func <Option <TResult>, MBrace.Cloud <FSharpOption <TResult> > > transform = option => Builder.Return(option.AsFSharpOption()); var fsTransform = transform.AsFSharpFunc(); var wfs = workflows .Select(wf => Builder.Bind(wf, fsTransform)) .ToArray(); var choice = MCloud.Choice <TResult>(wfs); Func <FSharpOption <TResult>, MBrace.Cloud <Option <TResult> > > transformRev = fsOption => Builder.Return(Option <TResult> .FromFSharpOption(fsOption)); var fsTransformRev = transformRev.AsFSharpFunc(); var result = Builder.Bind(choice, fsTransformRev); return(result); }
/// <summary> /// Executes a collection of workflows using parallel fork/join semantics. /// </summary> /// <typeparam name="TResult">Computation return type.</typeparam> /// <param name="workflows">Input workflows to be executed in parallel.</param> /// <returns>Array of aggregated results.</returns> public static Cloud <TResult[]> Parallel <TResult>(this IEnumerable <Cloud <TResult> > workflows) { var wfs = workflows.Select(w => w).ToArray(); return(MCloud.Parallel(wfs)); }
/// <summary> /// Performs cloud computation discarding its result. /// </summary> /// <typeparam name="TResult">Return type of the given workflow.</typeparam> /// <param name="workflow">The workflow to ignore.</param> public static CloudAction Ignore <TResult>(this Cloud <TResult> workflow) { return(new CloudAction(MCloud.Ignore(workflow))); }
/// <summary> /// Gets the assigned id of the currently running cloud task. /// </summary> public static Cloud <string> GetJobId() { return(MCloud.GetJobId()); }
/// <summary> /// Gets the assigned id of the currently running cloud process. /// </summary> public static Cloud <string> GetProcessId() { return(MCloud.GetProcessId()); }
abstract public T RunOnCurrentProcess <T>(MBrace.Cloud <T> c);
/// <summary> /// Await for task completion. /// </summary> /// <typeparam name="TResult">Return type of task.</typeparam> /// <param name="task">Task to be awaited.</param> public static Cloud <TResult> AwaitTask <TResult>(Task <TResult> task) { return(MCloud.AwaitTask(task, null)); }
/// <summary> /// Asynchronously suspends workflow for given amount of milliseconds. /// </summary> /// <param name="millisecondsDue">Milliseconds to suspend computation.</param> public static CloudAction Sleep(int millisecondsDue) { return(new CloudAction(MCloud.Sleep(millisecondsDue))); }
/// <summary> /// Gets total number of available workers in cluster context. /// </summary> /// <returns>The number of workers.</returns> public static Cloud <int> GetWorkerCount() { return(MCloud.GetWorkerCount()); }
/// <summary> /// Writes the following message to MBrace logging interface. /// </summary> /// <param name="format">Format string.</param> /// <param name="args">Arguments to format string.</param> public static CloudAction Log(string format, params object[] args) { return(new CloudAction(MCloud.Log(String.Format(format, args)))); }
abstract public T RunLocally <T>(MBrace.Cloud <T> c);
abstract public T Run <T>(MBrace.Cloud <T> c);
/// <summary> /// Creates a cloud computation that will execute provided computation on every available worker /// in the cluster and if successful returns the array of gathered results. /// This operator may create distribution. /// Any exception raised by children carry cancellation semantics. /// </summary> /// <typeparam name="TResult">Computation return type.</typeparam> /// <param name="workflow"></param> /// <returns>Array of the aggregated results.</returns> public static Cloud <TResult[]> Parallel <TResult>(Cloud <TResult> workflow) { return(MCloud.Parallel(workflow)); }
/// <summary> /// Disposes of a distributed resource. /// </summary> /// <param name="disposable">The resource to be disposed.</param> public static CloudAction Dispose <Disposable>(this Disposable disposable) where Disposable : ICloudDisposable { return(new CloudAction(MCloud.Dispose(disposable))); }
/// <summary> /// Creates a cloud computation that will execute given computations to targeted workers /// possibly in parallel and if successful returns the array of gathered results. /// This operator may create distribution. /// Exceptions raised by children carry cancellation semantics. /// </summary> /// <typeparam name="TResult">Computation return type.</typeparam> /// <param name="workflows">Input workflows to be executed in parallel in each worker.</param> /// <returns>Array of the aggregated results.</returns> public static Cloud <TResult []> Parallel <TResult>(this IEnumerable <Tuple <Cloud <TResult>, IWorkerRef> > workflows) { var wfs = workflows.ToArray(); return(MCloud.Parallel(wfs)); }
/// <summary> /// Get all workers in currently running cluster context. /// </summary> public static Cloud <IWorkerRef []> GetAvailableWorkers() { return(MCloud.GetAvailableWorkers()); }
/// <summary> /// For internal use only. Encapsulate workflow. /// </summary> /// <param name="body"></param> public CloudAction(MBrace.Cloud <Unit> body) { this.Body = body; }
/// <summary> /// Gets the assigned id of the currently running work item. /// </summary> public static Cloud <string> GetWorkItemId() { return(MCloud.GetWorkItemId()); }