Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Filtering and Sorting Lists of Objects

Filtering and Sorting Lists of Objects

When retrieving jobs, tasks, and nodes, you can filter and sort the results. The following C# and C++ examples show how to filter the nodes that you want to retrieve.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Hpc.Scheduler;
using Microsoft.Hpc.Scheduler.Properties;

namespace Filtering_and_Sorting_Lists_of_Objects
{
    class Program
    {
        static void Main(string[] args)
        {
            IScheduler scheduler = new Scheduler();
            ISchedulerCollection nodes = null;
            IFilterCollection filters = null;
            ISortCollection sortOn = null;

            try
            {
                scheduler.Connect("localhost");

                // Specify the filter criteria.
                filters = scheduler.CreateFilterCollection();
                filters.Add(FilterOperator.GreaterThanOrEqual, PropId.Node_NumCores, 1);
                filters.Add(FilterOperator.HasBitSet, PropId.Node_State, NodeState.Online);

                // Specify the sort criteria
                sortOn = scheduler.CreateSortCollection();
                sortOn.Add(SortProperty.SortOrder.Ascending, PropId.Node_NumCores);
                sortOn.Add(SortProperty.SortOrder.Descending, PropId.Node_CpuSpeed);

                // Get the list of nodes that match the filter criteria
                // and return them in the specified sort order.
                nodes = scheduler.GetNodeList(filters, sortOn);

                if (nodes.Count > 0)
                {
                    Console.WriteLine("Nodes matching filter criteria:");
                    Console.WriteLine("Name\t\tCores\tCPU Speed\tMemory");
                    foreach (ISchedulerNode node in nodes)
                    {
                        Console.WriteLine("{0}\t{1}\t{2:f2} GHz\t{3:f2} GB",
                            node.Name, node.NumberOfCores, node.CpuSpeed / 1000.0, node.MemorySize / 1000.0);
                    }
                }
                else
                {
                    Console.WriteLine("No nodes match the filter criteria.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}


Related topics

Using HPC

 

 

Show:
© 2015 Microsoft