Jump to content
  • Advertisement
Sign in to follow this  
coderWalker

Splitting the program

This topic is 2757 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am making a game with an engine simular to the Minecraft Engine:
bug5.png

I am currently trying to implement threads to get better performance.
(I have a Phenom II x4) So my goal is to have at-least 4 threads with a target of 6 threads. Seeing as each core i only 550Mhz and that's not really a lot.
Right now I have 2 threads (that are not efficient at all).
Thread0 is the main thread running the game.
Thread1 is a loader thread. When a Chunk (16x16x16 of blocks) needs to be loaded it adds it coordinates to an array and it loads it. Then Thread0 later gets the pointer.
However I am still getting some in game lag. This has to be because it takes time to add it to the array.
I have heard it's easier to use threads when you have your program separated from the beginning and adding them in is difficult.

If I understand correctly the way for the threads to be fastest is to keep thier resources Seperated and use the least amount of Mutex's possible.

How would you divide the program?

Just a thought, should I move all the map functions dealing with the chunk pointers to thread1? It could load the chunks make the pointers and add them to the array. I will need 1 mutex though when changing the array.

Is a thread pool a good idea? Is that defeating the purpose of simultaneously multitasking? Would that require alot of mutex's?

I now have this working for the first time (well kinda) it's going to kill me to change it after I finally got it working, however I know it's worth-it for speed.

Share this post


Link to post
Share on other sites
Advertisement
I doubt your cores run at 550 MHz. All the cores run at the processors max speed. As for your question, there are a couple of ways you can thread your program. One way is similar to what you are doing. Each thread has a single purpose, unique from the others. This is probably the most difficult to get a performance benefit from because rarely are you going to have two unique tasks taking the same amount of time. A second way is to split up individual tasks that can be parallelized. For example, if all of your objects need to be transformed, assign half of the work to one thread, and half to the other. This method also scales easier.

In your code, you say you are adding your objects to an array. That can be dangerous because if the array needs to expand, it needs to copy a large amount of memory. Perhaps you should try using a linked list.

Share this post


Link to post
Share on other sites

I doubt your cores run at 550 MHz. All the cores run at the processors max speed. As for your question, there are a couple of ways you can thread your program. One way is similar to what you are doing. Each thread has a single purpose, unique from the others. This is probably the most difficult to get a performance benefit from because rarely are you going to have two unique tasks taking the same amount of time. A second way is to split up individual tasks that can be parallelized. For example, if all of your objects need to be transformed, assign half of the work to one thread, and half to the other. This method also scales easier.

In your code, you say you are adding your objects to an array. That can be dangerous because if the array needs to expand, it needs to copy a large amount of memory. Perhaps you should try using a linked list.


I have a AMD Phenom II x4 2.2Ghz doesn't that mean 2.2Ghz/4 = 550Mhz per core?

Share this post


Link to post
Share on other sites


I have a AMD Phenom II x4 2.2Ghz doesn't that mean 2.2Ghz/4 = 550Mhz per core?


No, it doesn't mean this. You have 4 cores running at 2.2 GHz each of them.
A CPU with just 550 MHz on each core would be very slow in application which don't use multithreading. Well, it would probably be also very slow in applications using multithreading :D

Share this post


Link to post
Share on other sites

[quote name='coderWalker' timestamp='1299342647' post='4782091']
I have a AMD Phenom II x4 2.2Ghz doesn't that mean 2.2Ghz/4 = 550Mhz per core?


No, it doesn't mean this. You have 4 cores running at 2.2 GHz each of them.
A CPU with just 550 MHz on each core would be very slow in application which don't use multithreading. Well, it would probably be also very slow in applications using multithreading :D
[/quote]

Does that mean if I use 4 threads I will have 8.8Ghz of power?

Share this post


Link to post
Share on other sites
The simple answer is yes, if all three cores are maxed out. You may want to avoid using up all the processing of all the cores because there are other things the computer needs to run.

Share this post


Link to post
Share on other sites
What about a htread pool? I've never tried it but its my understandign that you split up tasks into processes. When a process needs to be done you request a thread from the pool and away it goes. That way you aren't limitting one thread to one type of task (rather just using them for anything that needs to be done as and when). I hear this method scales well with more cores (your target of 6) with no extra effort. The pool size is that of your cores so you'd set it to 2 or 4 or 6 and so on.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!