IJobSchedulerContextYieldResource Method (String, Int64)

Yields the resource with the specified amount without a restriction to children.
Namespace:  AGI.Parallel.Infrastructure
Assembly:  AGI.Parallel.Infrastructure (in AGI.Parallel.Infrastructure.dll) Version: 1.4.0.476 (1.4.0.476)
Syntax
long YieldResource(
        string resource,
        long amount
)

Parameters

resource
Type: SystemString
The resource. You can find common values for resources using ConsumableResources.
amount
Type: SystemInt64
The amount.

Return Value

Type: Int64
The resource amount currently consumed by the task.
Exceptions
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.
Examples
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);
            }
        }
    }
}
See Also

STK Scalability 1.4 API for .NET