Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 19 loops in amy app

and 18 levels of nesting. and every loop itrates 100 times;

it aproximately does 100 raised to the power 19.



it takes a very long time to perform such operation.
can we make it faster by doing simple multi-threading !! :confused:


Thanks & Regards
Nakul Kundra
9999788629
Posted
Comments
LittleYellowBird 12-Oct-10 11:41am    
Hi, If I understand you correctly it does the loop 19 times and that is repeated 100 times. Nesting does not come into it. So that is only 1900 times not 100 to the power of 19? 100 to the power of 19 is a very big number! Perhaps you need to check your figures it might not be repeating as often as you think. :)
nakulkundra 12-Oct-10 13:08pm    
no its 100 to the power of 19

10000000000000000000000000000000000000
much and it takes 6hrs to do so
shakil0304003 12-Oct-10 14:22pm    
I think it is impossible to execute 10000000000000000000000000000000000000
loop in 6 hours. you can try by a simple code
for(long i=0;i<10000000000;i++)
for(long j=0;j<10000000000;j++)
{}
this codes complexity is less then your complexity & this code can not execute with in 6 hours, i think ;)

18 levels of nesting. and every loop itrates 100 times; it can not be solved by multi-threading. It is also hard to solve in parallel processors because every loop dependent on another loop. In parallel processing you can process independent process parallel but dependent process can not execute parallel. And now your complexity is 100^18 = 10^19, if you will able to do it in parallel processing then to execute it in one sec you have to need 1000000000000 parallel processor. If you want to execute it in one month then you have to need 385802 parallel processors. So, i think you have to minimize the loops, there is no other option ;)
 
Share this answer
 
Comments
Keith Barrow 12-Oct-10 17:06pm    
My vote of 1:
"18 levels of nesting. and every loop itrates 100 times; it can not be solved by multi-threading."
Not true. He doesn't say what is being processed, if it is an "embarrassingly parallel" process, it can be. If he has 4 cores, then he will divide his process time by ~ 1/4. He *should* sort out the nesting, but parallelism can (but not necessarily will) help.
shakil0304003 12-Oct-10 23:33pm    
likely 100000000 operations can be work in 1 sec. he needs 10^19 operation, so it should be need 100000000000 sec, but he said that it takes 6 hours, i think by some reason, his program crashed after 6 hour. I think it may be for his memory, he stored all the data. now, by your say, if i divide the process time 1/4 then it will take 25000000000 sec, which also not physible.
Firstly, there is a good chance that you are doing something wrong if you have such deep nesting. Have a look at your algorithm to see if there is anything you can do to factor these out first.

Then you should look at the followings MS PDF document. It outlines solutions to various parallel problems, using the new additions in .net 4.0 to support the same.

http://download.microsoft.com/download/3/4/D/34D13993-2132-4E04-AE48-53D3150057BD/Patterns_of_Parallel_Programming_CSharp.pd[^]
 
Share this answer
 
Comments
nakulkundra 12-Oct-10 13:32pm    
I am using a loop to print all the possible combinations of ASCI 33 to 126
with 19 size of array.

what can be the simpler or faster way
nakulkundra 12-Oct-10 13:33pm    
I mean with max size 19 of array,
it starts from 1, then two then 3...
Here's one approach.

Start a thread that processes from each end of the arrays, and two more that start at the center of the arrays. Eventaully each pair od threads should intersect. It would take 1/4 of the time to process the arrays.
 
Share this answer
 
You can actually look at running loops on parallel processors (if this is supported in the framework you use) - see http://blog.robvolk.com/2009/06/parallel-foreach-loop-in-c-35.html[^].
 
Share this answer
 
Comments
nakulkundra 12-Oct-10 13:09pm    
no i dnt have parallel processors

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900