Solved

Parallel.For Loop Q?

Posted on 2011-03-24
12
759 Views
Last Modified: 2012-05-11
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
Comment
Question by:kevp75
  • 5
  • 4
  • 2
12 Comments
 
LVL 23

Assisted Solution

by:wdosanjos
wdosanjos earned 150 total points
ID: 35209034
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
 
LVL 27

Expert Comment

by:nmarun
ID: 35209077
0
 
LVL 25

Author Comment

by:kevp75
ID: 35209183
Arun, i don't understand how it applies to my need
0
 
LVL 25

Author Comment

by:kevp75
ID: 35215073
hello?
0
 
LVL 27

Accepted Solution

by:
nmarun earned 350 total points
ID: 35220467
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 25

Author Comment

by:kevp75
ID: 35221874
it doesn't say anywhere in that article that a step size cannot be used.
0
 
LVL 27

Expert Comment

by:nmarun
ID: 35221998
The article says:

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

Arun
0
 
LVL 25

Author Comment

by:kevp75
ID: 35243486
ah
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35243671
BTW, I provided the answer way before the accepted solution.
0
 
LVL 27

Expert Comment

by:nmarun
ID: 35270503
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
 
LVL 25

Author Closing Comment

by:kevp75
ID: 35278971
tank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now