Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

3D Studio keeps resetting CPU Affinity

3D Studio keeps resetting CPU Affinity

Rob_J_
Advocate Advocate
5,458 Views
20 Replies
Message 1 of 21

3D Studio keeps resetting CPU Affinity

Rob_J_
Advocate
Advocate

Hello,

I need to continue to work in another program while rendering test images from scenes in 3d Studio.  So for years I have always used windows task manager to set the affinity of the cores that 3d Studio was allowed to use.  Usually freeing up 2 cores allowed me to continue with other work.  Recently I have noticed that 2018 keeps turning those cores back on.  The only difference that has occurred lately was the installation of a 3rd party plugin for rendering (V-Ray 3.6)

 

Any thoughts on how to keep those cores turned off?  And thanks to the industry, uninstalling the render engine is not an option.

0 Likes
5,459 Views
20 Replies
Replies (20)
Message 2 of 21

-niels-
Mentor
Mentor
I've noticed this too... what i've found is that it resets every time i open a new render window (production or activeshade).
As long as i keep the same renderwindow open it stays at the amount of cores i set.
This is with Arnold, but i suspect the render engine doesn't matter for the behavior.

Not sure what would happen if you render more then 1 frame though... worst case it resets for each frame...

Niels van der Veer
Inventor professional user & 3DS Max enthusiast
Vault professional user/manager
The Netherlands

0 Likes
Message 3 of 21

Rob_J_
Advocate
Advocate

I notice it has also done it after an autosave and the programs opened windows refresh.

0 Likes
Message 4 of 21

Anonymous
Not applicable

I started playing around with Arnold in 3ds Max 2018 and I have a new PC i7-7700 CPU 4.2 GHZ, 32 Gig Mem, 64-Bit Windows 10 Pro.

 

Every time I open 3ds Max it defaults to all 8 processors when performing an Arnold Render. I also use Task Manager to set the Affinity to exclude the first processor of Zero to assist with it locking up my pc periodically when using All processors.  Sometimes, it seems like it is locked up but then if you wait a few minutes it then unfreezes but it makes performing other tasks like browsing internet, etc difficult to do.  

 

I would like to know if there is a permanent place I can set the affinity using some kind of Arnold Render CPU Options within 3ds Studio Max vs using the Task Manager each time?

0 Likes
Message 5 of 21

Anonymous
Not applicable

Okay, I found out where to set the CPU Core Affinity, Aka Threads, when using the Arnold Renderer.

 

Render Setup:Arnold Window

System > Threads > Deselect 'Autodect Threads' > Change 'Threads' to a negative number to specify the number of CPU Cores(Threads) you don't want used. E.g. -1 would mean use all CPU Cores(Threads) except 1. 

 

Observations

  • The affinity in Task Manager will probably show all cores still being used on the Details tab, which is weird.
  • I noticed on the Performance Tab in Task Manager that it fluctuates around 92-100% utilization when this is done.  It spikes back and forth. So, I guess it still really doesn't solve the problem of reaching 100% utilization every now and then.

 

 

Message 6 of 21

spacefrog_
Advisor
Advisor

Newer versions of current renderers tend to control the affinity mask they run on by themself internally. Most prominently Arnold and latest Vray versions do that. I stumbled over this because of userreports that even my automatic cpu controlling script PowerCoretools ( free on scriptsport ) can't control the cpu affinity any longer: it simply gets changed back to all processor cores as soon the renderers kick in

AFAIK vray provides an environment variable VRAY_NUM_THREADS which you can set to limit the used threads/core for rendering, Arnold provides a setting in the renderer's System tab. I haven't experiemented with  those settings by myself though, and in the case of Arnold i don't know if this setting will stick with the Max scene or with the machine ( which would make more sense of course )


Josef Wienerroither
Software Developer & 3d Artist Hybrid
Message 7 of 21

Anonymous
Not applicable

Hi,

 

this has been marked as solved, but I don't know what to do (or where to do it) with the vray variable mentioned. Our company renders with max 2018 and latest vray on windows 10 machines, and all of them have the problem of renders "hanging" the entire computer because of the affinity issue. It's super annoying and I can't find a fix anywhere online. There's a discussion about this on the Chaosgroup forum that leads nowhere either. 

 

So is this an 3ds max or Vray issue, and what is/are the solution(s)? Any scripts floating around or third party software or windows 10 settings? 

 

kind regards

0 Likes
Message 8 of 21

spacefrog_
Advisor
Advisor

Remark: the following is not really tested, the idea just sprung to my mind after reading your previous post

 

Anyways:

AFAIK vray makes use of an env variable called VRAY_NUM_THREADS ( if it exists) to limit the used cores during rendering.

 

So running the following command ONCE  in a Command prompt ( as administrator) on a machine would PERSISTENTLY limit the number of cores used by Vray during rendering to EXACTLY ONE CORE LESS then the actual cores existing on that specific  machine

 


set /a CORE_COUNT=%NUMBER_OF_PROCESSORS%-1 | setx /M VRAY_NUM_THREADS %CORE_COUNT%

You should restart 3ds Max or the Vray spawner to make use of that environment variable

 

Would be great if you could report back success or fail if you test this on your machines 😉


Josef Wienerroither
Software Developer & 3d Artist Hybrid
0 Likes
Message 9 of 21

Anonymous
Not applicable

I appreciate your fast and smart reply! It didn't work though.

I did reboot my system after succesfully doing that powershell command... Maybe I should do the command each time I startup or something? I rebooted the entire computer because I wasn't sure what exactly has to be rebooted (vray spawner is this just killing the proces somewhere?) 

 

I monitored all the cores and it still uses every single one of them and the computer still hangs...

0 Likes
Message 10 of 21

spacefrog_
Advisor
Advisor

ah - yeah sorry - seems the combined command in one line does'nt really succeed in setting the final env correctly

So simply splitting the command again into two lines would succeed ( i hope ;- ))

 

set /a CORE_COUNT=%NUMBER_OF_PROCESSORS%-1
setx /M VRAY_NUM_THREADS %CORE_COUNT%

 

to check the limiting env variable, you could simply type 

 

echo %VRAY_NUM_THREADS%

 and if would give you the specified number of cores used for vray rendering ( if it just prints out %VRAY_NUM_THREADS% the environment variable does'nt exist)

 

PS: too bad that i can't edit my previous reply to correct my error, such a silly limitation of this community board !


Josef Wienerroither
Software Developer & 3d Artist Hybrid
0 Likes
Message 11 of 21

Anonymous
Not applicable

Hi,

 

It does indeed just print out %VRAY_NUM_THREADS% when echoing. Tested it again and still uses all cores. 

 

From the chaosgroup documentation: "VRAY_NUM_THREADS – Manually set the number of computation threads. By default (when "Max Render Threads" is 0) V-Ray creates one computational thread per CPU core."

 

That makes it sound like there's a difference between threads and cores, and there could be more than one thread for one core. (That may sound incredibly stupid, I have no real idea what I'm talking about). So in that case it would make sense that altering the num_threads doesn't change the fact that it uses all cores...

0 Likes
Message 12 of 21

spacefrog_
Advisor
Advisor

adrian:

i just tested this and for me it works. on my 12 core system i used

 

setsetx /M VRAY_NUM_THREADS 6

 

and  after that rendering using vray inside of 3ds max uses only 50% of total CPU. But it seems that it does not exclude cores completely but shifts thread accross the total available cores as it likes. So each cores gets used, but total CPU usage still is only 50 %.

It simple uses some kind of more intelligent scheduling than locking out specific cores completely ( what affinity mask would do )


Josef Wienerroither
Software Developer & 3d Artist Hybrid
0 Likes
Message 13 of 21

Anonymous
Not applicable

50% CPU usage sounds a lot like double render times to me. Or am I not understanding that the righ way? We work on 12-core systems too, I don't want to destabilize the system by trying out some code I wrote myself, but if I would set the vray_num_threads to 10 in stead of 6, would you have around 80% CPU usage? In that case just setting it to 11 manually would get the most out of my cpu without locking up my pc. But that's just the same code as you previously suggested right? 

0 Likes
Message 14 of 21

spacefrog_
Advisor
Advisor

I explicitly limited the numbers of cores for vray to 6 in my previous test ( read it carefully again ). And as i have a 12 core system, this is means exactly 50% of cpu resources allocated to vray, and during rendering this is also exactly the cpu usage shown

So this proves that the environment variable works

 

If i would set my env variable to 11, ( one less than my actual core count ), the CPU usage while rendering would of course show the according percentage ( which would be  %91.67  )


Josef Wienerroither
Software Developer & 3d Artist Hybrid
Message 15 of 21

Anonymous
Not applicable

First of all, I really appreciate your help. 

 

Your code started with "setsetx", I assumed this was wrong since this throws me an error in powershell. I replaced it by setx and set the cores to 11. This doesn't give me 91% as would seem logic. It gives me exactly 50% CPU and I can see the "last" 6 cores not getting used at all. 

0 Likes
Message 16 of 21

Diffus3d
Advisor
Advisor

As a long time Vray user, it's Vray that is turning those back on.  There is a forum thread over at Chaosgroup where you can get an environment variable to re-enable it.  Vlado explains why this was necessary in the thread.  I believe it is this thread here.  Another forum thread here.  

 

Best Regards,

Alfred

0 Likes
Message 17 of 21

Anonymous
Not applicable

I haven't had the problem for a while now, and I used this code:

 

setx /M VRAY_NUM_THREADS 23

 

Is there any logical explanation why this works? I definitely am on a 12-core system, setting the value to '11' gave me 50% CPU usage. Setting it at 23, like now, gives me 100% CPU-usage, but without the occasional hanging of the system. 

I'm probably gonna roll this out to other systems later this week, unless someone might see an issue with this  solution?  

0 Likes
Message 18 of 21

Diffus3d
Advisor
Advisor

Hello @Anonymous,

 

I'm not 100% sure but I'm thinking that since you are using hyperthreading (or w/e the AMD equivalent is) your # of threads is doubled.  By setting 23 you are telling 1 processor not to hyperthread on the current job which frees it up for OS tasks and things.  I used to do that with set affinity back when that was a viable option with the same result.  Now though it does require the env variable.  Glad it's working for you though!

 

Shouldn't be much of an issue but your render times might be a little slower, nothing to complain about.  

 

Best Regards,

Alfred

0 Likes
Message 19 of 21

dbhinnant
Advocate
Advocate

Does checking "Low thread priority" in the Vray advanced settings accomplish the same thing?

0 Likes
Message 20 of 21

Anonymous
Not applicable

"...Is there any logical explanation why this works? I definitely am on a 12-core system, setting the value to '11' gave me 50% CPU usage. Setting it at 23, like now, gives me 100% CPU-usage, but without the occasional hanging of the system."

 

If you have 12 cores you have 24 threads, and the second number is what matters for vray.

0 Likes