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