• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 765
  • Last Modified:

Parallel.For Loop Q?

How can I use Step in a Parallel.For loop?

For Instance, I can do this:
For i As Integer = 0 To 100 Step 10
   'Do Something
Next

But this:
Parallel.For(0, 100 Step 10, Function(i)
   'Do Something
                                         End Function)

bombs with an Overload error
0
kevp75
Asked:
kevp75
  • 5
  • 4
  • 2
2 Solutions
 
wdosanjosCommented:
AFAIK, there is no way to set the Step on a Parallel.For (it is always 1).  You can work around this limitation by calculating your index as below:

Parallel.For(0, 10, Function(i)
                    Dim index As Integer = i * 10
                    'Do Something
                    End Function)

Open in new window

0
 
nmarunCommented:
0
 
kevp75Author Commented:
Arun, i don't understand how it applies to my need
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kevp75Author Commented:
hello?
0
 
nmarunCommented:
Have a look here: http://www.lovethedot.net/2009/02/parallelfor-deeper-dive-parallel.html - tells you there's no way to give a step-size for the Parallel.For method.

Arun
0
 
kevp75Author Commented:
it doesn't say anywhere in that article that a step size cannot be used.
0
 
nmarunCommented:
The article says:

you wouldn’t be able to modify the iterator inside the loop as you can in for

Arun
0
 
kevp75Author Commented:
ah
0
 
wdosanjosCommented:
BTW, I provided the answer way before the accepted solution.
0
 
nmarunCommented:
wdosanjos, Although you did answer the question before, I think your 'AFAIK' (your first post) intimated the author that you were not sure and that there might be a way of doing this. But when I provided a documented way of telling this, the author was convinced. So I'm ok with a half-split of points on this. Sorry, this was an oversight by me, should have seen this before.

kevp75, Please split the points between wdosanjos and I.

Arun
0
 
kevp75Author Commented:
tank you
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now