Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualic0de

Posted 24 April 2013 - 09:03 PM

I'm trying to make an optimized all software version of an OpenCL based ray-caster that I wrote a while ago and I'm struggling to find an efficient way to manage my threads. 

 

What I want to do is have each thread casting rays into a different slice of the screen and then when they all finish show the rendered screen and repeat. I have a version that works but it is not ideal.

 

This is a slightly simplified version of my current code:

	while(1) //render loop
	{
		for(int i = 0; i < numCpus; i++)
		{
                        //re-create thread
			threads[i] = SDL_CreateThread(drawrange, "", (void*)((i+1)*screen->w/numCpus));
		}

		for(int i = 0; i < numCpus; i++)
		{
			SDL_WaitThread(threads[i], NULL); //wait for thread to finish executing
		}

		SDL_UpdateWindowSurface(mainwindow);
	}

 

This is not ideal because I re-create the thread every time in the loop, which to my knowledge is inefficient. Semaphores, mutexes and the like all seem to try to stop two threads from doing something at the same time, I need to make sure that they do things at the same time. Anyone have an idea for a more efficient solution?

 

Because I only need simple multi-threading and I already use SDL I used SDL's multi-threading api.


#3ic0de

Posted 24 April 2013 - 09:02 PM

I'm trying to make an optimized all software version of an OpenCL based ray-caster that I wrote a while ago and I'm struggling to find an efficient way to manage my threads. 

 

What I want to do is have each thread casting rays into a different slice of the screen and then when they all finish show the rendered screen and repeat. I have a version that works but it is not ideal.

 

This is a slightly simplified version of my current code:

	while(1) //render loop
	{
		for(int i = 0; i < numCpus; i++)
		{
                        //re-create thread
			threads[i] = SDL_CreateThread(drawrange, "", (void*)((i+1)*screen->w/numCpus));
		}

		for(int i = 0; i < numCpus; i++)
		{
			SDL_WaitThread(threads[i], NULL); //wait for thread to finish executing
		}

		SDL_UpdateWindowSurface(mainwindow);
	}

 

This is not ideal because I re-create the thread every time in the loop, which to my knowledge is inefficient. Semaphores, mutexes and the like all seem to try to stop two threads from doing something at the same time, I need to make sure that they do things at the same time. Anyone have an idea for a more efficient solution.


#2ic0de

Posted 24 April 2013 - 09:00 PM

I'm trying to make an optimized all software version of an OpenCL based ray-caster that I wrote a while ago and I'm struggling to find an efficient way to manage my threads. 

 

What I want to do is have each thread casting rays into a different slice of the screen and then when they all finish show the rendered screen and repeat. I have a version that works but it is not ideal.

 

This is a slightly simplified version of my current code:

	while(1) //render loop
	{
		for(int i = 0; i < numCpus; i++)
		{
                        re-create thread
			threads[i] = SDL_CreateThread(drawrange, "", (void*)((i+1)*screen->w/numCpus));
		}

		for(int i = 0; i < numCpus; i++)
		{
			SDL_WaitThread(threads[i], NULL); //wait for thread to finish executing
		}

		SDL_UpdateWindowSurface(mainwindow);
	}

 

This is not ideal because I re-create the thread every time in the loop, which to my knowledge is inefficient. Semaphores, mutexes and the like all seem to try to stop two threads from doing something at the same time, I need to make sure that they do things at the same time. Anyone have an idea for a more efficient solution.


#1ic0de

Posted 24 April 2013 - 08:59 PM

I'm trying to make an optimized all software version of an OpenCL based ray-caster that I wrote a while ago and I'm struggling to find an efficient way to manage my threads. 

 

What I want to do is have each thread casting rays into a different slice of the screen and then when they all finish show the rendered screen and repeat. I have a version that works but it is not ideal.

 

This is a slightly simplified version of my current code:

	while(1) //render loop
	{
		for(int i = 0; i < numCpus; i++)
		{
                        re-create thread
			threads[i] = SDL_CreateThread(drawrange, "", (void*)((i+1)*screen->w/numCpus));
		}

		for(int i = 0; i < numCpus; i++)
		{
			SDL_WaitThread(threads[i], NULL); //wait for thread to finish executing
		}

		SDL_UpdateWindowSurface(mainwindow);
	}

 

This is not ideal because I re-create the thread every time in the loop. Semaphores, mutexes and the like all seem to try to stop two threads from doing something at the same time, I need to make sure that they do things at the same time.

 


PARTNERS