471,071 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 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 1664
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Martin Schou | last post: by
46 posts views Thread by Neptune | last post: by
9 posts views Thread by Javaman59 | last post: by
9 posts views Thread by jdlists | last post: by
8 posts views Thread by Nathan Sokalski | last post: by
reply views Thread by leo001 | last post: by

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.