示例#1
0
        public static void SubmitAndWait(ClusterSubmitterArgs clusterArgs, IDistributable distributableObj, int maxSubmitAfterTasksFail = 0)
        {
            using (ParallelOptionsScope.Suspend())
            {
                int numberOfTries = 0;

retry:

                Submit(clusterArgs, distributableObj);

                JobWaitingParams jobWaitingParams = WaitForJobInternal(clusterArgs);

                if (jobWaitingParams.JobState == v2008R2.Properties.JobState.Canceled)
                {
                    throw new Exception("Job canceled.");
                }
                else if (jobWaitingParams.JobState == v2008R2.Properties.JobState.Failed)
                {
                    if (numberOfTries < maxSubmitAfterTasksFail)
                    {
                        ++numberOfTries;
                        Console.WriteLine("Job failed, trying again...");
                        goto retry;
                    }
                    throw new Exception("Job failed.");
                }
                //HpcLib.HpcLib.CopyFiles(new List<String> { "" }, _remoteTaskOutDir, TASK_OUT_DIR);
            }
        }
示例#2
0
        public bool Refresh()
        {
            bool changed = false;
            ISchedulerCounters counters;

            using (ParallelOptionsScope.Suspend())
            {
                if (Connect() && null != (counters = GetCounters()))
                {
                    changed =
                        BusyCores != counters.BusyCores ||
                        IdleCores != counters.IdleCores ||
                        QueuedTasks != counters.QueuedTasks;


                    BusyCores   = counters.BusyCores;
                    IdleCores   = counters.IdleCores;
                    QueuedTasks = counters.QueuedTasks;
                }
                else
                {
                    changed = BusyCores != -1;

                    BusyCores   = -1;
                    IdleCores   = -1;
                    QueuedTasks = -1;
                }
            }
            return(changed);
        }
示例#3
0
        public Matrix <string, string, double> Normalize(Matrix <string, string, double> input, ParallelOptions parallelOptions)
        {
            Matrix <string, string, double> output = null;

            using (ParallelOptionsScope.Create(parallelOptions))
            {
                output = Normalize(input);
            }
            return(input);
        }
示例#4
0
        public void NormalizeInPlace(ref ShoMatrix matrix, ParallelOptions parallelOptions)
        {
            var matrix2 = matrix;

            using (ParallelOptionsScope.Create(parallelOptions))
            {
                NormalizeInPlace(ref matrix2);
            }
            matrix = matrix2;
        }
示例#5
0
        public Matrix <string, string, double> ToKernel(Matrix <string, string, double> unnormalizedInput, ParallelOptions parallelOptions, int?cidInBatchCountOrNull = null)
        {
            Matrix <string, string, double> kernel = null;

            using (ParallelOptionsScope.Create(parallelOptions))
            {
                kernel = ToKernel(unnormalizedInput, cidInBatchCountOrNull);
            }
            return(kernel);
        }
示例#6
0
        private static void SubmitInternal(ClusterSubmitterArgs clusterArgs, IDistributable distributableObj)
        {
            lock (_submitterLockObj)  // for now, just let one thread submit at a time.
            {
                if (clusterArgs.Archive != null)
                {
                    MBT.Escience.FileUtils.ArchiveExes(clusterArgs.Archive);
                }

                //ArgumentCollection argsToUse = (ArgumentCollection)applicationArgs.Clone();

                CopyExes(clusterArgs);

                clusterArgs.StdErrDirName = CreateUniqueDirectory(clusterArgs.ExternalRemoteDirectoryName, "Stderr", clusterArgs.Name);
                clusterArgs.StdOutDirName = CreateUniqueDirectory(clusterArgs.ExternalRemoteDirectoryName, "Stdout", clusterArgs.Name);


                if (clusterArgs.CopyInputFiles.Count > 0)
                {
                    CopyInputFiles(clusterArgs.CopyInputFiles, clusterArgs.ExternalRemoteDirectoryName);
                }

                using (ParallelOptionsScope.Suspend())
                {
                    switch (clusterArgs.Version)
                    {
                    case 1:
                        SubmitViaAPI1(clusterArgs, distributableObj);
                        break;

                    case 2:
                        Console.Error.WriteLine("Api2 and 3 are the same. Submitting via Api3.");
                        SubmitViaAPI3(clusterArgs, distributableObj);
                        break;

                    case 3:
                        SubmitViaAPI3(clusterArgs, distributableObj);
                        break;

                    default:
                        throw new NotSupportedException(string.Format("Cluster version {0} is not supported.", clusterArgs.Version));
                    }
                }
                Console.WriteLine("Processed job to cluster {0} with path {1}", clusterArgs.Cluster, clusterArgs.ExternalRemoteDirectoryName);


                Console.WriteLine("Writing log file");
                HpcLibSettings.TryWriteToLog(clusterArgs);
                Console.WriteLine("Writing log entry to cluster directory");
                HpcLibSettings.WriteLogEntryToClusterDirectory(clusterArgs);
                Console.WriteLine("Done");
            }
            return;
        }
 public void ValidateCreateForThreadCount()
 {
     using (ParallelOptionsScope parallel = ParallelOptionsScope.Create(Constants.ParallelProcess))
     {
         Assert.IsNotNull(parallel);
         Assert.AreEqual(Constants.ParallelProcess, ParallelOptionsScope.Current.MaxDegreeOfParallelism);
         Assert.IsTrue(ParallelOptionsScope.Exists);
     }
     ApplicationLog.WriteLine(string.Concat(
                                  "ParallelOptionsScope BVT: Validation of Create method for thread count completed successfully."));
 }
 public void ValidateCreateFullyParallel()
 {
     using (ParallelOptionsScope scope = ParallelOptionsScope.CreateFullyParallel())
     {
         Assert.IsNotNull(scope);
         Assert.AreEqual(Environment.ProcessorCount, ParallelOptionsScope.Current.MaxDegreeOfParallelism);
         Assert.IsTrue(ParallelOptionsScope.Exists);
     }
     ApplicationLog.WriteLine(string.Concat(
                                  "ParallelOptionsScope BVT: Validation of CreateFullyParallel method completed successfully."));
 }
 public void ValidateCreateSingleThreaded()
 {
     using (ParallelOptionsScope scope = ParallelOptionsScope.CreateSingleThreaded())
     {
         Assert.IsNotNull(scope);
         Assert.AreEqual(Constants.SerialProcess, ParallelOptionsScope.Current.MaxDegreeOfParallelism);
         Assert.IsTrue(ParallelOptionsScope.Exists);
     }
     ApplicationLog.WriteLine(string.Concat(
                                  "ParallelOptionsScope BVT: Validation of CreateSingleThreaded method completed successfully."));
 }
示例#10
0
        /// <summary>
        /// Runs Tasks locally on distributableObject.
        /// </summary>
        /// <param name="distributableObject">The object that will run the tasks.</param>
        public void Distribute(IDistributable distributableObject)
        {
            using (ParallelOptionsScope.Create(ParallelOptions))
            {
                distributableObject.RunTasks(Tasks, TaskCount);

                if (Cleanup)
                {
                    distributableObject.Cleanup(TaskCount);
                }
            }
        }
示例#11
0
        public void TestParallelQueryExtensionsWithParallelOptionsScope()
        {
            List <ClusterStatus> clusterStatusList = HpcLibSettings.ActiveClusters.Where(name => !name.Equals("msr-gcb-n10", StringComparison.CurrentCultureIgnoreCase))
                                                     .Select(clusterName => new ClusterStatus(clusterName)).ToList();

            List <ClusterStatus> expected = clusterStatusList;

            using (ParallelOptionsScope.CreateFullyParallel())
            {
                clusterStatusList.AsParallel().WithParallelOptionsScope();
            }

            Assert.AreSame(expected, clusterStatusList);
        }
        public void ValidateCDispose()
        {
            ParallelOptionsScope scope = ParallelOptionsScope.Create(Constants.ParallelProcess);

            Assert.IsNotNull(scope);
            Assert.AreEqual(Constants.ParallelProcess, ParallelOptionsScope.Current.MaxDegreeOfParallelism);
            Assert.IsTrue(ParallelOptionsScope.Exists);

            scope.Dispose();
            Assert.IsFalse(ParallelOptionsScope.Exists);

            ApplicationLog.WriteLine(string.Concat(
                                         "ParallelOptionsScope BVT: Validation of Dispose method completed successfully."));
        }
        public void ValidateCreateForParallelOptions()
        {
            ParallelOptions parallel = new ParallelOptions();

            parallel.MaxDegreeOfParallelism = Constants.SerialProcess;

            ParallelOptionsScope scope = ParallelOptionsScope.Create(parallel);

            Assert.IsNotNull(scope);
            Assert.AreEqual(Constants.SerialProcess, ParallelOptionsScope.Current.MaxDegreeOfParallelism);
            Assert.IsTrue(ParallelOptionsScope.Exists);

            ApplicationLog.WriteLine(string.Concat(
                                         "ParallelOptionsScope BVT: Validation of Create method for ParallelOptions completed successfully."));
        }
示例#14
0
        private bool Connect()
        {
            if (_scheduler != null)
            {
                return(true);
            }

            bool connected = false;

            using (ParallelOptionsScope.Suspend())
            {
                connected = HpcLib.TryConnect(Cluster, out _scheduler);
            }

            return(connected);
        }
 public void ValidateParallelOptionsScopeProperties()
 {
     using (ParallelOptionsScope.Create(Environment.ProcessorCount))
     {
         Assert.IsTrue(ParallelOptionsScope.Exists);
         ParallelOptions parallel = ParallelOptionsScope.Current;
         Assert.IsNotNull(parallel);
         Assert.IsNotNull(parallel.CancellationToken);
         Assert.AreEqual(Constants.SerialProcess, parallel.TaskScheduler.Id);
         Assert.AreEqual(Environment.ProcessorCount, parallel.MaxDegreeOfParallelism);
         Assert.AreEqual(1, ParallelOptionsScope.SingleThreadedOptions.MaxDegreeOfParallelism);
         Assert.AreEqual(
             Environment.ProcessorCount,
             ParallelOptionsScope.FullyParallelOptions.MaxDegreeOfParallelism);
     }
     ApplicationLog.WriteLine("Trace BVT: Validation of all ParallelOptionsScope properties completed successfully.");
 }
示例#16
0
        /// <summary>
        /// Runs Tasks locally on distributableObject.
        /// </summary>
        /// <param name="distributableObject">The object that will run the tasks.</param>
        public void Distribute(IDistributable distributableObject)
        {
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                distributableObject.Cancel();
                Environment.ExitCode = -1073741510; // exit by control break
            };

            using (ParallelOptionsScope.Create(ParallelOptions))
            {
                distributableObject.RunTasks(Tasks, TaskCount);

                if (Cleanup)
                {
                    distributableObject.Cleanup(TaskCount);
                }
            }
        }