本文整理匯總了C#中System.Threading.Tasks.ParallelOptions類的典型用法代碼示例。如果您正苦於以下問題:C# ParallelOptions類的具體用法?C# ParallelOptions怎麽用?C# ParallelOptions使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ParallelOptions類屬於System.Threading.Tasks命名空間,在下文中一共展示了ParallelOptions類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Build
public void Build(MetricDB db, int k, Index ref_index)
{
this.DB = db;
this.K = k;
this.R = ref_index;
int sigma = this.R.DB.Count;
this.INVINDEX = new List<List<int>> (sigma);
for (int i = 0; i < sigma; ++i) {
this.INVINDEX.Add(new List<int>());
}
var A = new int[this.DB.Count][];
int count = 0;
var compute_one = new Action<int>(delegate(int objID) {
var u = this.GetKnr(this.DB[objID], this.K);
A[objID] = u;
++count;
if (count % 1000 == 0) {
Console.WriteLine ("==== {0}/{1} db: {2}, k: {3}", count, this.DB.Count, this.DB.Name, k);
}
});
ParallelOptions ops = new ParallelOptions();
ops.MaxDegreeOfParallelism = -1;
Parallel.ForEach(new ListGen<int>((int i) => i, this.DB.Count), ops, compute_one);
for (int objID = 0; objID < this.DB.Count; ++objID) {
var u = A[objID];
for (int i = 0; i < this.K; ++i) {
this.INVINDEX[u[i]].Add (objID);
}
}
}
示例2: ImportAllStreams
public void ImportAllStreams()
{
var ids = new List<int>();
using (var con = new System.Data.SqlClient.SqlConnection(_cs))
{
con.Open();
ids = GetStreamIds(con).OrderBy(d => d).ToList();
}
var po = new ParallelOptions { MaxDegreeOfParallelism = 4 };
//Parallel.ForEach(ids, po, id =>
//{
// var sw = Stopwatch.StartNew();
// TryImportStream(id);
// sw.Stop();
// ImportedStreams++;
// Console.WriteLine(" Done in {0}", sw.Elapsed);
//});
foreach (var id in ids)
{
var sw = Stopwatch.StartNew();
TryImportStream(id);
sw.Stop();
ImportedStreams++;
Console.WriteLine(" Done in {0}", sw.Elapsed);
}
}
示例3: GetBuildInfoDtos
public List<BuildInfoDto> GetBuildInfoDtos()
{
var buildInfoDtos = new ConcurrentBag<BuildInfoDto>();
try
{
var tfsServer = _helperClass.GetTfsServer();
// Get the catalog of team project collections
var teamProjectCollectionNodes = tfsServer.CatalogNode.QueryChildren(
new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None);
var parallelOptions = new ParallelOptions {MaxDegreeOfParallelism = 1};
Parallel.ForEach(teamProjectCollectionNodes, parallelOptions, teamProjectCollectionNode =>
{
var task = GetBuildInfoDtosPerTeamProject(teamProjectCollectionNode, tfsServer, DateTime.MinValue);
task.ConfigureAwait(false);
task.Wait();
var buildInfos = task.Result;
foreach (var buildInfoDto in buildInfos)
{
buildInfoDtos.Add(buildInfoDto);
}
});
}
catch (Exception e)
{
LogService.WriteError(e);
throw;
}
return buildInfoDtos.ToList();
}
示例4: GetBuildInfoDtosPolling
public List<BuildInfoDto> GetBuildInfoDtosPolling(String filterDate)
{
var buildInfoDtos = new List<BuildInfoDto>();
try
{
var sinceDateTime = DateTime.Now.Subtract(new TimeSpan(int.Parse(filterDate), 0, 0));
var tfsServer = _helperClass.GetTfsServer();
// Get the catalog of team project collections
var teamProjectCollectionNodes = tfsServer.CatalogNode.QueryChildren(
new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None);
var parallelOptions = new ParallelOptions() {MaxDegreeOfParallelism = 1};
Parallel.ForEach(teamProjectCollectionNodes, parallelOptions, teamProjectCollectionNode =>
{
var taskBuidInfos = GetBuildInfoDtosPerTeamProject(teamProjectCollectionNode, tfsServer, sinceDateTime);
taskBuidInfos.ConfigureAwait(false);
taskBuidInfos.Wait();
lock (buildInfoDtos)
{
buildInfoDtos.AddRange(taskBuidInfos.Result);
}
});
}
catch (Exception e)
{
LogService.WriteError(e);
throw;
}
return buildInfoDtos;
}
示例5: Initialize
/// <summary>
/// Initialize the experiment with configuration file parameters.
/// </summary>
/// <param name="name">The name of the experiment</param>
/// <param name="xmlConfig">The parent XML configuration element</param>
public virtual void Initialize(string name, XmlElement xmlConfig)
{
// Set all properties
Name = name;
DefaultPopulationSize = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
Description = XmlUtils.GetValueAsString(xmlConfig, "Description");
// Set all internal class variables
_activationScheme = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
ComplexityRegulationStrategy = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
Complexitythreshold = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
ParallelOptions = ExperimentUtils.ReadParallelOptions(xmlConfig);
// Set evolution/genome parameters
NeatEvolutionAlgorithmParameters = new NeatEvolutionAlgorithmParameters
{
SpecieCount = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount"),
InterspeciesMatingProportion = XmlUtils.GetValueAsDouble(xmlConfig,
"InterspeciesMatingProbability"),
MinTimeAlive = XmlUtils.GetValueAsInt(xmlConfig, "MinTimeAlive")
};
NeatGenomeParameters = ExperimentUtils.ReadNeatGenomeParameters(xmlConfig);
// Set experiment-specific parameters
MaxTimesteps = XmlUtils.TryGetValueAsInt(xmlConfig, "MaxTimesteps");
MinSuccessDistance = XmlUtils.TryGetValueAsInt(xmlConfig, "MinSuccessDistance");
MaxDistanceToTarget = XmlUtils.TryGetValueAsInt(xmlConfig, "MaxDistanceToTarget");
MazeVariant =
MazeVariantUtl.convertStringToMazeVariant(XmlUtils.TryGetValueAsString(xmlConfig, "MazeVariant"));
}
示例6: Main
static void Main(string[] args)
{
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
Console.WriteLine("Press enter to start");
Console.ReadLine();
// Batch the connections, once they're all active though it's fine
int connectionBatchSize = 10;
int connectionSleepInterval = 1000;
int maxClients = 3000;
var options = new ParallelOptions
{
MaxDegreeOfParallelism = connectionBatchSize
};
for (int x = 0; x < maxClients; x += connectionBatchSize)
{
Parallel.For(0, connectionBatchSize, options, i =>
{
StartClient();
});
System.Threading.Thread.Sleep(connectionSleepInterval);
}
Console.Read();
}
示例7: ValidateSparseMatrixAsDenseAnsi
public void ValidateSparseMatrixAsDenseAnsi()
{
SparseMatrix<string, string, double> sparseMatrixObj = GetSparseMatrix();
ParallelOptions parallelOptObj = new ParallelOptions();
DenseAnsi denseAnsiObj =
sparseMatrixObj.AsDenseAnsi<double>(parallelOptObj);
// Validate all properties of Ansi and SparseMatrix
Assert.AreEqual(sparseMatrixObj.ColCount, denseAnsiObj.ColCount);
Assert.AreEqual(sparseMatrixObj.ColKeys.Count, denseAnsiObj.ColKeys.Count);
Assert.AreEqual(sparseMatrixObj.IndexOfColKey.Count, denseAnsiObj.IndexOfColKey.Count);
Assert.AreEqual(sparseMatrixObj.IndexOfRowKey.Count, denseAnsiObj.IndexOfRowKey.Count);
Assert.AreEqual("?", denseAnsiObj.MissingValue.ToString((IFormatProvider)null));
Assert.AreEqual(sparseMatrixObj.RowCount, denseAnsiObj.RowCount);
Assert.AreEqual(sparseMatrixObj.RowKeys.Count, denseAnsiObj.RowKeys.Count);
Assert.AreEqual(utilityObj.xmlUtil.GetTextValue(
Constants.SimpleMatrixNodeName,
Constants.DenseAnsiStringNode),
denseAnsiObj.ToString2D().Replace("\r", "").Replace("\n", "").Replace("\t", ""));
ApplicationLog.WriteLine(
"SparseMatrix BVT : Validation of AsDenseAnsi() method successful");
}
示例8: ExecuteAsync
public override async Task ExecuteAsync()
{
// Create 100 Data objects
var data = Enumerable.Range(1, 100).Select(i => new Data { Number = i });
// Option 1a: use Upsert with an IDictionary<string, object> of documents in upsert
var bulkData = data.ToDictionary(d => "dotnetDevguideExample-" + d.Number);
// Note: There is no UpsertAsync overload that takes multiple values (yet)
// which is why this example wraps the synchronized method in a new Task.
// If your code is fully synchronous, you can simply call _bucket.Upsert(...)
var bulkResult = await Task.Run(() => _bucket.Upsert(bulkData));
var successCount = bulkResult.Where(r => r.Value.Success).Count();
Console.WriteLine("Upserted {0} values", bulkResult.Count);
// Option 1b: Specify ParallelOptions to customize how the client parallelizes the upserts
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = 32 };
var bulkResult2 = await Task.Run(() => _bucket.Upsert(bulkData, parallelOptions));
successCount = bulkResult2.Where(r => r.Value.Success).Count();
Console.WriteLine("Upserted {0} values", successCount);
// Option 2: Spawn multiple Upsert tasks and wait on for all to complete
var bulkTasks = bulkData.Select(d => _bucket.UpsertAsync(d.Key, d.Value));
var bulkResults = await Task.WhenAll(bulkTasks);
successCount = bulkResults.Where(r => r.Success).Count();
Console.WriteLine("Upserted {0} values", successCount);
}
示例9: MaxDegreeOfParallelismPropertyBehavior
public void MaxDegreeOfParallelismPropertyBehavior()
{
var po = new ParallelOptions {MaxDegreeOfParallelism = 10};
Assert.That(po.MaxDegreeOfParallelism, Is.EqualTo(10));
po.MaxDegreeOfParallelism = 3;
Assert.That(po.MaxDegreeOfParallelism, Is.EqualTo(3));
}
示例10: Read_Streams
public void Read_Streams()
{
long values = 0;
int streams = 0;
var watch = Stopwatch.StartNew();
var opt = new ParallelOptions { MaxDegreeOfParallelism = 4 };
Parallel.ForEach(GetStreams(), opt, stream =>
//foreach (var stream in GetStreams())
{
streams++;
var repository = BuildRepository(stream);
foreach (var value in repository.GetValues())
values++;
var speed = values / watch.Elapsed.TotalSeconds;
Console.WriteLine("Completed {0} number {1} : {2:0} total of {3} ", stream, streams, speed, values);
}
);
watch.Stop();
Console.WriteLine("read {0} values in {1} streams in {2}", values, streams, watch.Elapsed);
}
示例11: DownloadProjectsFromGitHub
private static void DownloadProjectsFromGitHub(IEnumerable<Repository> searchRepositoryResult,
string buildFolder)
{
var parallelOptions = new ParallelOptions {MaxDegreeOfParallelism = 1};
Parallel.ForEach(searchRepositoryResult, parallelOptions, r =>
{
var archivePath = Path.Combine(buildFolder, r.Name + ".zip");
var destinationDirectoryName = Path.Combine(buildFolder, r.Name);
if (!File.Exists(archivePath))
{
var downloadUrl = r.HtmlUrl + "/archive/master.zip";
Console.WriteLine("Downloading from: {0}", downloadUrl);
using (var client = new WebClient())
{
client.DownloadFile(downloadUrl, archivePath);
}
}
try
{
Console.WriteLine("Extracting to: {0}", destinationDirectoryName);
ZipFile.ExtractToDirectory(archivePath, destinationDirectoryName);
}
catch (Exception e)
{
Console.WriteLine(e);
Directory.Delete(destinationDirectoryName, true);
}
});
}
開發者ID:nickgodsland,項目名稱:DiscoverProjectsThatAreEasilyBuiltWithMsbuild,代碼行數:30,代碼來源:DiscoverProjectsThatAreEasilyBuiltWithMsbuild.cs
示例12: ExecuteAsync
public override async Task ExecuteAsync()
{
// Call BulkInsert to generate some data
await new BulkInsert().ExecuteAsync();
// Generate the keys to retrieve
var keys = Enumerable.Range(1, 100).Select(i => "dotnetDevguideExample-" + i).ToList();
// Option 1a: use Get with a IList<string> of document keys to retrieve
// Note: There is no GetAsync overload that takes multiple keys (yet)
// which is why this example wraps the synchronized method in a new Task.
// If your code is fully synchronous, you can simply call _bucket.Get(...)
var bulkResult = await Task.Run(() => _bucket.Get<Data>(keys));
var successCount = bulkResult.Where(r => r.Value.Success).Count();
Console.WriteLine("Got {0} values", bulkResult.Count);
// Option 1b: Specify ParallelOptions to customize how the client parallelizes the gets
var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = 32 };
var bulkResult2 = await Task.Run(() => _bucket.Get<Data>(keys, parallelOptions));
successCount = bulkResult2.Where(r => r.Value.Success).Count();
Console.WriteLine("Got {0} values", successCount);
// Option 2: Spawn multiple Upsert tasks and wait on for all to complete
var bulkTasks = keys.Select(key => _bucket.GetAsync<Data>(key));
var bulkResults = await Task.WhenAll(bulkTasks);
successCount = bulkResults.Where(r => r.Success).Count();
Console.WriteLine("Got {0} values", successCount);
}
示例13: ValidateRowKeysPairAnsiGetInstanceFromPairAnsi
public void ValidateRowKeysPairAnsiGetInstanceFromPairAnsi()
{
ParallelOptions parOptObj = new ParallelOptions();
UOPair<char> uoPairObj = new UOPair<char>('?', '?');
DensePairAnsi dpaObj =
DensePairAnsi.CreateEmptyInstance(
new string[] { "R0", "R1", "R2" },
new string[] { "C0", "C1", "C2", "C3" },
uoPairObj);
dpaObj.WriteDensePairAnsi(Constants.FastQTempTxtFileName,
parOptObj);
using (RowKeysPairAnsi rkaObj =
RowKeysPairAnsi.GetInstanceFromPairAnsi(
Constants.FastQTempTxtFileName, parOptObj))
{
Assert.AreEqual(4, rkaObj.ColCount);
Assert.AreEqual(3, rkaObj.RowCount);
}
if (File.Exists(Constants.FastQTempTxtFileName))
File.Delete(Constants.FastQTempTxtFileName);
ApplicationLog.WriteLine(
"RowKeysPairAnsi BVT : Validation of GetInstanceFromPairAnsi() method successful");
}
示例14: ValidateRowKeysPDGetInstanceFromPaddedDoubleFileAccess
public void ValidateRowKeysPDGetInstanceFromPaddedDoubleFileAccess()
{
DenseMatrix<string, string, double> denseMatObj =
GetDenseMatrix();
ParallelOptions parOptObj = new ParallelOptions();
denseMatObj.WritePaddedDouble(Constants.FastQTempTxtFileName,
parOptObj);
using (RowKeysPaddedDouble rkpdObj =
RowKeysPaddedDouble.GetInstanceFromPaddedDouble(
Constants.FastQTempTxtFileName, parOptObj, FileAccess.ReadWrite,
FileShare.ReadWrite))
{
Assert.AreEqual(denseMatObj.ColCount, rkpdObj.ColCount);
Assert.AreEqual(denseMatObj.RowCount, rkpdObj.RowCount);
Assert.AreEqual(denseMatObj.RowKeys.Count, rkpdObj.RowKeys.Count);
Assert.AreEqual(denseMatObj.ColKeys.Count, rkpdObj.ColKeys.Count);
}
if (File.Exists(Constants.FastQTempTxtFileName))
File.Delete(Constants.FastQTempTxtFileName);
ApplicationLog.WriteLine(
"RowKeysPaddedDouble BVT : Validation of GetInstanceFromPaddedDouble(file-access) method successful");
}
示例15: ValidateRowKeysAnsiGetInstanceFromDenseAnsi
public void ValidateRowKeysAnsiGetInstanceFromDenseAnsi()
{
DenseMatrix<string, string, double> denseMatObj =
GetDenseMatrix();
ParallelOptions parOptObj = new ParallelOptions();
denseMatObj.WriteDenseAnsi(Constants.FastQTempTxtFileName,
parOptObj);
using (RowKeysAnsi rkaObj =
RowKeysAnsi.GetInstanceFromDenseAnsi(Constants.FastQTempTxtFileName,
parOptObj))
{
Assert.AreEqual(denseMatObj.ColCount, rkaObj.ColCount);
Assert.AreEqual(denseMatObj.RowCount, rkaObj.RowCount);
Assert.AreEqual(denseMatObj.RowKeys.Count, rkaObj.RowKeys.Count);
Assert.AreEqual(denseMatObj.ColKeys.Count, rkaObj.ColKeys.Count);
}
if (File.Exists(Constants.FastQTempTxtFileName))
File.Delete(Constants.FastQTempTxtFileName);
ApplicationLog.WriteLine(
"RowKeysAnsi BVT : Validation of GetInstanceFromDenseAnsi() method successful");
}