Export (0) Print
Expand All

Getting a List of Nodes in the Cluster

The following C# and C++ examples show how to list the compute nodes of a cluster and get information about them, such as the amount of memory and number of cores. This example enumerates all nodes in the cluster. For an example that shows how to filter and sort the nodes, see Filtering and Sorting Lists of Objects.


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

namespace Getting_a_List_of_Nodes_in_the_Cluster
{
    class Program
    {
        static void Main(string[] args)
        {
            IScheduler scheduler = new Scheduler();

            try
            {
                scheduler.Connect("localhost");

                foreach (ISchedulerNode node in scheduler.GetNodeList(null, null))
                {
                    PrintNodeProperties(node);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

        private static void PrintNodeProperties(ISchedulerNode node)
        {
            Console.WriteLine("Properties for node {0}:", node.Name);
            Console.WriteLine("Id: {0}", node.Id);
            Console.WriteLine("Guid: {0}", node.Guid.ToString());
            Console.WriteLine("State: {0}", node.State);
            Console.WriteLine("Reachable: {0}", node.Reachable);
            Console.WriteLine("CpuSpeed: {0:f2} GHz", node.CpuSpeed / 1000.0);
            Console.WriteLine("MemorySize: {0:f2} GB", node.MemorySize / 1000.0);
            Console.WriteLine("NumberOfCores: {0}", node.NumberOfCores);
            Console.WriteLine("NumberOfSockets: {0}", node.NumberOfSockets);
            Console.WriteLine("MoveToOffline: {0}", node.MoveToOffline);
            Console.WriteLine("OfflineTime: {0}", (DateTime.MinValue == node.OfflineTime) ? "" : node.OfflineTime.ToString());
            Console.WriteLine("OnlineTime: {0}", (DateTime.MinValue == node.OnlineTime) ? "" : node.OnlineTime.ToString());

            Console.WriteLine("Node groups to which this node belong:");
            foreach (string name in node.NodeGroups)
            {
                Console.WriteLine("\t" + name);
            }

            Console.Write("Supported job types:");
            if (JobType.Batch == (node.JobType & JobType.Batch))
                Console.Write(" Scheduled batch jobs");
            if (JobType.Admin == (node.JobType & JobType.Admin))
                Console.Write(", Command jobs");
            if (JobType.Service == (node.JobType & JobType.Service))
                Console.Write(", SOA service jobs");
            if (JobType.Broker == (node.JobType & JobType.Broker))
                Console.Write(", SOA broker jobs");
            Console.WriteLine();

            Console.WriteLine("Core information:");
            foreach (ISchedulerCore core in node.GetCores())
            {
                if (SchedulerCoreState.Offline == core.State)
                    Console.WriteLine("\tCore {0} is offline", core.Id);
                else if (SchedulerCoreState.Idle == core.State)
                    Console.WriteLine("\tCore {0} is idle", core.Id);
                else if (SchedulerCoreState.Busy == core.State)
                {
                    if (0 == core.TaskId.JobTaskId)
                        Console.WriteLine("\tCore {0} is reserving resources for job {1}", core.Id, core.JobId);
                    else
                        Console.WriteLine("\tCore {0} is running task {1} of job {2}", core.Id, core.TaskId.JobTaskId, core.JobId);
                }
                else if (SchedulerCoreState.Draining == core.State)
                    Console.WriteLine("\tCore {0} is running task {1} of job {2}" +
                        "\tand will be taken offline when done.", core.Id, core.TaskId.JobTaskId, core.JobId);
            }

            Console.WriteLine();
        }
    }
}


Related topics

Using HPC

 

 

Show:
© 2015 Microsoft