Question parallel programming

andrews

Well-known member
Joined
Nov 22, 2011
Messages
167
Programming Experience
5-10
Hi,
I do not know much of parallel programming but I try to do something simple (I guess).
My PC has 4 cores


I write in the module :


Imports System.Threading.Tasks


Then


public function dosomething as integer
dim i,j, sum1, sum2 , sum as integer


for i = 1 to 1000
sum1= sum1+ i
next


for j = 1 to 1000
sum2 = sum2 + j
next


sum = sum1 + sum2
return sum
end function


do not see the foolishness of this function because it must emphasize just the parallel programming problem


I want that the two iterations works at the same time
I wrote :
parallel.for(
But the editor proposed just parallel.form1 or parallel.my and parallel.for was not possible.
What am I missing?
Thanks for any response
 
Make sure you import System.Threading.Tasks. Also, Parallel.For() will not run your two iterations at the same time, it will run one iteration four indexes at a time.
 
Thanks for the interest.
I know that parallel computing is not so easy and I do not want to become an expert by reading many documents about. :=)
Can somebody give me the information by head how I can run two iterations at the same time.
 
The issue is that you had a name clash. You named your project Parallel and that means that the default namespace would be Parallel too. As such, when you use Parallel in code, the compiler interprets it as your default namespace rather than the Parallel class from the System.Threading.Tasks namespace. This is a reason to NEVER use project names that can clash with existing namespaces and types. If you had named your project ParallelTest or ParallelDemo or the like then you would have been OK. Better still, always give your projects compound names. Come with a "company name" to use in all your projects. I used to work for myself and my business name was Wunnell Development so all my projects are named something like Wunnell.SomeProject. That pretty much guarantees no name clashes.
 
Sorry, jmcilhinney but I never mentionned the name of my project (Dice) but it is good advice.
Almost certainly either your project was originally named Parallel or you changed the root namespace to that after creating the project.
But the editor proposed just parallel.form1 or parallel.my and parallel.for was not possible.
Form1 is the first form added to your project by default and every VB.NET Windows app has a My namespace, so the fact that those two are members of Parallel according to Intellisense means that you have a Parallel namespace in your project.
 
Back
Top