/// <summary> /// Method to run tasks specifying the task name and count /// </summary> /// <param name="tasksToRun">name of task</param> /// <param name="taskCount">count of task</param> public override void RunTasks(RangeCollection tasksToRun, long taskCount) { var allTheWorkQuery = InputFile.ReadEachLine(); var myWorkAndAnIndex = SpecialFunctions.DivideWork(allTheWorkQuery, tasksToRun, taskCount, 1, new RangeCollection()); double myTotal = double.NaN; bool isFirst = true; foreach (var numberAndIndex in myWorkAndAnIndex) { double number = double.Parse(numberAndIndex.Key, (IFormatProvider)null); Thread.Sleep(SleepMilliseconds); //make the work take longer if (isFirst) { myTotal = number; isFirst = false; } else { myTotal = Operator.Aggregate(myTotal, number); } } if (!isFirst) // make sure we actually did something. { var myUniqueResultFileName = GetFileTaskFileName(tasksToRun.ToString()); using (TextWriter writer = File.CreateText(myUniqueResultFileName)) { writer.WriteLine(myTotal); } } }
/// <summary> /// Runs the tasks /// </summary> /// <param name="tasksToRun">number of tasks to be ran in a range collection</param> /// <param name="taskCount">task count</param> public override void RunTasks(RangeCollection tasksToRun, long taskCount) { ISequenceParser parser = SequenceParsers.FindParserByFileName(InputFile.FullName); var allTheWorkQuery = parser.Parse(); var myWorkAndAnIndex = SpecialFunctions.DivideWork(allTheWorkQuery, tasksToRun, taskCount, 1, new RangeCollection()); var myUniqueResultFileName = GetFileTaskFileName(tasksToRun.ToString()); float gcCount = 0; long seqLength = 0; using (TextWriter writer = File.CreateText(myUniqueResultFileName)) { // loop all sequences in current task foreach (var numberAndIndex in myWorkAndAnIndex) { writer.WriteLine(">" + numberAndIndex.Key.ID); foreach (byte val in numberAndIndex.Key) { seqLength++; switch (val) { case (byte)'G': case (byte)'g': case (byte)'C': case (byte)'c': gcCount++; break; } } if (gcCount > 0) { writer.Write(((gcCount / (float)seqLength) * 100) + "%"); } else { writer.Write(gcCount + "%"); } seqLength = 0; gcCount = 0; writer.WriteLine(); } } }
/// <summary> /// Runs the tasks /// </summary> /// <param name="tasksToRun">number of tasks to be ran in a range collection</param> /// <param name="taskCount">task count</param> public override void RunTasks(RangeCollection tasksToRun, long taskCount) { ISequenceParser parser = SequenceParsers.FindParserByFileName(InputFile.FullName); var allTheWorkQuery = parser.Parse(InputFile.FullName); var myWorkAndAnIndex = SpecialFunctions.DivideWork(allTheWorkQuery, tasksToRun, taskCount, 1, new RangeCollection()); var myUniqueResultFileName = GetFileTaskFileName(tasksToRun.ToString()); float gcCount = 0; long seqLength = 0; using (TextWriter writer = File.CreateText(myUniqueResultFileName)) { // loop all sequences in current task foreach (var numberAndIndex in myWorkAndAnIndex) { writer.WriteLine(">" + numberAndIndex.Key.ID); foreach (byte val in numberAndIndex.Key) { seqLength++; switch (val) { case (byte)'G': case (byte)'g': case (byte)'C': case (byte)'c': gcCount++; break; } } if (gcCount > 0) writer.Write(((gcCount / (float)seqLength) * 100) + "%"); else writer.Write(gcCount + "%"); seqLength = 0; gcCount = 0; writer.WriteLine(); } } }
static void Main(string[] args) { try { // before using the ArgCollection class, let the DigipedeClient grab its args. DigipedeClient client = new DigipedeClient(); args = client.ProcessArguments(args, true); ArgCollection argCollection = ArgCollection.GetInstance(args); // show help, if requested if (argCollection.ExtractOptionalFlag("help")) { Console.WriteLine(""); Console.WriteLine(UsageMessage); Console.WriteLine(HelpMessage); return; } // fail if the DigipedeClient doesn't have the args SpecialFunctions.CheckCondition(client.IsInitialized, "Digipede Client didn't initialize."); string keepTestName = argCollection.ExtractOptional("keepTest", "AlwaysKeep"); string skipRowIndexFileNameOrNull = argCollection.ExtractOptional <string>("skipRowIndexFile", null); string optimizerName = argCollection.ExtractOptional("optimizer", "BrentThenGrid"); argCollection.CheckNoMoreOptions(); int pieceCount = argCollection.ExtractNext <int>("pieceCount"); //int taskPerJobCount = argCollection.ExtractNext<int>("taskPerJobCount"); -- we're not using this -- keep it in case we want to put it back string treeFileName = argCollection.ExtractNext <string>("treeFile"); string predictorFileName = argCollection.ExtractNext <string>("predictorFile"); string targetFileName = argCollection.ExtractNext <string>("targetFile"); string leafDistributionName = argCollection.ExtractNext <string>("leafDistribution"); string nullDataGeneratorName = argCollection.ExtractNext <string>("nullDataGenerator"); string niceName = argCollection.ExtractNext <string>("niceName"); string outputDirectoryName = argCollection.ExtractNext <string>("outputDirectory"); RangeCollection nullIndexRangeCollection = argCollection.ExtractNext <RangeCollection>("nullIndexRange"); SpecialFunctions.CheckCondition(nullIndexRangeCollection.IsBetween(-1, int.MaxValue), "nullIndex must be at least -1"); argCollection.CheckThatEmpty(); Directory.CreateDirectory(outputDirectoryName); // Define a JobTemplate for PhyloD. JobTemplate jobTemplate = CreateJobTemplate(); // Require 32 bit (ensures we use WOW64 on 64-bit machines) since SpecialFunctions.dll built for x86. jobTemplate.Control.UseWow64On64Bit = true; // allow task failures (all but one failure will result in job success) jobTemplate.JobDefaults.MaxFailures = pieceCount - 1; // allow multiple concurrent tasks (one for each core); each isolated in its own process. jobTemplate.Control.Concurrency = ApplicationConcurrency.MultiplePerCore; jobTemplate.Control.ProcessHostingOptions = HostingOptions.ManySingleUse; // create a Job based on that JobTemplate Job job = jobTemplate.NewJob(); // add job-specific data / files FileDefCollection fileDefs = job.FileDefs; // files Utility.GetNamedFileDef(fileDefs, Constants.TreeFileDefName).RemoteName = treeFileName; Utility.GetNamedFileDef(fileDefs, Constants.PredictorFileDefName).RemoteName = predictorFileName; Utility.GetNamedFileDef(fileDefs, Constants.TargetFileDefName).RemoteName = targetFileName; // skipRowIndex file is more complicated because it may not exist, but the JobTemplate requires it. FileDef fileDef = Utility.GetNamedFileDef(fileDefs, Constants.SkipRowIndexFileDefName); if (skipRowIndexFileNameOrNull == null || skipRowIndexFileNameOrNull == "null") { // stream an empty file fileDef.Stream = new MemoryStream(0); } else { // stream the actual file fileDef.LocalName = skipRowIndexFileNameOrNull; } // Create the tasks for the template for (int pieceIndex = 0; pieceIndex < pieceCount; pieceIndex++) { // Create a Task for this piece Task task = job.NewTask(); // Create an InputData object to encapsulate all input data in one place InputData inputData = new InputData(optimizerName, keepTestName, leafDistributionName, nullDataGeneratorName, niceName, outputDirectoryName, pieceIndex, pieceCount, nullIndexRangeCollection.ToString()); // create a Worker for this task task.Worker = new PhyloDWorker(inputData); } // Wire events to catch result data. Note that retrieving data isn't necessary here -- // data can be requested in a server call from another process. job.TaskCompleted += job_TaskCompleted; // Write an event to catch any monitoring errors client.MonitoringError += client_MonitoringError; // submit the job SubmissionResult sr = client.SubmitJob(jobTemplate, job); Console.WriteLine("Submitted job {0} with {1} tasks.", sr.JobId, job.Tasks.Count); // wait for the result JobStatusSummary jss = client.WaitForJobWithStatus(sr.JobId); Console.WriteLine("Job finished with status of {0}", jss.Status); } catch (Exception exception) { Console.WriteLine(""); Console.WriteLine(exception.Message); if (exception.InnerException != null) { Console.WriteLine(exception.InnerException.Message); } Console.WriteLine(""); Console.WriteLine(UsageMessage); throw; } }
/// <summary> /// Method to run tasks specifying the task name and count /// </summary> /// <param name="tasksToRun">name of task</param> /// <param name="taskCount">count of task</param> public override void RunTasks(RangeCollection tasksToRun, long taskCount) { var allTheWorkQuery = InputFile.ReadEachLine(); var myWorkAndAnIndex = SpecialFunctions.DivideWork(allTheWorkQuery, tasksToRun, taskCount, 1, new RangeCollection()); double myTotal = double.NaN; bool isFirst = true; foreach (var numberAndIndex in myWorkAndAnIndex) { double number = double.Parse(numberAndIndex.Key, (IFormatProvider)null); Thread.Sleep(SleepMilliseconds); //make the work take longer if (isFirst) { myTotal = number; isFirst = false; } else { myTotal = Operator.Aggregate(myTotal, number); } } if (!isFirst) // make sure we actually did something. { var myUniqueResultFileName = GetFileTaskFileName(tasksToRun.ToString()); using (TextWriter writer = File.CreateText(myUniqueResultFileName)) { writer.WriteLine(myTotal); } } }
public override string GetSkipRangeCollection() { return(RowIndexRangeCollection.ToString()); }