本文整理汇总了C#中IList.AsParallel方法的典型用法代码示例。如果您正苦于以下问题:C# IList.AsParallel方法的具体用法?C# IList.AsParallel怎么用?C# IList.AsParallel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IList
的用法示例。
在下文中一共展示了IList.AsParallel方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PurgePath
/// <summary>
/// Removes containing paths and merge overlapping paths.
/// </summary>
/// <param name="scaffoldPaths">Input paths/scaffold.</param>
public void PurgePath(IList<ScaffoldPath> scaffoldPaths)
{
if (scaffoldPaths != null && 0 != scaffoldPaths.Count)
{
this.internalScaffoldPaths = scaffoldPaths.AsParallel().OrderBy(t => t.Count).ToList();
bool isUpdated = true;
bool[] isConsumed = new bool[this.internalScaffoldPaths.Count];
while (isUpdated)
{
isUpdated = false;
for (int index = 0; index < this.internalScaffoldPaths.Count; index++)
{
if (null != this.internalScaffoldPaths[index] &&
0 != this.internalScaffoldPaths[index].Count && !isConsumed[index])
{
isUpdated |=
this.SearchContainingAndOverlappingPaths(this.internalScaffoldPaths[index], isConsumed);
}
else
{
isConsumed[index] = true;
}
}
}
this.UpdatePath(isConsumed);
scaffoldPaths.Clear();
((List<ScaffoldPath>)scaffoldPaths).AddRange(this.internalScaffoldPaths);
}
}
示例2: GetFiles
// Takes same patterns, and executes in parallel
private static IEnumerable<string> GetFiles(string path,
IList<string> searchPatterns,
SearchOption searchOption = SearchOption.AllDirectories)
{
return searchPatterns.AsParallel()
.SelectMany(searchPattern =>
Directory.EnumerateFiles(path, searchPattern, searchOption));
}
示例3: CrossProductParallel
private static long CrossProductParallel(IList<long> vector1, IList<long> vector2)
{
if (vector1.Count != vector2.Count)
return 0;
var sum = (from a in vector1.AsParallel()
select ((from b in vector2 select b * a).Sum())).Sum();
return sum;
}
示例4: CreateTaskSharing
public IList<TaskSharingViewModel> CreateTaskSharing(IList<IFormFile> file, Guid taskId, Guid staffId)
{
Args.NotNull(file, nameof(file));
var taskSharings = new List<TaskSharingViewModel>();
file.AsParallel().ToList().ForEach(p => {
using (var reader = new StreamReader(p.OpenReadStream()))
{
reader.BaseStream.Position = 0;
var fileName = p.ContentDisposition.Split(';')[2].Split('=')[1].Replace("\"","");
var taskSharing = m_TaskSharingManager.CreateTaskSharing(taskId, staffId, fileName, p.ContentType, reader.BaseStream);
taskSharings.Add(taskSharing.ToViewModel());
}
});
return taskSharings;
}
示例5: IndexCompleted
public ActionResult IndexCompleted(int offSetX, int offSetY, int canvasWidth, int canvasHeight, string errMsg, IList<LogQueryResultDetail> details)
{
if (string.IsNullOrWhiteSpace(errMsg))
{
var list = new List<int[]>();
//list.Add(new int[] { offSetX, offSetY, offSetX, offSetY + canvasHeight, 255, 0, 0 });
//list.Add(new int[] { offSetX, offSetY + canvasHeight, offSetX + canvasWidth, offSetY + canvasHeight, 255, 0, 0 });
//list.Add(new int[] { offSetX + canvasWidth, offSetY + canvasHeight, offSetX + canvasWidth, offSetY, 255, 0, 0 });
//list.Add(new int[] { offSetX + canvasWidth, offSetY, offSetX, offSetY, 255, 0, 0 });
var curDT = DateTime.MinValue;
var curElapsed = -1L;
foreach (var cur in details.AsParallel().OrderBy(i => i.Elapsed).ThenBy(i => i.CreatedDateTime))
{
}
return Json(new { points = list, errmsg = "" }, JsonRequestBehavior.AllowGet);
}
return Json(new { errMsg = errMsg }, JsonRequestBehavior.AllowGet);
}
示例6: GenerateScaffold
/// <summary>
/// Generate sequences from list of contig nodes.
/// </summary>
/// <param name="contigGraph">Contig Overlap Graph.</param>
/// <param name="paths">Scaffold paths.</param>
/// <returns>List of sequences of scaffolds.</returns>
protected IList<ISequence> GenerateScaffold(
ContigGraph contigGraph,
IList<ScaffoldPath> paths)
{
if (contigGraph == null)
{
throw new ArgumentNullException("contigGraph");
}
if (paths == null)
{
throw new ArgumentNullException("paths");
}
List<ISequence> scaffolds = paths.AsParallel().Select(t => t.BuildSequenceFromPath(contigGraph, this.kmerLength)).ToList();
IEnumerable<Node> visitedNodes = contigGraph.Nodes.AsParallel().Where(t => !t.IsMarked());
scaffolds.AddRange(visitedNodes.AsParallel().Select(t => contigGraph.GetNodeSequence(t)));
contigGraph.Dispose();
return scaffolds;
}
示例7: TransformInboundMessages
private IList<CloudQueueMessage> TransformInboundMessages(IList<CloudQueueMessage> inboundMessages, Stopwatch stopWatch)
{
if(this.OptionalThreadSafeMessageTransformer == null)
return inboundMessages;
// Transform messages before requeueing them.
if(inboundMessages.Count < 5)
// When we have a few messages, transform them sequentially.
inboundMessages = inboundMessages.Select(msg => this.OptionalThreadSafeMessageTransformer(msg)).ToList();
else
// When there are many messages, transform them in parallel.
inboundMessages = inboundMessages.AsParallel().AsOrdered().Select(msg => this.OptionalThreadSafeMessageTransformer(msg)).ToList();
this.LogInformation("Done transforming {0} messages. Elapsed {1}.", inboundMessages.Count, stopWatch.Elapsed);
stopWatch.Reset();
stopWatch.Start();
return inboundMessages;
}
示例8: ComputeReport
public ReportingResult ComputeReport(
IList<FrameworkName> targets,
string submissionId,
AnalyzeRequestFlags requestFlags,
IDictionary<MemberInfo, ICollection<AssemblyInfo>> allDependencies,
IList<MemberInfo> missingDependencies,
IDictionary<string, ICollection<string>> unresolvedAssemblies,
IList<string> unresolvedUserAssemblies,
IEnumerable<string> assembliesWithErrors)
{
var types = allDependencies.Keys.Where(dep => dep.TypeDocId == null);
ReportingResult result = new ReportingResult(targets, types, submissionId, requestFlags);
missingDependencies
.AsParallel()
.ForAll((Action<MemberInfo>)((item) =>
{
// the calling assemblies are in Finder...
if (allDependencies == null)
{
lock (result)
{
result.AddMissingDependency(null, item, item.RecommendedChanges);
}
}
else
{
ICollection<AssemblyInfo> calledIn;
if (!allDependencies.TryGetValue(item, out calledIn))
return;
foreach (var callingAsm in calledIn)
{
lock (result)
{
result.AddMissingDependency(callingAsm, item, item.RecommendedChanges);
}
}
}
}));
if (assembliesWithErrors != null)
{
foreach (var error in assembliesWithErrors)
{
result.AddAssemblyWithError(error);
}
}
foreach (var unresolvedAssembly in unresolvedUserAssemblies)
{
result.AddUnresolvedUserAssembly(unresolvedAssembly, unresolvedAssemblies == null ? Enumerable.Empty<string>() : unresolvedAssemblies[unresolvedAssembly]);
}
// Compute per assembly report
if (allDependencies != null)
{
var perAssemblyUsage = ComputePerAssemblyUsage(targets, missingDependencies, allDependencies);
result.SetAssemblyUsageInfo(perAssemblyUsage);
// Compute the map of assemblyInfo to name
var assemblyNameMap = ComputeAssemblyNames(perAssemblyUsage);
result.SetAssemblyNameMap(assemblyNameMap);
}
return result;
}
示例9: ReadContigAlignment
/// <summary>
/// Aligns reads to contigs using kmer method of alignment.
/// </summary>
/// <param name="contigs">List of contig sequences.</param>
/// <param name="reads">List of read sequences.</param>
/// <param name="kmerLength">Kmer Length.</param>
/// <returns>List of Contig.</returns>
public static IList<Contig> ReadContigAlignment(IList<ISequence> contigs, IList<ISequence> reads, int kmerLength)
{
KmerIndexerDictionary map = SequenceToKmerBuilder.BuildKmerDictionary(reads, kmerLength);
IList<ContigIndex> contigDatas;
contigDatas = contigs.AsParallel().Select(contig =>
{
IEnumerable<ISequence> kmers = SequenceToKmerBuilder.GetKmerSequences(contig, kmerLength);
ContigIndex index = new ContigIndex(contig);
foreach (ISequence kmer in kmers)
{
IList<KmerIndexer> positions;
if (map.TryGetValue(kmer, out positions) ||
map.TryGetValue(kmer.GetReverseComplementedSequence(), out positions))
{
index.ContigReadMatchIndexes.Add(positions);
}
else
{
index.ContigReadMatchIndexes.Add(new List<KmerIndexer>());
}
}
return index;
}).ToList();
return contigDatas.Select(contigData =>
{
IList<Task<IList<ReadMap>>> tasks =
new List<Task<IList<ReadMap>>>();
// Stores information about contigs for which tasks has been generated.
IList<long> visitedReads = new List<long>();
// Creates Task for every read in nodes for a given contig.
for (int index = 0; index < contigData.ContigReadMatchIndexes.Count; index++)
{
int readPosition = index;
foreach (KmerIndexer kmer in contigData.ContigReadMatchIndexes[index])
{
long contigIndex = kmer.SequenceIndex;
if (!visitedReads.Contains(contigIndex))
{
visitedReads.Add(contigIndex);
tasks.Add(
Task<IList<ReadMap>>.Factory.StartNew(t => MapRead(readPosition, contigData.ContigReadMatchIndexes, contigIndex, kmerLength), TaskCreationOptions.AttachedToParent));
}
}
}
Contig contigOutputStructure = new Contig();
contigOutputStructure.Consensus = contigData.ContigSequence;
for (int index = 0; index < visitedReads.Count; index++)
{
foreach (ReadMap maps in tasks[index].Result)
{
Contig.AssembledSequence assembledSeq = new Contig.AssembledSequence()
{
Length = maps.Length,
Position = maps.StartPositionOfContig,
ReadPosition = maps.StartPositionOfRead,
Sequence = reads.ElementAt(visitedReads[index])
};
if (new string(
contigOutputStructure.Consensus.GetSubSequence(
assembledSeq.Position, assembledSeq.Length).Select(a => (char)a).ToArray()).
Equals(new string(assembledSeq.Sequence.GetSubSequence(assembledSeq.ReadPosition, assembledSeq.Length)
.Select(a => (char)a).ToArray())))
{
assembledSeq.IsComplemented = false;
assembledSeq.IsReversed = false;
}
else
{
assembledSeq.IsComplemented = true;
assembledSeq.IsReversed = true;
}
contigOutputStructure.Sequences.Add(assembledSeq);
}
}
return contigOutputStructure;
}).ToList();
}