c# - performance of parallel for loop -


this question has answer here:

i need set number of processor's threads parallel "for-loop". want work 3 threads of 8 (4-cores processor) ..... i'm using 8 threads.

        system.threading.tasks.parallel.for(0, exponentstring.length, (i, loopstate) =>         {             int y = my_function (a, exponent[i], modulo);             string str = y.tostring();             if (str == numbers[0])             {                 loopstop = 1;                 loopstate.stop();              }          }); 

thanks ideas.

there overload takes paralleloptions object:

var options = new paralleloptions(); options.maxdegreeofparallelism = 3; parallel.for(0, exponentstring.length, options, (i, loopstate) =>         { ...         }); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -