Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » Multi-core gaming!

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Multi-core gaming!
Goalie Ca
Member #2,579
July 2002
avatar

Okay.. everyone seems to be getting shiny new computers with dual or quad core. Most allegro games are single core and not exactly taxing modern CPU's.

Nonetheless... one of my research projects may be to create a multi-core model for game programming. I can't say too much (not sure who's IP /what is involved) but the user of the library will certainly have to figure out dependencies between tasks and figure out what tasks in the first place. The library will handle the rest :D

As just a thing of curiosity.. how interested are you "hobbyists" in doing a little extra work needed to exploit multi-core? I figure a lot of you would rather not deal with the complexity and would probably rather just use simple stuff like parallel STL with parallel for loops.

How have you done your multi-core and what sort of library would you like??? Do you even care?

-------------
Bah weep granah weep nini bong!

SiegeLord
Member #7,827
October 2006
avatar

Quote:

I figure a lot of you would rather not deal with the complexity and would probably rather just use simple stuff like parallel STL with parallel for loops.

Simple? Yes. Less effective than more complicated schemes? Unlikely. Many games involve a large number of agents which can trivially be made so that they can do their thing independently of each other, be it AI scripts or physics (depending on the solver), while communicating with each other through some sort of event/message system. That arrangement is trivially simulated using parallel loops.

I personally haven't used any, but OpenMP looks rather nifty. I shall test it out as soon as I can to see if it is as great as it appears.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

BAF
Member #2,981
December 2002
avatar

Most stuff I make isn't complex enough to tax one core, let alone 4.

amber
Member #6,783
January 2006
avatar

Most Allegro games can benefit from dual cores. :)

One CPU to run the obnoxious 100% CPU busy-wait timing loop that seems to pervade Allegro projects, and one for the user to do other stuff on. ;)

Goalie Ca
Member #2,579
July 2002
avatar

Quote:

That arrangement is trivially simulated using parallel loops.

The goal of my project is to never let a core sit idle. It is quite possible using parallel loops that one task simply takes longer than all others. Then you're left with 1 cpu busy and several idling. It is also possible that there are loops with only one or two items in them and they can be run separately from everyone else.

The primary goal is to keep all cpu's as busy as possible.

edit:

Quote:

One CPU to run the obnoxious 100% CPU busy-wait timing loop that seems to pervade Allegro projects, and one for the user to do other stuff on.

Timers Fixed in allegro5 ;)

-------------
Bah weep granah weep nini bong!

Kibiz0r
Member #6,203
September 2005
avatar

I've heard a good model for game programming on multiple threads:

It's basically an event system with a page-flipping analogy.

Using an event system makes "calls" inherently thread-safe because each module can run in its own thread and only has to sync up to the event system.

The page-flipping analogy is a bit more work. Basically, the idea is the put all the game data in one place and have the ability to flip the "game data buffer" so that you're only writing to one at a time. That gives you the ability to read from the last frame and write to the current frame, mostly eliminating the need for locks when doing asynchronous work on the game data.

That doesn't eliminate the case where two threads want to write to the same piece of data, though. The easy way out there is to just make sure that only one thing will be responsible for altering one piece of data.

SiegeLord
Member #7,827
October 2006
avatar

Quote:

It is quite possible using parallel loops that one task simply takes longer than all others.

Perhaps. I would argue that such tasks are rare, and when they do happen they can be internally parallelized themselves. I think regardless of the methodology used, if the types of tasks are constantly being changed the utilization of the cpu can only get so high... in the end the user will have to step in and alter the algorithms as needed.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Goalie Ca
Member #2,579
July 2002
avatar

Well i'm collaborating with one of the large game companies. It was mostly his proposal. I don't know how large games are made but it is quite possible that not a lot is loop based and is quite conditional in execution. That is probably where tasks shine.

-------------
Bah weep granah weep nini bong!

OICW
Member #4,069
November 2003
avatar

Quote:

One CPU to run the obnoxious 100% CPU busy-wait timing loop that seems to pervade Allegro projects

Well if you put a rest() inside it will not eat up 100% of CPU time.

The question is what will be the performance gain on multi-core systems and what will be the performance loss on single core systems.

[My website][CppReference][Pixelate][Allegators worldwide][Who's online]
"Final Fantasy XIV, I feel that anything I could say will be repeating myself, so I'm just gonna express my feelings with a strangled noise from the back of my throat. Graaarghhhh..." - Yahtzee
"Uhm... this is a.cc. Did you honestly think this thread WOULDN'T be derailed and ruined?" - BAF
"You can discuss it, you can dislike it, you can disagree with it, but that's all what you can do with it"

Kibiz0r
Member #6,203
September 2005
avatar

Quote:

I don't know how large games are made

Go buy Game Coding Complete, 2nd Edition.

GullRaDriel
Member #3,861
September 2003
avatar

I am currently writting a multithreaded test that I will put there and in my a.cc members page.

We will see if there are any benefit or not.

EDIT:

Got it baby :-P

The test:
A simple loop with a cireclefill at mouse position
At each loop the program down the color for each pixel

How it works:
Label 1
The main loop post a semaphore for each computing thread
Each thread have a part of the screen to compute
The main loop wait for each thread to post back a semaphore
Goto 1

Results:
1 thread : 18 fps
2 thread : 35 fps

I must close some running apps for the result to be meaningfull. Source / binaries / screenshot will be uploaded after wash ;-) ( me , not the code ;-) )

EDIT:
If someone want to test ( binaries are windows only but it should be easy to compile)
ThreadProcessingSrc
ThreadProcessingWindowsBinaries

Run the program from a command line with the number of thread you want passed as first argument.

Example: t_blur.exe 1

test running:
{"name":"594430","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/a\/aa0f8a954224c267a5fb2b11c83c813b.jpg","w":800,"h":625,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/a\/aa0f8a954224c267a5fb2b11c83c813b"}594430

Hell, that was funny ! :D

EDIT:

Benchmarking without having azureus downloading (still) unlicensed manga in background is better ;-)

Final Results:

1 thread , 19 to 21 Fps
2 thread , 38 to 40 Fps
3 thread , 38 to 40 Fps
...
I got the same result with 50 threads than with 2. There must be some little difference but I do not see it as I used the millisecond part of QueryPerformanceCounter.

For information, the test is running in 32 bit windowed directX mode, and my computer have a core 2 duo @ 2 Ghz, 2 G DDR2 , Geforce 8600 with 512 MB dedicated memory.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Peter Wang
Member #23
April 2000

I didn't read your code, but don't expect any benefit for simple tests like
that. There is nearly no computation going on so all your time will be spent
drawing to the screen, or waiting for the timer. And you can't draw to the
same bitmap from multiple threads concurrently (assuming you are using
Allegro).

edit: ok, I see you are doing some sort of blurring in the threads which could be enough work.

GullRaDriel
Member #3,861
September 2003
avatar

Quote:

And you can't draw to the
same bitmap from multiple threads concurrently (assuming you are using
Allegro).

Could you develop that part, because it is working there ???

I was assuming that putpixel was acting as me doing line[ x + bmp -> h * y] = newcolor.

Perhaps it is really different when using video bitmap, but as I use memory bitmap, what's the heck ?

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Peter Wang
Member #23
April 2000

Well, yes, it happens to work for memory bitmaps, but it's not really supported. For video bitmaps it really won't work (with some drivers).

Forget what I said. I shouldn't reply to posts before my morning coffee.

GullRaDriel
Member #3,861
September 2003
avatar

Don't be so harsh with yourself, Peter. It happens to work because I am lucky and I choosed memory bitmap without thinking at it.

The fact is that I saw the evidence ( memory vs video ) just after reading your previous post ;)

Have a good day Peter, knowing that I am as crappy as you before drinking my morning coffee, it can not be something else than a good day ;-)

EDIT:
I played with the proggy some few hours, and now I have just achieved a software blur (only looking at the four direction around a point).

With 1 thread it is running at:
8 Fps in DirectX Fullscreen 1280x800x32
17 Fps in DirectX Fullscreen 800x600x32
28 Fps in DirectX Fullscreen 640x480x32
119 Fps in DirectX Fullscreen 320x200x32

With 2 thread it is running at:
16 Fps in DirectX Fullscreen 1280x800x32
34 Fps in DirectX Fullscreen 800x600x32
53 Fps in DirectX Fullscreen 640x480x32
201 Fps in DirectX Fullscreen 320x200x32

Rey Brujo was there last evening to make some test, but as he have an old computer, there was no nice result except the fact that the thing was working on his single core processor.

I am thinking of collision management processed the way I did with pixel per pixel effect. If I have enough time under my hands, I will try something.

Edit: Could not resist to post the 320 x 200 shot ;-)
http://www.allegro.cc/files/attachment/594440

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Kibiz0r
Member #6,203
September 2005
avatar

Johan Henriksson
Member #11
April 2000
avatar

I don't think there will be a silver bullet to add parallelism to games same way there is none for programs.

you get a lot of speed out of just parallelizing loops using standard worker threads. plenty of languages can do this more or less automatically for you. common loop structures likewise, mapreduce is one such example. Haskell+extensions can automatically parallelize it (mapreduce is taken from functional programming, time to upgrade guys?).

the problem today isn't parallelizing, the problem is debugging and reasoning about it. this is why if you need really heavy threading then you go for a language meant for it, such as erlang. these also tend to scale better.

GullRaDriel
Member #3,861
September 2003
avatar

Give me some processing loop to optimize using threads! ;-D

Warning: will only work better if multi core/processor is used with héhéhé

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Arthur Kalliokoski
Second in Command
February 2005
avatar

Quote:

Give me some processing loop to optimize using threads!

Make a Mandelbrot set generator where each core does pixel modulo x, like if you have two cores, one core does the even x pixels, and the other does the odd x pixels. Well, since we have SSE now, have one core doing four pixels at once in even rows, and the other the odd rows.

They all watch too much MSNBC... they get ideas.

Johan Henriksson
Member #11
April 2000
avatar

not just focusing on cores, one should also look into the GPU. the memory bandwidth is huge and you don't have any caches so if you have a memory intensive stuff, it's a serious option and cpu's won't be able to match in the near future, no matter how many cores are in there. we're currently playing around with Cuda at work for some image processing and it's easy to learn (but only available for recent hw, use shaders until then)

Goalie Ca
Member #2,579
July 2002
avatar

My understanding is that GPU's do one thing to many pixels.. kinda like SIMD on steroids.

-------------
Bah weep granah weep nini bong!

Johan Henriksson
Member #11
April 2000
avatar

GPUs are vector machines. your own personal cray :) next generation GPUs support libraries like CUDA so you can use it for generic computation. it is not really SIMD, it can do assymetric processing as well. but for the sake of sanity, you keep it mostly symmetric.

prism-urase
Member #9,511
February 2008
avatar

Well, personally, I think that only a fanatic would want to truly tax their CPU with their own programming. Personally I'd want to get as much out of my CPU while using as little of its resources as possible, so unless there's some way using multi-core in an Allegro-made game would enhance gameplay, compatibility, or efficiency, I'd have to go against it.

Economy: It's just an elaborate game. If you have the will, you can win, no matter who you are, unless you're terribly disabled.

GullRaDriel
Member #3,861
September 2003
avatar

Quote:

So unless there's some way using multi-core in an Allegro-made game would enhance gameplay, compatibility, or efficiency, I'd have to go against it.

What about computing things 2x faster ? As in some collision management ? Software graphic effects ?

Well. I think that will start the flame wars, but guys, are you fool enough to spend so much money in dual / quadri core processor without using more than 50% for a dual core and 25% for a quadri core processor ?

In that case stop buying products you are not plenty using !

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Fladimir da Gorf
Member #1,565
October 2001
avatar

I'd say switching to OpenGL will give you a dozen times better and faster results, and isn't nearly as difficult as using a multi-processor environment efficiently.

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

 1   2 


Go to: