Learning D and implementing a ray/path tracer algorithm to solidify the learning. I would like to cast rays in parallel, so this is currently how I have my outer for-loop parallelized:
auto yRange = new int[](imageHeight);
for (auto i = 0; i < imageHeight; ++i)
{
yRange[i] = i;
}
foreach(ref y; parallel(yRange))
{
// Inner loop and ray casting...
}
So two questions:
- Is there a simpler way to initialize an array in D where each element is the value of its index without using the first for-loop?
- Is there a simpler way to parallelize the for-loop? For example, in C++ I could use OpenMP:
#pragma omp parallel for
for (auto y = 0; y < imageHeight; ++y)
{
// ...
}
Perhaps some way to use a range instead? Something like (syntax obviously wrong)
foreach(ref y; parallel(0..imageHeight))
{
// ...
}
I found a simpler way to create the array from a range:
So that was helpful.