making parllel for loop with uses of all processor
-
here is my code, word is a string array. i want to convert this code into parllel ,so that i can reduce time and use all processor of my i5 processor system.. for (int i = 0; i < k1; i++) { for (int j = 0; j < k1; j++) { num[j][i] = Convert.ToInt32(words[count]); count++; } } can anyone help me out in this????
-
here is my code, word is a string array. i want to convert this code into parllel ,so that i can reduce time and use all processor of my i5 processor system.. for (int i = 0; i < k1; i++) { for (int j = 0; j < k1; j++) { num[j][i] = Convert.ToInt32(words[count]); count++; } } can anyone help me out in this????
Easiest solution is to convert it to a parallel loop[^], available in .NET 4;
using System;
using System.Threading.Tasks;class Demo
{
int N = 1000;void TestMethod() { Parallel.For(0, N, (i, loopState) => { Console.WriteLine(i); if (i == 100) { loopState.Break(); } }); }
}
If you need more control, you'd typically use a thread[^].
Bastard Programmer from Hell :suss:
-
Easiest solution is to convert it to a parallel loop[^], available in .NET 4;
using System;
using System.Threading.Tasks;class Demo
{
int N = 1000;void TestMethod() { Parallel.For(0, N, (i, loopState) => { Console.WriteLine(i); if (i == 100) { loopState.Break(); } }); }
}
If you need more control, you'd typically use a thread[^].
Bastard Programmer from Hell :suss:
-
I tried this code.. but i m getting high execution time than its sequential code.. and parllel execution should take less execution time than sequential code.. :(
KUNWAR999 wrote:
and parllel execution should take less execution time than sequential code.. :(
..if the problem can be solved using parallel threads, and only when implemented correctly. The example was the easiest method, but it's only a shorthand for a specific type of problem. You can spawn threads[^] to run code concurrently. It's usually the OS that decides on which core the thread runs, but I believe you can set it's affinity.
Bastard Programmer from Hell :suss:
-
KUNWAR999 wrote:
and parllel execution should take less execution time than sequential code.. :(
..if the problem can be solved using parallel threads, and only when implemented correctly. The example was the easiest method, but it's only a shorthand for a specific type of problem. You can spawn threads[^] to run code concurrently. It's usually the OS that decides on which core the thread runs, but I believe you can set it's affinity.
Bastard Programmer from Hell :suss:
-
i hv tried it one more way as using #pragma omp parllel .. but vs2010 saying that its unrecognized concept.. actually i am avoiding using threads because i want to use parllel processing in processor directly.. :(