Click or drag to resize

IEnforceTaskPrecondition Interface

Indicates that the job scheduler enforces task preconditions. This is a marker interface and has no methods.

Namespace:  AGI.Parallel.Client
Assembly:  AGI.Parallel.Client (in AGI.Parallel.Client.dll) Version: 2.9.0.1601 (2.9.0.1601)
Syntax
public interface IEnforceTaskPrecondition
Examples
using System;
using System.Collections.Generic;
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();

                // Check if this feature is supported by querying for the IEnforceTaskPrecondition interface.
                IEnforceTaskPrecondition preconditionCapable = scheduler as IEnforceTaskPrecondition;
                if (preconditionCapable != null)
                {
                    IList<AgentSnapshot> agents = ((IGetAgentInfo)preconditionCapable).GetAgentInfo();
                    string agentMachineName = agents[0].MachineName;

                    Job job = scheduler.CreateJob();

                    // Restrict the task to be run only on the first agent machine.
                    job.TaskPreconditions.Add(CommonResources.Hostname, Operator.MemberOf, new string[] { agentMachineName });

                    // Restrict the task to be run on machines that have at least 1 empty host slot.
                    job.TaskPreconditions.Add(CommonResources.AvailableCores, Operator.GreaterThan, 0);

                    job.AddTask(new RestrictedTask());

                    job.Submit();
                    job.WaitUntilDone();

                    Console.WriteLine(job.Tasks[0].Result);
                }
                else
                {
                    Console.WriteLine("This job scheduler does not support task preconditions.");
                }
            }

            /*
             * The output of the application should resemble:
             * Hello from MyComputerName
             */
        }

        [Serializable]
        public class RestrictedTask : Task
        {
            public override void Execute()
            {
                this.Result = "Hello from " + Environment.MachineName;
            }
        }
    }
}
See Also

STK Parallel Computing Server 2.9 API for .NET