The artifacts in the left image are randomly placed each run, and with varying degrees of severity.
The code behind my for-loop is pretty straightforward:
Color[] noisegen(Racket.Module basis)
{
Color[] ret = new Color[col.Length];
int colx, coly;
//sequential
float d;
for (int i = 0; i < col.Length; i++)
{
colx = i % img.Width;
coly = i / img.Width;
d = (float)(basis.Get((colx + xtrans) / (double)img.Width, (coly + ytrans) / (double)img.Width));
ret = new Color(d, d, d);
}
//end-sequential
//Parallel.For(0, col.Length, (i) =>
//{
// float d;
// colx = i % img.Width;
// coly = i / img.Width;
// d = (float)(basis.Get((colx + xtrans) / (double)img.Width, (coly + ytrans) / (double)img.Width));
// ret = new Color(d, d, d);
//});
return ret;
}
I'm not going to post the actual perlin noise function (noted here as basis.Get(...) ) for space economy reasons, but I'm pretty sure it's pure functional. It's pretty much a facelift of Perlin's "improved" 2002 implementation.
I really have no idea what's going on when I use my parallel implementation instead of my sequential one. Is it that the function is returning before some of the threads finish execution? Are parallel for loops not guaranteed to evaluate everything? I feel like I'm missing something very simple.