I have two questions about paralel.for
I got to explain them by code
points[x,y];
maxX=100;maxY=250;
paralel.for (0,maxX,x =>{
for(int y=0,y<maxY,y++)
{
if (points [x,y]==0) {points[x,y]=10;
}
}
In above a paralel.for is accessing an array that lives outside the loop.
I it is 100% sure that the paralel.for loop will do all points in a some random order, ea never will the same point be in use allready. However since the variable was existing before the paralel.for i wonder if it is problematic, maybe causing threads waiting on eachother. I had read something about atomic writes, but not sure if that is a problem here. So i wonder if above code should be written differently ea a beter way to include variables that lives outside its scope.
Another question i have about paralel.for
in above code after the paralel.for a 'normal' for loop for Y happens.
Although i'm still a bit troubled about passing trough variables (ea atomic and treath locks).. I think with proper code it could have nested paralel.for
But, in that it would create 100x 250 "tasks" to do. Is dat fine for a computer or isnt that a good idea. I saw some implementation where people used the number of cores. But the inner calculation in those loops might not require an equal time, and in that case using the available core numbers, could left one CPU calculate a lot longer then the others and cause slow code. So i wonder whats best ?