Notifications
Clear all

[Closed] Multithread in Maxscript

I’m probably going to look into this tomorrow for a bit and see what I can find.

I’m trying to not use the SDK, just normal script, but instance/copy objects as fast as possible. Right now I can do around 1100 a second if all goes well. However i’d like to try and do this faster if possible.

But multi-threading what I have might get to be too hairy code wise, but we’ll see I guess.

If Maxscript only uses 1 core, which I’m pretty sure it does? If I could use 2 or 4 cores, I should potentially be able to create around 4400 objects a second if max allows so. Even if I got a 2-3x increase in speed that would be pretty nice.

If Maxscript only uses 1 core, which I’m pretty sure it does? If I could use 2 or 4 cores…

FAIK maxscript uses only 1 core.
Do not know of a way to make maxscript use more than 1 core (maybe dynamically compiling C# code to do such a thing? denisT -> is that possible?).
Could send data to GPUs, but that won’t help with most operations in max.
Vray, mentalray, and other programs use all the cores, but that is C++ magic.
So, if you can write C++ magic, max can use all cores.

Yeah, that’s kinda of what I figured. I’m learning C#. Maybe I’ll attempt to learn C++ at some point.

 lo1

What do you mean that maxscript is limited to one core? You’ve already shown it can multithread mostly anything using threading.

What do you mean that maxscript is limited to one core? You’ve already shown it can multithread mostly anything using threading.

We can create threads in maxscript all day long, but we are not guaranteed that the operating system will distribute these threads to all the cores to utilize 100% of the processing power of the computer. Check your task manager the next time you’re running a multithreaded script, it won’t display 100% usage, whereas if you render with vray or mental ray, all the cores jump up to 100%. That’s the C++ magic I was referring to. Technically, I can agree that max can use more than one core, but it won’t use 100% of all the cores unless you use C++ magic. I would be happy to be proven wrong.

There is nothing ‘magical’ going on with C++.

 lo1
myThreads = #()

fn doSomeStuff = 
(
	for i = 1 to 10000000 do pi * pi * pi
	print "done"
)

for i = 1 to 8 do
(
	myThreads[i] = dotNetObject "system.componentModel.backgroundWorker"	
	dotnet.addEventHandler myThreads[i] "DoWork" doSomeStuff
	myThreads[i].runWorkerAsync()
)

magical!

lo,

i’m getting different results on my windows7 box:

are you running xp?
my cores don’t pass 50% when processing your example script.
perhaps this is an operating system issue?
Needless to say, your computer does one thing, mine does another.
C’est la vie.

*edit – just noticed you have for i=1 to 8… lemme change that to 4 and see if the cores are used 100%.
*edit – Nope. Hovering around 41% useage now.

 lo1

tested on windows 7:

max 2009 – 100% usage
max 2012 – 25% usage

wtf, autodesk? :shrug:

I tried creating objects in max with your background worker code, similar to how I was doing it before. However, this no longer works and crashes max almost immediately.

Interesting…


 ( --WARNING: THIS WILL CRASH MAX
 	local myThreads = #()
 	fn doSomeStuff = 
 	(
 		with redraw off ( box() )
 		print "done"
 	)
 	for i = 1 to 8 do
 	(
 		myThreads[i] = dotNetObject "system.componentModel.backgroundWorker"	
 		dotnet.addEventHandler myThreads[i] "DoWork" doSomeStuff
 		myThreads[i].runWorkerAsync()
 	)
 )
 

This tells me that the stable creation and modification of objects in max is limited to 1 core.
For code that does not update max’s viewports, multithreading is great and can use (most) of the computer. But, for tasks like rigging, moving, animating, creating, etc… max is limited to 1 core. Again, I would be happy to be proven wrong as that would mean all of my scripts could be refactored to use all cores and would be many times faster. I have no problem with being wrong, and I’m not trying to argue with you lo, just trying to write better, faster code.

Page 2 / 3