IJobSchedulerContextYieldResource Method (String, Int64) |
Namespace: AGI.Parallel.Infrastructure
Exception | Condition |
---|---|
ArgumentNullException | If resource is null. |
ArgumentOutOfRangeException | If amount if less than 0. |
JobSchedulerException | If error occurred during operation. For instance, there were not enough resources to satisfy reserve request. |
using System; using System.Threading; using AGI.Parallel.Client; using AGI.Parallel.Infrastructure; namespace CodeSamples { class Program { static void Main(string[] args) { using (IJobScheduler scheduler = new ClusterJobScheduler("localhost")) { scheduler.Connect(); Task yieldOwnCore = new YieldOwnCore(); Task takeAllCores = new TakeAllCores(); takeAllCores.SetProperty(TaskProperties.MinCoresForTask, scheduler.GetMaximumHostCount()); Job job = scheduler.CreateJob(); job.AddTask(yieldOwnCore); job.AddTask(takeAllCores); job.Submit(); job.WaitUntilDone(); // Note that task2 had to block until task1 yielded his core. Console.WriteLine("Task1: Start: " + yieldOwnCore.GetProperty<DateTime>(TaskProperties.HostStartTime)); Console.WriteLine("Task1: End: " + yieldOwnCore.GetProperty<DateTime>(TaskProperties.HostEndTime)); Console.WriteLine("Task2: Start: " + takeAllCores.GetProperty<DateTime>(TaskProperties.HostStartTime)); Console.WriteLine("Task2: End: " + takeAllCores.GetProperty<DateTime>(TaskProperties.HostEndTime)); } /* * The output of the application should resemble: * Task1: Start: 7/11/2013 3:00:47 PM * Task1: End: 7/11/2013 3:00:52 PM * Task2: Start: 7/11/2013 3:00:49 PM * Task2: End: 7/11/2013 3:00:49 PM */ } [Serializable] public class YieldOwnCore : Task { public override void Execute() { IJobSchedulerContext schedulerContext = this.GetProperty<IJobSchedulerContext>(TaskProperties.JobSchedulerContext); // He's going to give back his allocated core schedulerContext.YieldResource(ConsumableResources.Cores, 1); // But he can still do work if he wants. Thread.Sleep(5000); } } [Serializable] public class TakeAllCores : Task { public override void Execute() { IJobSchedulerContext schedulerContext = this.GetProperty<IJobSchedulerContext>(TaskProperties.JobSchedulerContext); } } } }
STK Parallel Computing Server 2.9 API for .NET