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.2.0.275 (1.2.0.275)

Syntax

C#
long YieldResource(
        string resource,
        long amount
)
Visual Basic
Function YieldResource ( _
        resource As String, _
        amount As Long _
) As Long

Parameters

resource
Type: System..::..String
The resource. You can find common values for resources using ConsumableResources.
amount
Type: System..::..Int64
The amount.

Return Value

The resource amount currently consumed by the task.

Examples

  Copy imageCopy
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);
            }
        }
    }
}

Exceptions

Exception Condition
System..::..ArgumentNullException If resource is null.
System..::..ArgumentOutOfRangeException If amount if less than 0.
AGI.Parallel.Client..::..JobSchedulerException If error occurred during operation. For instance, there were not enough resources to satisfy reserve request.

See Also