Questions tagged [parallel.for]

Parallel.For is a .NET method that allows iterations of a for-like loop to execute in parallel using tasks.

The Parallel.For method basically accepts delegate methods to use in a parallel fashion.
This does not meant that the methods will be always executed in parallel, because that mechanism is delegated to the .

249 questions
16
votes
8 answers

Parallelizing a for loop gives no performance gain

I have an algorithm which converts a bayer image channel to RGB. In my implementation I have a single nested for loop which iterates over the bayer channel, calculates the rgb index from the bayer index and then sets that pixel's value from the…
eladidan
  • 2,634
  • 2
  • 26
  • 39
11
votes
4 answers

What's the best way of achieving a parallel infinite Loop?

I've gotten used to using Parallel.For() in .NET's parallel extensions as it's a simple way of parallelizing code without having to manually start and maintain threads (which can be fiddly). I'm now looking at an infinite loop (do something until I…
11
votes
1 answer

What is the meaning of AStride in TParallel.For?

TParallel.For() has an argument called AStride. In my case AStride is 2: TParallel.&For(2, 1, 10, procedure(index: Integer) begin TThread.Queue(nil, procedure begin memo1.Lines.Add(index.ToString()); …
iPath ツ
  • 2,468
  • 20
  • 31
11
votes
3 answers

Task.Factory.StartNew or Parallel.ForEach for many long-running tasks?

Possible Duplicate: Parallel.ForEach vs Task.Factory.StartNew I need to run about 1,000 tasks in a ThreadPool on a nightly basis (the number may grow in the future). Each task is performing a long running operation (reading data from a web…
Zaid Masud
  • 13,225
  • 9
  • 67
  • 88
10
votes
3 answers

Does Thread.Sleep hinder other threads?

Here is a console program want 10 threads start in batch, wait 5 seconds, and stop in batch. static void Main(string[] args) { System.Threading.Tasks.Parallel.For(0, 10, (index) => { Action act = (i) => { …
demaxSH
  • 1,743
  • 2
  • 20
  • 27
10
votes
2 answers

Parallel.For() slows down with repeated execution. What should I look at?

I wrote a naive Parallel.For() loop in C#, shown below. I also did the same work using a regular for() loop to compare single-thread vs. multi-thread. The single thread version took about five seconds every time I ran it. The parallel version took…
jrv
  • 443
  • 4
  • 14
9
votes
2 answers

Parallel.For not utilising all cores

I'm doing heavy mathematical computations using Math.Net Numerics parallely inside Parallel.For block. When I run code in my local system with 4 cores(2*2), it's using all 4 cores. But when I run same code in our dev server with 8 cores(4*2), it's…
malkam
  • 2,337
  • 1
  • 14
  • 17
7
votes
5 answers

Is it possible to define the execution order in Parallel.For?

// parameters.Count == 10 // actualFreeLicenses == 2 Parallel.For(0, parameters.Count, new ParallelOptions() { MaxDegreeOfParallelism = actualFreeLicenses }, i => …
Saint
  • 5,397
  • 22
  • 63
  • 107
7
votes
4 answers

Memory barriers in Parallel.For

Microsoft's documention of Parallel.For contains the following method: static void MultiplyMatricesParallel(double[,] matA, double[,] matB, double[,] result) { int matACols = matA.GetLength(1); int matBCols = matB.GetLength(1); int…
adv12
  • 8,443
  • 2
  • 24
  • 48
7
votes
2 answers

OMP For parallel thread ID hello world

I'm trying to get started with using basic OpenMP functionality in C. My basic understanding of 'omp parallel for' leads me to believe the following should distribute the following iterations of the loop between threads and should execute…
Oliver
  • 651
  • 2
  • 9
  • 17
6
votes
3 answers

Why isn't Parallel.For fast with heap-intensive operations?

For some operations Parallel scales well with the number of CPU's, but for other operations it does not. Consider the code below, function1 gets a 10x improvement while function2 gets a 3x improvement. Is this due to memory allocation, or perhaps…
6
votes
5 answers

Parallel.ForEach maintain collection order?

Is there a way to guarantee order when using Parallel.ForEach()? The collection I am looping over needs to maintain it's order but I was looking for some performance improvement.
6
votes
5 answers

Writing To A File With Multiple Streams C#

I am trying to download a large file (>1GB) from one server to another using HTTP. To do this I am making HTTP range requests in parallel. This lets me download the file in parallel. When saving to disk I am taking each response stream, opening the…
shortspider
  • 1,045
  • 15
  • 34
6
votes
3 answers

How to use Parallel.For?

I want to use Parallel Programming in my project (WPF) . here is my for loop code. for (int i = 0; i < results.Count; i++) { product p = new product(); Common.SelectedOldColor = p.Background; p.VideoInfo = results[i]; …
unbalanced
  • 1,192
  • 5
  • 19
  • 44
5
votes
3 answers

Change for loop to Parallel.For loop

I can change my loop for (int i = 0; i < something; i++) to: Parallel.For(0, something, i => But how to do this with this loop?: for (i = 3; i <= something / 2; i = i + 2) Thanks for answers.
Monna L
  • 105
  • 7
1
2 3
16 17