/// <summary> /// Given a check matrix <c>H</c>, compute matrices <c>S</c>, <c>M</c>, and a random permutation <c>P</c> such that /// <c>S*H*P = (Id|M)</c>. Return <c>S^-1</c>, <c>M</c>, and the systematic form of H /// </summary> /// /// <param name="H">The check matrix</param> /// <param name="SecRnd">The source of randomness</param> /// /// <returns>Returns the tuple <c>(S^-1, M, P)</c></returns> public static MaMaPe ComputeSystematicForm(GF2Matrix H, IRandom SecRnd) { MaMaPe mmp = null; object lockobj = new object(); if (ParallelUtils.IsParallel) { Func <bool> condFn = () => mmp == null; ParallelUtils.Loop(new ParallelOptions(), condFn, loopState => { MaMaPe mmp2 = GetMMP(H, SecRnd); if (mmp2 != null) { lock (mmp2) { mmp = mmp2; } } }); } else { do { mmp = GetMMP(H, SecRnd); }while (mmp == null); } return(mmp); }
private void ProcessLoadingQueue() { if (_loadQueue.Count > 0) // Task.Run(() => { ParallelUtils.While(() => _loadQueue.Count > 0 && (Surface != null && !Surface.Disposing && !Surface.IsDisposed), ProcessItem); }//); }
private void ProcessLoadQueueThread() { while (Surface != null && !Surface.Disposing && !Surface.IsDisposed) { ParallelUtils.While(() => concurrentDownloads < 6 && _loadQueue.Count > 0 && (Surface != null && !Surface.Disposing && !Surface.IsDisposed), ProcessItem); Thread.Sleep(50); } }
private void Run(double cdr, double cpr, AssetOverrideSetting assetOverrideSetting = null) { var folderInfo = CopyTemporaryModel(); m_staticAnalysisResult = NancyUtils.RunStaticResultByPath(cdr.ToString(), cpr.ToString(), folderInfo.YmlFolder, folderInfo.DsFolder, assetOverrideSetting); ParallelUtils.Start(() => Directory.Delete(folderInfo.YmlFolder, true)); }
public bool Load(string topLevelFolder, bool forceReload = false) { if (String.IsNullOrWhiteSpace(topLevelFolder)) { _logger.Error("3959", "The provided top level folder is either null or only whitespace."); return(false); } if (!Directory.Exists(topLevelFolder)) { _logger.Error("4089", $"The specified folder does not exist: {topLevelFolder}."); return(false); } // Skip reloading the cache if nothing on the file system has change and // the user is not asking to force a reload. // if (!WorkspaceHasChangedSinceLastLoad && !forceReload) { return(true); } // Reset all cached state // Reset(); // // Now start the loading process // WorkspaceHasChangedSinceLastLoad = false; // Prepare the file watchers on our new set of files // SetupFileSystemWatchers(topLevelFolder); try { // Translate the xml to elements and add them to the cache. // if (!XmlToGraphTranslator.TranslateToCache(_logger, topLevelFolder, _elementsByIdCollection)) { return(false); } // In parallel, apply the Resolve method to each of the cached elements. // ParallelUtils.ForEach(_logger, _elementsByIdCollection, Resolve); } catch (Exception e) { _logger.Error("9494", $"While loading the graph cache the following execption was thrown: {e.Message}"); return(false); } return(true); }
public void BeginExecuteAndAddTest() { int functions = 20; Func <int>[] fn = new Func <int> [functions]; for (int i = 0; i < fn.Length; ++i) { fn[i] = Dummy; } int res = ParallelUtils.BeginExecuteAndAdd((a, b) => a + b, fn); int expected = Dummy() * functions; Assert.AreEqual(expected, res); }
public override IPositionEvaluationBatch EvaluateIntoBuffers(IEncodedPositionBatchFlat positions, bool retrieveSupplementalResults = false) { if (positions.Moves == null) { throw new Exception("NNEvaluatorLC0NNEvaluator requires Moves to be provided"); } if (retrieveSupplementalResults) { throw new NotImplementedException("retrieveSupplementalResults not supported"); } Evaluator.EvaluateNN(positions, positions.Positions); const int NUM_POSITIONS_PER_THREAD = 40; ParallelOptions parallelOptions = ParallelUtils.ParallelOptions(positions.NumPos, NUM_POSITIONS_PER_THREAD); Parallel.For(0, positions.NumPos, parallelOptions, PreparePosition); return(new PositionEvaluationBatch(IsWDL, HasM, positions.NumPos, policies, w, l, m, null, new TimingStats()));; }
private DealModelFolerInfo CopyTemporaryModel() { var srcDsFolder = m_datasetPath; var temporaryFolder = CommUtils.CreateTemporaryFolder(Platform.UserName); var temporaryDsFolder = CommUtils.CreateFolder(temporaryFolder, m_asOfDate); ParallelUtils.StartUntilFinish( () => FileUtils.Copy(m_ymlPath, Path.Combine(temporaryFolder, "script.yml")), () => FileUtils.Copy(Path.Combine(srcDsFolder, "collateral.csv"), Path.Combine(temporaryDsFolder, "collateral.csv")), () => FileUtils.Copy(Path.Combine(srcDsFolder, "AmortizationSchedule.csv"), Path.Combine(temporaryDsFolder, "AmortizationSchedule.csv"), false), () => FileUtils.Copy(Path.Combine(srcDsFolder, "PromisedCashflow.csv"), Path.Combine(temporaryDsFolder, "PromisedCashflow.csv"), false), () => FileUtils.Copy(Path.Combine(srcDsFolder, "Reinvestment.csv"), Path.Combine(temporaryDsFolder, "Reinvestment.csv"), false), () => FileUtils.Copy(Path.Combine(srcDsFolder, "PastVariables.csv"), Path.Combine(temporaryDsFolder, "PastVariables.csv"), false), () => FileUtils.Copy(Path.Combine(srcDsFolder, "CurrentVariables.csv"), Path.Combine(temporaryDsFolder, "CurrentVariables.csv"), false), () => FileUtils.Copy(Path.Combine(srcDsFolder, "FutureVariables.csv"), Path.Combine(temporaryDsFolder, "FutureVariables.csv"), false), () => FileUtils.Copy(Path.Combine(srcDsFolder, "CombinedVariables.csv"), Path.Combine(temporaryDsFolder, "CombinedVariables.csv")) ); return(new DealModelFolerInfo(temporaryFolder, temporaryDsFolder)); }
public static String Mine(Block lastBlock) { Staticnonce = 0L; String hash = CreateHash(lastBlock, Staticnonce); DateTime timestamp = DateTime.UtcNow; int difficulty = lastBlock.difficulty; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); ThreadPool.SetMaxThreads(0, 10); hash = CreateHash(lastBlock, 0); Func <bool> whileCondFn = () => !hash.StartsWith(string.Concat(Enumerable.Repeat("0", difficulty))); ParallelUtils.While(whileCondFn, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, (ParallelLoopState) => { lock (_object) { difficulty = AdjustDifficulty(lastBlock, timestamp, 3); timestamp = DateTime.UtcNow; Staticnonce += 1; hash = CreateHash(lastBlock, Staticnonce);; System.Diagnostics.Debug.WriteLine(hash + Staticnonce); System.Diagnostics.Debug.WriteLine(difficulty); //Console.WriteLine(whileCondFn()); if (hash.StartsWith(string.Concat(Enumerable.Repeat("0", difficulty)))) { Console.WriteLine("fdasfjkla;jsdfads" + hash); Console.WriteLine(Staticnonce); ActualHash = hash; ActualDiff = difficulty; //_Form1.richTextBox1.Invoke(new Action(() => _Form1.richTextBox1.Text += hash)); //BlockchainApp._Form1.update(hash); ActualNonce = Staticnonce; ParallelLoopState.Stop(); } } }); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; // Format and display the TimeSpan value. string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine("RunTime " + elapsedTime); blocktime = elapsedTime; nonce = ActualNonce; return(ActualHash); }
public async Task FetchOrders(List <int> regions) { OrdersBag = new ConcurrentBag <List <MarketOrder> >(); //new List<MarketOrder>(3000000); var handler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; var pageRequests = new ConcurrentQueue <string>(); foreach (var regionId in regions) { pageRequests.Enqueue($"https://crest-tq.eveonline.com/market/{regionId}/orders/all/?page=1"); } // EVE crest allows 150 requests per second // ignoring the burst allowance of 400 for now await Task.Run(() => { using (var client = new HttpClient(handler)) using (var rateGate = new RateGate(150, TimeSpan.FromSeconds(1))) { ParallelUtils.ParallelWhileNotEmpty(pageRequests, (item, adder) => { rateGate.WaitToProceed(); var result = client.GetAsync(item).Result; var json = result.Content.ReadAsStringAsync().Result; var response = JsonConvert.DeserializeObject <MarketOrderCollection>(json); if (response != null) { if (response.next != null) { adder(response.next.href); } OrdersBag.Add(response.Orders); //Orders.AddRange(response.Orders); //Trace.WriteLine("Download: " + item); } }); } }).ContinueWith((prevTask) => { var orders = new List <MarketOrder>(3000000); foreach (var list in OrdersBag) { orders.AddRange(list); } var groupedByStation = orders.ToLookup(x => x.StationId); foreach (var stationGroup in groupedByStation) { var station = Db.Instance.Stations.FirstOrDefault(s => s.stationID == stationGroup.Key); if (station == null) { continue; } foreach (var order in stationGroup) { order.SolarSystemId = station.solarSystemID; order.RegionId = station.regionID; order.StationSecurity = station.security; //SecurityUtils.RoundSecurity(station.security); } } orders.RemoveAll(x => x.SolarSystemId == 0); if (Settings.Default.IgnoreNullSecStations) { orders.RemoveAll(x => x.StationSecurity <= 0.0); } if (Settings.Default.IgnoreContraband) { var contraband = Db.Instance.ContrabandTypes.GroupBy(x => x.typeID).Select(x => x.Key); orders.RemoveAll(x => contraband.Contains(x.TypeId)); } OrdersByType = orders.ToLookup(o => o.TypeId); // create subsets for each item type }); /*await Task.Run(() => * { * var groupedByStation = Orders.ToLookup(x => x.StationID); * * foreach (var stationGroup in groupedByStation) * { * var station = DB.Instance.Stations.FirstOrDefault(s => s.stationID == stationGroup.Key); * if (station == null) continue; * * foreach (var order in stationGroup) * { * order.SolarSystemID = station.solarSystemID; * order.RegionID = station.regionID; * order.StationSecurity = station.security; * } * } * * if(Settings.Default.IgnoreNullSecStations) * Orders.RemoveAll(x => x.StationSecurity <= 0.0); * * if (Settings.Default.IgnoreContraband) * { * var contraband = DB.Instance.ContrabandTypes.GroupBy(x => x.typeID).Select(x => x.Key); * Orders.RemoveAll(x => contraband.Contains(x.TypeID)); * } * });*/ //OrdersByType = orders.ToLookup(o => o.TypeID); // create subsets for each item type //Orders.Clear(); }