[XviD-devel] hey I'm back :)

Bryan Mayland bmayland at leoninedev.com
Mon Nov 21 17:54:17 CET 2005


Skal wrote:
> yep, sorry i'm late sending you the stuff.
> You can get the code here:
> http://skal.planet-d.net/slave.c
> http://skal.planet-d.net/slave.h
>
>   
    The good news is that I've fixed the deadlock that is in the code I 
sent you earlier, and am getting a much better distribution of 
macroblocks processed per thread: (warning, 2051 pixel wide image)
http://capnbry.net/~bmayland/xvid/xvid-mpme.png
Diff and win32 binary:
http://capnbry.net/~bmayland/xvid/multi.diff
http://capnbry.net/~bmayland/xvid/xvidcoreMP.zip

I guess the big question now is how to best use your abstraction to 
clean up my code. 

Currently in CVS, there is one MotionEstimation(...) function.  In my 
code, I've *copied* the internals of that function into a thread 
function with a basic while(!terminated) loop.  The main thread now puts 
its parameters in variables accessible by the thread, kicks it off, then 
contributes by running its own ME loop.  When out of macroblocks the 
threads rejoin and return from MotionEstimation(...).

I'm thinking the way to do this now would be to remove the entirety of 
the MotionEstimation function into the thread function.  For 
single-threaded execution, the thread function will just call the thread 
function directly.  For multi-threaded execution, I'm leaning towards:
For each thread:
  copy ME()'s parameters into a structure and put it in a ThreadWorkerData
  xvThreadSetTodo(&threadN, threadworkerdataN);
// at this point all threads should be working on ME
For each thread:
  xvThreadSync(&threadN);

Alternatively, we can xvThreadInit numthreads - 1, SetTodo on them and 
call one thread function directly so the main thread is doing more than 
waiting for everyone to finish.  I don't think that would look that bad 
in code, and has the benefit of creating one less thread.

Of course, this starts to be a big mess if you need to set this up 
everywhere you want parallelism.  So what's the better way?  I'm open to 
suggestion before I dig into making my changes.


More information about the XviD-devel mailing list