473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Converting a nested loop to use multithreading?

Hello all,

I have the following nested loop structure that I would love to convert to x
amount of threads:

For i = 0 To 100
For j = 0 To 100
For k = 0 To 100
Console.WriteLine("k = " & k)
Next
Console.WriteLine("j = " & j)
Next
Console.WriteLine("i =" & i)
Next

This process is based on existing code that I have that is taking well over
1 hour to complete.

Could someone provide me with example code to convert this to
multithreading, say 10 threads at once?
Nov 21 '05 #1
5 1755
Hi Richard,

I don't have the code, but this raises an interesting question to me.

Doing 10 things simultaneously isn't necessary quicker and may actually be
slower... right or wrong?
Unless in each thread there is some latency time that the thread must wait
for I/O or something that another thread might be operating. Because unless
you have more than one processor, nothing actually happens at the same time,
just the process's time is divided per thread... am I right on this?

Sorry I don't have the code.. but also wanted to know an answer to my
question about your question. :)

Shane
"Richard Aubin" <rca_hyip@@hotmail.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Hello all,

I have the following nested loop structure that I would love to convert to x amount of threads:

For i = 0 To 100
For j = 0 To 100
For k = 0 To 100
Console.WriteLine("k = " & k)
Next
Console.WriteLine("j = " & j)
Next
Console.WriteLine("i =" & i)
Next

This process is based on existing code that I have that is taking well over 1 hour to complete.

Could someone provide me with example code to convert this to
multithreading, say 10 threads at once?

Nov 21 '05 #2
Hello,

Yes, I am waiting for something to complete between loops.

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:uy****************@TK2MSFTNGP11.phx.gbl...
Hi Richard,

I don't have the code, but this raises an interesting question to me.

Doing 10 things simultaneously isn't necessary quicker and may actually be
slower... right or wrong?
Unless in each thread there is some latency time that the thread must wait
for I/O or something that another thread might be operating. Because unless you have more than one processor, nothing actually happens at the same time, just the process's time is divided per thread... am I right on this?

Sorry I don't have the code.. but also wanted to know an answer to my
question about your question. :)

Shane
"Richard Aubin" <rca_hyip@@hotmail.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Hello all,

I have the following nested loop structure that I would love to convert
to x
amount of threads:

For i = 0 To 100
For j = 0 To 100
For k = 0 To 100
Console.WriteLine("k = " & k)
Next
Console.WriteLine("j = " & j)
Next
Console.WriteLine("i =" & i)
Next

This process is based on existing code that I have that is taking well

over
1 hour to complete.

Could someone provide me with example code to convert this to
multithreading, say 10 threads at once?


Nov 21 '05 #3
In that case, Chapter 19 of the Wrox "Professional VB.NET" book has code
that might be of use on how to do threading and thread pooling.

you can probably download the code from
www.wrox.com

maybe it would give you and idea.

HTH,

Shane
"Richard Aubin" <rca_hyip@@hotmail.com> wrote in message
news:uW*************@TK2MSFTNGP09.phx.gbl...
Hello,

Yes, I am waiting for something to complete between loops.

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:uy****************@TK2MSFTNGP11.phx.gbl...
Hi Richard,

I don't have the code, but this raises an interesting question to me.

Doing 10 things simultaneously isn't necessary quicker and may actually be slower... right or wrong?
Unless in each thread there is some latency time that the thread must wait for I/O or something that another thread might be operating. Because unless
you have more than one processor, nothing actually happens at the same

time,
just the process's time is divided per thread... am I right on this?

Sorry I don't have the code.. but also wanted to know an answer to my
question about your question. :)

Shane
"Richard Aubin" <rca_hyip@@hotmail.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Hello all,

I have the following nested loop structure that I would love to

convert to
x
amount of threads:

For i = 0 To 100
For j = 0 To 100
For k = 0 To 100
Console.WriteLine("k = " & k)
Next
Console.WriteLine("j = " & j)
Next
Console.WriteLine("i =" & i)
Next

This process is based on existing code that I have that is taking well

over
1 hour to complete.

Could someone provide me with example code to convert this to
multithreading, say 10 threads at once?



Nov 21 '05 #4
Hi Shane,

That is exactly what I'm looking for.

Now all I have to do is dissect their code and apply it to my program.

Thanks!
"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:Oy****************@TK2MSFTNGP10.phx.gbl...
In that case, Chapter 19 of the Wrox "Professional VB.NET" book has code
that might be of use on how to do threading and thread pooling.

you can probably download the code from
www.wrox.com

maybe it would give you and idea.

HTH,

Shane
"Richard Aubin" <rca_hyip@@hotmail.com> wrote in message
news:uW*************@TK2MSFTNGP09.phx.gbl...
Hello,

Yes, I am waiting for something to complete between loops.

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:uy****************@TK2MSFTNGP11.phx.gbl...
Hi Richard,

I don't have the code, but this raises an interesting question to me.

Doing 10 things simultaneously isn't necessary quicker and may actually
be
slower... right or wrong?
Unless in each thread there is some latency time that the thread must wait for I/O or something that another thread might be operating. Because

unless
you have more than one processor, nothing actually happens at the same

time,
just the process's time is divided per thread... am I right on this?

Sorry I don't have the code.. but also wanted to know an answer to my
question about your question. :)

Shane
"Richard Aubin" <rca_hyip@@hotmail.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
> Hello all,
>
> I have the following nested loop structure that I would love to

convert
to
x
> amount of threads:
>
> For i = 0 To 100
> For j = 0 To 100
> For k = 0 To 100
> Console.WriteLine("k = " & k)
> Next
> Console.WriteLine("j = " & j)
> Next
> Console.WriteLine("i =" & i)
> Next
>
> This process is based on existing code that I have that is taking

well over
> 1 hour to complete.
>
> Could someone provide me with example code to convert this to
> multithreading, say 10 threads at once?
>
>



Nov 21 '05 #5
It is a pretty decent book Not bad for a reference... If you decide to buy
a copy--for sure buy online..the book is like $60 in Books a million but if
you get there discount card and order online it is at least half that price.

Glad to help you,

Shane

"Richard Aubin" <rca_hyip@@hotmail.com> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
Hi Shane,

That is exactly what I'm looking for.

Now all I have to do is dissect their code and apply it to my program.

Thanks!
"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:Oy****************@TK2MSFTNGP10.phx.gbl...
In that case, Chapter 19 of the Wrox "Professional VB.NET" book has code
that might be of use on how to do threading and thread pooling.

you can probably download the code from
www.wrox.com

maybe it would give you and idea.

HTH,

Shane
"Richard Aubin" <rca_hyip@@hotmail.com> wrote in message
news:uW*************@TK2MSFTNGP09.phx.gbl...
Hello,

Yes, I am waiting for something to complete between loops.

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message news:uy****************@TK2MSFTNGP11.phx.gbl...
> Hi Richard,
>
> I don't have the code, but this raises an interesting question to me. >
> Doing 10 things simultaneously isn't necessary quicker and may actually
be
> slower... right or wrong?
> Unless in each thread there is some latency time that the thread must
wait
> for I/O or something that another thread might be operating.

Because unless
> you have more than one processor, nothing actually happens at the same time,
> just the process's time is divided per thread... am I right on this?
>
> Sorry I don't have the code.. but also wanted to know an answer to my > question about your question. :)
>
> Shane
> "Richard Aubin" <rca_hyip@@hotmail.com> wrote in message
> news:u3**************@TK2MSFTNGP12.phx.gbl...
> > Hello all,
> >
> > I have the following nested loop structure that I would love to

convert
to
> x
> > amount of threads:
> >
> > For i = 0 To 100
> > For j = 0 To 100
> > For k = 0 To 100
> > Console.WriteLine("k = " & k)
> > Next
> > Console.WriteLine("j = " & j)
> > Next
> > Console.WriteLine("i =" & i)
> > Next
> >
> > This process is based on existing code that I have that is taking

well > over
> > 1 hour to complete.
> >
> > Could someone provide me with example code to convert this to
> > multithreading, say 10 threads at once?
> >
> >
>
>



Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0;...
46
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are...
8
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the...
17
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html Why is C# 500% slower than C++ on Nested Loops ??? Will this problem be solved in...
9
by: Javaman59 | last post by:
Using local declarations within a block often makes code more readable, but is it less efficient? eg... void P() { while (...) { int i = ...; bool b = ...; .... } }
6
by: Samuel R. Neff | last post by:
I'm having weird results with a form that is already displayed modally (via ShowDialog) displaying a second form via ShowDialog. The last form is not modal even though it's called with ShowDialog....
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
9
by: jdlists | last post by:
I have inheirted some existing code, that i will explain in a moment, have needed to extend and ultimately should be able to run in threads. I've done a bunch of work with python but very little...
8
by: Nathan Sokalski | last post by:
I have several nested For loops, as follows: For a As Integer = 0 To 255 For b As Integer = 0 To 255 For c As Integer = 0 To 255 If <Boolean ExpressionThen <My CodeElse Exit For Next If Not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.