'omp parallel for' construct

General OpenMP discussion

'omp parallel for' construct

Postby el nino » Fri Jun 27, 2008 5:02 pm

Hi i'm currently developing an graphical application and i have a rendering function that loops through all the objects to be rendered and applies various shaders and lighting effects. I was just wondering if this is possible:

#pragma omp parallel for
for (std::vector<RenderObject*>::iterator it = objects.begin(); it < objects.end(); ++it)
{
object = *it;
object->UpdateShader();
if (object->shader == sceneShader || !object->shader)
{
sceneShader->setWorldMatrix(&(object->transformationMatrix));
shm->render(object, sceneShader);
}
else
{
shm->render(object, object->shader);
}
}

i realise that the iterators need to be integers so do i have to attempt to convert the loop variables to use integers or will omp be able to convert the iterators into the required data types(probably not).

If so how would you loop through the various elements of a vector datastructure without using an iterator, and make use of the OMP for construct.

Apologies if this doesn't make sense, i'm a bit of a newb

Thanks in advance


******EDIT************

i replaced the for loop with:

for(int i = 0; i < objects.size(); ++i)
{
object = objects.at(i);

...................

it seems to compile will run it 2mrw.......
el nino
 
Posts: 1
Joined: Fri Jun 27, 2008 4:36 pm

Re: 'omp parallel for' construct

Postby ejd » Fri Jun 27, 2008 7:00 pm

OpenMP V3 allows random access iterators to be parallelized. Unfortunately most vendors are just now implementing this spec. Within the next few months you should start seeing implementations out that support it. Meanwhile you have to do something like what you have in your edit.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am


Return to Using OpenMP

Who is online

Users browsing this forum: Exabot [Bot] and 10 guests