Can the metaball generator system be parallelized?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
tcdoe
Posts: 0
Joined: Wed Aug 07, 2013 6:57 pm

Can the metaball generator system be parallelized?

Post by tcdoe »

Hi All,
Sorry if this is not the place to ask this question, I'm new to these forums and if anyone could suggest a better place to ask, thanks.

I've written a Python script to build complex 'molecule-like' structures using thousands of metaballs. It works, but it's pretty slow (One trick that I've figured out to speed it up is to set the metaball's UPDATE property to 'NEVER', and then after the script is finished switch the base metaball to ALWAYS. This results in about 50x speedup).

It still takes about 5-30 min to generate a 2000 element structure, which is too slow for my goals (adaptive structures).

Why am I using metaballs? Well, I've tried to use boolean operations to 'join' standard mesh objects (mostly capsules and spheres) but the overall topology is very complex and boolean operations often fail. It's also slow that way anyhow (but since i'm a noob there may be something i'm missing...). For now the metaballs work.

I'm running 2x Intel Xeon E5-2690 processors so I have 16 cores to work with.

My question is: can the metaball generation be parallelized in some fashion within the Python script? Right now i'm just looping over all locations and adding metaballs 'one-by-one'. It would be awesome if I could at least vectorize this and add them 16 at a time.

I'm kind of new to Python so maybe this is either simple or totally impossible... I don't want to beat my head against something if it's 'impossible'.

Any info or suggestions are greatly appreciated!
best,
tcdoe

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX »

python itself runs on a single virtual core, unless you use threading or the multiprocessing module. But blender doesn't really support threaded python, see

http://www.blender.org/documentation/bl ... ing-module

Furthermore, metaballs are currently not thread-safe, you couldn't even parallize in C (afaik sergey is working on it in his GSoC project, not sure what changes to expect eventually).
I'm sitting, waiting, wishing, building Blender in superstition...

stiv
Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv »

No idea if this applies here, but whenever you can, it helps to replace loops with comprehensions.

The other standard way to speed up Python code is to write an extension in C/C++ to do the heavy lifting. Oftentimes, the code has some small section that accounts for most of the execution time.

tcdoe
Posts: 0
Joined: Wed Aug 07, 2013 6:57 pm

Thanks. I'm trying some 'brute force' ideas...

Post by tcdoe »

Thanks very much for the replies.

So I'm trying a 'brute force' approach where I'm have a 'master' script that subdivides the original wireframe into relevent sub-objects and run them in independent blender 'instances'.

Then I have to write a script to 'combine' all the separate results. I hope it works.

thanks again,
t.

Post Reply