private static void Execute() { Thread.CurrentThread.Name = "Main"; int loopend = DesiredChunks.Count; List <Task> tasks = new List <Task>(); for (int i = 0; i < loopend; i++) { int a = DesiredChunks[i][0]; int b = DesiredChunks[i][1]; Task task = new Task(() => { new SlemenikDownloader().DownloadData(a, b); }); Console.WriteLine(Thread.CurrentThread.Name); tasks.Add(task); } // partition to batch size of 8 for 8 core processors. List <List <Task> > batches = MyCollections.Partition <Task>(tasks.ToArray(), 8).ToList(); foreach (var batch in batches) { Console.WriteLine("Batch start"); foreach (Task t in batch) { t.Start(); } foreach (Task t in batch) { t.Wait(); } } Console.WriteLine("Task finished"); }
static void Main(string[] args) { List <List <int> > chunks = GConfig.GET_PICKED_CHUNKS(); List <List <int> > list = new List <List <int> >(); string[] augs = Directory.GetFiles(Path.Combine(GConfig.WORKSPACE_DIR, GConfig.AUGMENTATION_SUBDIR)); foreach (string s in augs) { if (File.Exists(s)) { Regex rx = new Regex(@"[0-9]{3}[_]{1}[0-9]{2,3}", RegexOptions.Compiled | RegexOptions.IgnoreCase); Match matches = rx.Match(s); string chunk = matches.Value; string[] parts = chunk.Split("_"); List <int> element = new List <int>(); element.Add(int.Parse(parts[0])); element.Add(int.Parse(parts[1])); list.Add(element); } } List <List <int> > filteredChunks = new List <List <int> >(); foreach (List <int> chunk in chunks) { bool kurac = true; for (int i = 0; i < list.Count; i++) { if (list[i][0] == chunk[0] && list[i][1] == chunk[1]) { kurac = false; break; } } if (!kurac) { continue; } filteredChunks.Add(chunk); } chunks = filteredChunks; List <Task> tasks = new List <Task>(); Console.WriteLine($"Processing {chunks.Count} chunks."); foreach (List <int> chunk in chunks) { Program prg = new Program(); prg.TxtDatasetFileName = chunk[0] + "_" + chunk[1] + ".txt"; prg.DmrFileName = $"pcd{chunk[0]}_{chunk[1]}"; prg.SamplesFileName = $"{chunk[0]}_{chunk[1]}augmentation_result.txt"; Task t = new Task((exec_env) => { try { Program exec_env_prg = (Program)exec_env; Tools.Time(exec_env_prg.UnfilteredSampleObjects); Tools.Time(exec_env_prg.FilterOverlappingObjects); Tools.Time(exec_env_prg.FilterUndergroundPoints); exec_env_prg.samples = exec_env_prg.samples.Take(GConfig.ObjectsToAdd).ToList(); Tools.Time(exec_env_prg.ComputeRbnnMinVals); Tools.Time(exec_env_prg.SaveResults); } catch (Exception ex) { Console.WriteLine("Failed executing " + ((Program)exec_env).TxtDatasetFileName + ex.StackTrace + ex.Message); } }, prg); tasks.Add(t); } List <List <Task> > batches = MyCollections.Partition <Task>(tasks.ToArray(), 5).ToList(); foreach (var batch in batches) { foreach (Task t in batch) { t.Start(); } foreach (Task t in batch) { t.Wait(); } } Console.WriteLine("Program finished. Press the ANY key to continue..."); Console.ReadLine(); }
static void Main(string[] args) { string[] filepaths = Directory.GetFiles(lazfolder, "*.laz"); string[] dmrpaths = Directory.GetFiles(dmrfolder); List <Task> tasks = new List <Task>(); foreach (string path in filepaths) { string current_path = path; Task task = new Task(() => { CoreProcedure procedure = new CoreProcedure(current_path); procedure.PreprocessLaz(); }); tasks.Add(task); } // partition to batch size of 8 for 8 core processors. List <List <Task> > batches = MyCollections.Partition <Task>(tasks.ToArray(), 8).ToList(); foreach (var batch in batches) { foreach (Task t in batch) { t.Start(); } foreach (Task t in batch) { t.Wait(); } foreach (Task t in batch) { t.Dispose(); } } tasks = new List <Task>(); foreach (string dmr in dmrpaths) { if (dmr.Contains("pcd")) { continue; } string current_dmr = dmr; Task task = new Task((object dmr_state) => { CoreProcedure procedure = new CoreProcedure((string)dmr_state); procedure.Dmr2Pcd(); }, current_dmr); tasks.Add(task); } batches = MyCollections.Partition <Task>(tasks.ToArray(), 8).ToList(); foreach (var batch in batches) { foreach (Task t in batch) { t.Start(); } foreach (Task t in batch) { t.Wait(); } } }