Exemple #1
0
        public List <ExecutionStatistics> Start <TStringCollection>(string executionName, int numberOfExecutionIterations)
            where TStringCollection : IStringCollection, new()
        {
            _stringCollection = new TStringCollection();
            _executionName    = executionName;

            List <ExecutionStatistics> executionStatistics = new List <ExecutionStatistics>();

            for (int executionIteration = 0; executionIteration < numberOfExecutionIterations; executionIteration++)
            {
                _stopWatch.Start();
                ParallelLoopResult loopResult = Parallel.ForEach(_wordsToPopulate, (word) =>
                {
                    _stringCollection.AddString(word);
                });
                _stopWatch.Stop();

                SpinWait.SpinUntil(() => loopResult.IsCompleted);

                executionStatistics.Add(new ExecutionStatistics()
                {
                    WordCount          = _wordsToPopulate.Length,
                    PopulatedWordCount = _stringCollection.NumberOfWords,
                    ExecutionTime      = _stopWatch.Elapsed,
                });

                _stringCollection.Reset();
                _stopWatch.Reset();
            }

            return(executionStatistics);
        }
Exemple #2
0
        public ChooseJobTemplate(string cluster)
        {
            InitializeComponent();

            lstTemplates.Items.Clear();

            if (cluster != "")
            {
                try
                {
                    Scheduler scheduler = new Scheduler();
                    scheduler.Connect(cluster);

                    IStringCollection ngs = scheduler.GetJobTemplateList();
                    foreach (String ng in ngs)
                    {
                        lstTemplates.Items.Add(ng /*+ " (" + scheduler.GetNodesInNodeGroup(ng).Count().ToString() + ")" */);
                    }
                }
                catch
                {
                }
            }

            Mouse.OverrideCursor = null;
        }
Exemple #3
0
        static void Inner(IStringCollection collection, int i, ISerializer s2)
        {
            var concrete = (ListStringCollection)collection;

            while (collection.Count <= i)
            {
                concrete.Add(null);
            }
            concrete[i] = s2.FixedLengthString(null, concrete[i], StringSize);
        }
Exemple #4
0
        public static List <string> convert(IStringCollection collection)
        {
            List <string> list = new List <string>();

            foreach (string item in collection)
            {
                list.Add(item);
            }
            return(list);
        }
Exemple #5
0
        }         // FormatCommaSeparated

        // ----------------------------------------------------------------------
        /// <summary>
        /// Removes all items in the given list from this instance.
        /// </summary>
        /// <param name="items">the items to remove</param>
        public void RemoveAll(IStringCollection items)
        {
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }
            foreach (string item in items)
            {
                Remove(item);
            }
        }         // RemoveAll
Exemple #6
0
        }         // Add

        // ----------------------------------------------------------------------
        /// <summary>
        /// Adds all items in the given list to this instance.
        /// </summary>
        /// <param name="items">the items to add</param>
        public void AddAll(IStringCollection items)
        {
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }
            foreach (string item in items)
            {
                InnerList.Add(item);
            }
        }         // AddAll
Exemple #7
0
        string LoadStringCore(StringId id, string language)
        {
            language ??= Resolve <IGameplaySettings>().Language;
            var asset = _modApplier.LoadAsset(id.Id, language);

            return(asset switch
            {
                IStringCollection collection => collection.GetString(id, language),
                string s => s,
                _ => null
            });
Exemple #8
0
        }         // StringCollection

        // ----------------------------------------------------------------------
        /// <summary>
        /// Creates a new instance with all the items of the given collection.
        /// </summary>
        /// <param name="collection">the items to add. may not be null. any non-string items
        /// in this collection will be returned as null when trying to access them later.</param>
        public StringCollection(IStringCollection collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            InnerList.Capacity = collection.Count;
            foreach (string item in collection)
            {
                InnerList.Add(item);
            }
        }         // StringCollection
 // ----------------------------------------------------------------------
 /// <summary>
 /// Creates a new instance with all the items of the given collection.
 /// </summary>
 /// <param name="collection">the items to add. may not be null. any non-string items
 /// in this collection will be returned as null when trying to access them later.</param>
 public StringCollection( IStringCollection collection )
 {
     if ( collection == null )
     {
         throw new ArgumentNullException( "collection" );
     }
     InnerList.Capacity = collection.Count;
     foreach ( string item in collection )
     {
         InnerList.Add( item );
     }
 }
Exemple #10
0
        private static ISchedulerTask AddCleanupTaskToJob(ClusterSubmitterArgs clusterArgs, IScheduler scheduler, ISchedulerJob job, IDistributable distributableJob)
        {
            ISchedulerCollection taskList        = job.GetTaskList(scheduler.CreateFilterCollection(), scheduler.CreateSortCollection(), true);
            IStringCollection    dependencyTasks = scheduler.CreateStringCollection();

            if (!clusterArgs.OnlyDoCleanup)
            {
                dependencyTasks.Add(((ISchedulerTask)taskList[0]).Name);
            }
            ISchedulerTask cleanupTask = CreateCleanupTask(job, clusterArgs.ExternalRemoteDirectoryName, clusterArgs.StdErrRelativeDirName, clusterArgs.StdOutRelativeDirName, "cleanup", isFinalCleanup: true);

            Locally local = new Locally()
            {
                Cleanup         = true,
                TaskCount       = clusterArgs.TaskCount,
                Tasks           = new RangeCollection(),
                ParallelOptions = new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 1
                }
            };

            DistributeApp.Distribute distributeExe = new DistributeApp.Distribute()
            {
                Distributor   = local,
                Distributable = distributableJob
            };

            string exeName = distributableJob is DistributableWrapper ? clusterArgs.ExeName : distributeExe.GetType().Assembly.GetName().Name;

            string taskCommandLine = string.Format("{0}\\{1} {2}", clusterArgs.ExeRelativeDirectoryName, exeName, CreateTaskString(distributeExe, clusterArgs.MinimalCommandLine));

            cleanupTask.CommandLine = taskCommandLine;

            if (!clusterArgs.OnlyDoCleanup)
            {
                cleanupTask.DependsOn = dependencyTasks;
            }
            job.AddTask(cleanupTask);
            return(cleanupTask);
        }
Exemple #11
0
        /// <summary>
        /// commands are special job that contains a single task and cab be run only by administrators
        /// A command job is not scheduled (it runs immediately)
        /// </summary>
        /// <param name="commandLine">the command to execute</param>
        /// <param name="info">provides additional property values used by command. if no additional property values, set to null</param>
        /// <param name="nodes">indentify the nodes on which the command will run.</param>
        /// <param name="userName">the name of the runas user, in the form domain\username</param>
        /// <param name="password">the password for the runas user</param>
        public void CreateCommand(string commandLine, ICommandInfo info, IStringCollection nodes, string userName, string password)
        {
            if (UserPrivilege.Admin != _scheduler.GetUserPrivilege())
            {
                return;
            }

            manualReset.Reset();

            //create the command
            IRemoteCommand command = _scheduler.CreateCommand(commandLine, info, nodes);

            //subscribe to one or more events before starting the command
            command.OnCommandJobState  += OnJobStateCallback;
            command.OnCommandTaskState += OnCommandTaskStateCallback;
            command.OnCommandOutput    += OnCommandOutputCallback;
            command.OnCommandRawOutput += OnCommandRawOutputCallback;

            command.StartWithCredentials(userName, password);

            manualReset.WaitOne();
        }
Exemple #12
0
        private static IStringCollection GetNodesToUse(ClusterSubmitterArgs clusterArgs, IScheduler scheduler, ISchedulerJob job)
        {
            job.AutoCalculateMax = false;
            job.AutoCalculateMin = false;
            var availableNodes           = scheduler.GetNodeList(null, null);
            IStringCollection nodesToUse = scheduler.CreateStringCollection();
            List <string>     nodesFound = new List <string>();

            foreach (var node in availableNodes)
            {
                string nodeName = ((Microsoft.Hpc.Scheduler.SchedulerNode)node).Name;
                if (!clusterArgs.NodeExclusionList.Contains(nodeName))
                {
                    nodesToUse.Add(nodeName);
                }
                else
                {
                    nodesFound.Add(nodeName);
                }
            }
            Helper.CheckCondition(nodesFound.Count != clusterArgs.NodeExclusionList.Count, "not all nodes in exclusion list found: check for typo " + clusterArgs.NodeExclusionList);

            return(nodesToUse);
        }
Exemple #13
0
        private static ISchedulerTask CreateTask(int?taskNumber, ClusterSubmitterArgs clusterArgs, ISchedulerJob job, IDistributable distributableObj, IStringCollection nodesToUse)
        {
            Locally local = new Locally()
            {
                Cleanup   = false,
                TaskCount = clusterArgs.TaskCount,
                Tasks     = taskNumber.HasValue ? new RangeCollection(taskNumber.Value) : null,
            };

            ISchedulerTask task = job.CreateTask();

            if (nodesToUse != null)
            {
                task.RequiredNodes = nodesToUse;
            }
            if (clusterArgs.NumCoresPerTask != null)
            {
                task.MinimumNumberOfCores = clusterArgs.NumCoresPerTask.Value;
                task.MaximumNumberOfCores = clusterArgs.NumCoresPerTask.Value;
                task.MaximumNumberOfNodes = 1;
                local.ParallelOptions.MaxDegreeOfParallelism = clusterArgs.NumCoresPerTask.Value;
            }
            if (!clusterArgs.IsExclusive)
            {
                local.ParallelOptions = new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 1
                };
            }

            task.WorkDirectory = clusterArgs.ExternalRemoteDirectoryName;

            DistributeApp.Distribute distributeExe = new DistributeApp.Distribute()
            {
                Distributable = distributableObj,
                Distributor   = local
            };

            string taskArgString = CreateTaskString(distributeExe, clusterArgs.MinimalCommandLine);
            string exeName       = distributeExe.Distributable is DistributableWrapper ? clusterArgs.ExeName : distributeExe.GetType().Assembly.GetName().Name;

            string taskCommandLine = null;

            if (clusterArgs.UseMPI)
            {
                taskCommandLine = string.Format("mpiexec -n {0} {1}\\{2} {3}", clusterArgs.NumCoresPerTask, clusterArgs.ExeRelativeDirectoryName, exeName, taskArgString);
            }
            else
            {
                taskCommandLine = string.Format("{0}\\{1} {2}", clusterArgs.ExeRelativeDirectoryName, exeName, taskArgString);
            }
            task.CommandLine = taskCommandLine;

            string taskNumberAsString = taskNumber.HasValue ? taskNumber.Value.ToString() : "*";

            task.Name = Helper.CreateDelimitedString(" ", distributableObj.JobName, taskNumberAsString);
            Console.WriteLine(Resource.StdOutRelativeDirName + clusterArgs.StdOutRelativeDirName);
            task.StdErrFilePath = string.Format(@"{0}\{1}.txt", clusterArgs.StdErrRelativeDirName, taskNumberAsString);
            task.StdOutFilePath = string.Format(@"{0}\{1}.txt", clusterArgs.StdOutRelativeDirName, taskNumberAsString);

            Console.WriteLine(Resource.CreateTask, task.CommandLine.Length, task.CommandLine);
            if (task.StdErrFilePath.Length >= 160)
            {
                Console.WriteLine(Resource.Caution, task.StdErrFilePath.Length);
            }

            return(task);
        }
Exemple #14
0
        private static void SubmitViaAPI3(ClusterSubmitterArgs clusterArgs, IDistributable distributableObj)
        {
            Console.WriteLine(string.Format("Connecting to cluster {0} using API version 3 .", clusterArgs.Cluster));

            using (IScheduler scheduler = new Scheduler())
            {
                scheduler.Connect(clusterArgs.Cluster);
                ISchedulerJob job = scheduler.CreateJob();

                job.Name     = distributableObj.JobName;
                job.Priority = clusterArgs.Priority;

                if (clusterArgs.JobTemplate != null)
                {
                    Microsoft.Hpc.Scheduler.IStringCollection jobTemplates = scheduler.GetJobTemplateList();
                    string decodedJobTemplate = System.Web.HttpUtility.UrlDecode(clusterArgs.JobTemplate);
                    if (jobTemplates.Contains(decodedJobTemplate))
                    {
                        job.SetJobTemplate(decodedJobTemplate);
                    }
                    else
                    {
                        Console.WriteLine(string.Format(Resource.Job_template, decodedJobTemplate));
                        foreach (var template in jobTemplates)
                        {
                            Console.Write("'" + template + "' ");
                        }
                        Console.WriteLine(Resource.SubmitViaAPI3);
                    }
                }


                if (clusterArgs.NumCoresPerTask != null)
                {
                    clusterArgs.IsExclusive = false;
                }

                IStringCollection nodesToUse = null;

                if (clusterArgs.NodeExclusionList != null && clusterArgs.NodeExclusionList.Count > 0)
                {
                    nodesToUse = GetNodesToUse(clusterArgs, scheduler, job);
                }
                else if (clusterArgs.NodesToUseList != null && clusterArgs.NodesToUseList.Count > 0)
                {
                    nodesToUse = scheduler.CreateStringCollection();
                    foreach (string nodeName in clusterArgs.NodesToUseList)
                    {
                        nodesToUse.Add(nodeName);
                    }
                }
                else if (clusterArgs.NumCoresPerTask != null)
                {
                    job.AutoCalculateMax = true;
                    job.AutoCalculateMin = true;
                }
                else if (clusterArgs.IsExclusive)
                {
                    job.UnitType = Microsoft.Hpc.Scheduler.Properties.JobUnitType.Node;
                    if (clusterArgs.MinimumNumberOfNodes != null)
                    {
                        job.MaximumNumberOfNodes = clusterArgs.MaximumNumberOfNodes.Value;
                        job.MinimumNumberOfNodes = clusterArgs.MinimumNumberOfNodes.Value;
                    }
                }
                else if (clusterArgs.MinimumNumberOfCores != null)
                {
                    if (clusterArgs.MaximumNumberOfCores == null)
                    {
                        job.AutoCalculateMax = true;
                    }
                    else
                    {
                        job.AutoCalculateMax     = false;
                        job.MaximumNumberOfCores = clusterArgs.MaximumNumberOfCores.Value;
                    }
                    job.MaximumNumberOfCores = clusterArgs.MaximumNumberOfCores ?? Math.Max(clusterArgs.TaskCount, scheduler.GetCounters().TotalCores);
                    job.MinimumNumberOfCores = clusterArgs.MinimumNumberOfCores.Value;
                    job.AutoCalculateMin     = false;
                }
                else
                {
                    job.AutoCalculateMax = true;
                    job.AutoCalculateMin = true;
                }

                if (!clusterArgs.OnlyDoCleanup)
                {
                    if (clusterArgs.TaskRange.IsContiguous())
                    {
                        if (clusterArgs.TaskRange.LastElement > clusterArgs.TaskCount - 1)
                        {
                            clusterArgs.TaskRange = new RangeCollection(clusterArgs.TaskRange.FirstElement, clusterArgs.TaskCount - 1);
                        }
                        ISchedulerTask task = CreateTask(null, clusterArgs, job, distributableObj, nodesToUse);

                        task.Type = TaskType.ParametricSweep;

                        task.StartValue = 0;
                        task.EndValue   = clusterArgs.TaskCount - 1;

                        job.AddTask(task);
                    }
                    else
                    {
                        job.AddTasks(clusterArgs.TaskRange.Select(taskNum => CreateTask((int)taskNum, clusterArgs, job, distributableObj, nodesToUse)).ToArray());
                    }
                }
                else
                {
                    clusterArgs.Cleanup = true;
                }

                ISchedulerTask cleanupTask = null;
                if (clusterArgs.Cleanup)
                {
                    cleanupTask = AddCleanupTaskToJob(clusterArgs, scheduler, job, distributableObj);
                }

                Console.WriteLine(Resource.Submitting_job);
                scheduler.SubmitJob(job, null, null);
                clusterArgs.JobID = job.Id;
                Console.WriteLine(job.Name + Resource.submitted);
            }
        }
 // ----------------------------------------------------------------------
 /// <summary>
 /// Removes all items in the given list from this instance.
 /// </summary>
 /// <param name="items">the items to remove</param>
 public void RemoveAll( IStringCollection items )
 {
     if ( items == null )
     {
         throw new ArgumentNullException( "items" );
     }
     foreach ( string item in items )
     {
         Remove( item );
     }
 }
 // ----------------------------------------------------------------------
 /// <summary>
 /// Adds all items in the given list to this instance.
 /// </summary>
 /// <param name="items">the items to add</param>
 public void AddAll( IStringCollection items )
 {
     if ( items == null )
     {
         throw new ArgumentNullException( "items" );
     }
     foreach ( string item in items )
     {
         InnerList.Add( item );
     }
 }
Exemple #17
0
 public static bool Compare(this IStringCollection source, IStringCollection n, Func <string, string, Action <string, string>, bool> checkitem, Action <string, string> errAct)
 {
     return(Compare <string>(source, n, checkitem, errAct));
 }
Exemple #18
0
        //for best results, run this sample code in queued scheduling mode
        static void Main(string[] args)
        {
            string clusterName = Environment.GetEnvironmentVariable("CCP_SCHEDULER");

            using (IScheduler scheduler = new Scheduler())
            {
                Console.WriteLine("Connecting to {0}", clusterName);
                scheduler.Connect(clusterName);

                //assume you have two nodegroups, NodeGroup1 and NodeGroup2
                IStringCollection nodeGroup1 = scheduler.GetNodesInNodeGroup("NodeGroup1");
                IStringCollection nodeGroup2 = scheduler.GetNodesInNodeGroup("NodeGroup2");
                if (nodeGroup1.Count == 0 || nodeGroup2.Count == 0)
                {
                    Console.WriteLine("Node groups are not set up correctly");
                    return;
                }

                //and nodes in NodeGroup2 are not in NodeGroup1, and vise versa.
                string nodeToMove = "";
                foreach (string node in nodeGroup2)
                {
                    if (!nodeGroup1.Contains(node))
                    {
                        nodeToMove = node;
                        break;
                    }
                }
                if (string.IsNullOrEmpty(nodeToMove))
                {
                    Console.WriteLine("No eligible nodes to move");
                    return;
                }

                //create a job to run on NodeGroup1
                ISchedulerJob job = scheduler.CreateJob();
                job.NodeGroups.Add("NodeGroup1");
                //Set unit type to node, but let it autocalculate resources
                job.UnitType = JobUnitType.Node;

                ISchedulerTask task = job.CreateTask();
                task.CommandLine = "ver";
                task.Type        = TaskType.Service;
                job.AddTask(task);

                job.OnTaskState += new EventHandler <TaskStateEventArg>(job_OnTaskState);
                Console.WriteLine("Submitting job on NodeGroup1");
                scheduler.SubmitJob(job, null, null);
                Console.WriteLine("Job {0} Submitted", job.Id);

                //wait for the job to start running
                running.WaitOne();

                job.Refresh();
                int allocationCount = job.AllocatedNodes.Count;
                Console.WriteLine("Number of allocated nodes: {0}", allocationCount);

                //Check the status of NodeGroup1 nodes
                int idleCores = 0;
                foreach (string nodename in nodeGroup1)
                {
                    ISchedulerNode node = scheduler.OpenNodeByName(nodename);
                    idleCores += node.GetCounters().IdleCoreCount;
                }

                //There are no more idle cores remaining in this node group
                //So we'll place one of the nodes from NodeGroup2 allow the job to grow
                if (idleCores == 0)
                {
                    running.Reset();

                    //Changing nodegroups is available through the UI or PowerShell
                    string powershellScript = String.Format("add-pssnapin microsoft.hpc; " +
                                                            "add-hpcgroup -scheduler {0} -name {1} -nodename {2}",
                                                            clusterName, "NodeGroup1", nodeToMove);
                    using (PowerShell ps = PowerShell.Create())
                    {
                        ps.AddScript(powershellScript, true);
                        ps.Invoke();
                    }

                    running.WaitOne();
                    Console.WriteLine("(Waiting 5 seconds for job to update the scheduler)");
                    Thread.Sleep(5 * 1000);
                    job.Refresh();
                    int newAllocationCount = job.AllocatedNodes.Count;

                    //verify that job has grown
                    if (newAllocationCount > allocationCount)
                    {
                        Console.WriteLine("Job has grown to {0} nodes", newAllocationCount);
                    }
                }
                else
                {
                    Console.WriteLine("There are still idle cores in the nodegroup");
                }
            }
        }
Exemple #19
0
 public static bool Compare(this IStringCollection source, IStringCollection n)
 {
     return Compare<string>(source,n);
 }
Exemple #20
0
 public static bool Compare(this IStringCollection source, IStringCollection n, Func<string, string, Action<string, string>, bool> checkitem, Action<string, string> errAct)
 {
     return Compare<string>(source,n,checkitem,errAct);
 }
Exemple #21
0
 public Microsoft.Hpc.Scheduler.IRemoteCommand CreateCommand(string commandLine, ICommandInfo info, IStringCollection nodes, bool redirectOutput)
 {
     lock (SyncRoot) { return(Instance.CreateCommand(commandLine, info, nodes, redirectOutput)); }
 }
Exemple #22
0
 public static bool Compare(this IStringCollection source, IStringCollection n)
 {
     return(Compare <string>(source, n));
 }