multithreading - use of a local variable in C# Parallel.For -


i new using parallel.for , stuck on following.

within loop use pointer offset (ipathmatrixoffset) need increase fixed number (nstages) every iteration. after r iterations offset have value r * nstages.

i declare variable inside loop , set r*nstages.

this think not efficient way - performance critical code (that's why using pointer based code here) - want try , see if incrementing nstages @ end of each iteration faster.

but don't know how declare variable local thread , can't figure out msdn.

this must common question ... surely overlooking obvious.

help appreciated.

current code:

parallel.for(0, nstates, r => {     int ipathmatrixoffset;     double local_maxv;      ipathmatrixoffset = r * nstages;      // code, calculates local_maxv      // store result in path matrix     fixed (double* ppathmatrix = &pathmatrix[0, t])     {         *(ppathmatrix + ipathmatrixoffset) = local_maxv;     } }); 

would like:

parallel.for(0, nstates, r => {     double local_maxv;     // code      // store result in path matrix     fixed (double* ppathmatrix = &pahmatrix[0, t])     {         *(ppathmatrix + ipathmatrixoffset) = local_maxv;     }     ipathmatrixoffset += nstages;  }); 


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -