Author Topic: Priority Affinity switch  (Read 11361 times)

2015-09-03, 14:23:49

Nik

  • Active Users
  • **
  • Posts: 167
    • View Profile
    • HQ Details
Download script

Hi, guys. Maybe somebody will find my small script useful.

Button on the toolbar:
Enabled - 3dsmax priority low, affinity -1 core
Disabled - 3dsmax proirity normal, affinity max

Drag in viewport to install. Check NikScripts category - Priority Switch and add it to toolbar.

« Last Edit: 2016-02-04, 19:45:13 by nik684 »

2015-09-03, 15:29:48
Reply #1

atelieryork

  • Active Users
  • **
  • Posts: 283
    • View Profile
    • Atelier York
Thanks! One issue - once I enable it, it works, but then if I press it again it doesn't go back to full affinity. It seems locked.
Alex York
Atelier York
www.atelieryork.co.uk
max 2016 sp1, corona 1.3 final, win 8.1. pro

2015-09-03, 15:32:56
Reply #2

Nik

  • Active Users
  • **
  • Posts: 167
    • View Profile
    • HQ Details
Can you send me sysinfo.systemAffinity answer in the Listener?
F11 -> sysinfo.systemAffinity -> copy next string

2015-09-03, 15:35:59
Reply #3

atelieryork

  • Active Users
  • **
  • Posts: 283
    • View Profile
    • Atelier York
281474976710655P
Alex York
Atelier York
www.atelieryork.co.uk
max 2016 sp1, corona 1.3 final, win 8.1. pro

2015-09-03, 16:46:43
Reply #4

Nik

  • Active Users
  • **
  • Posts: 167
    • View Profile
    • HQ Details
Can somebody explain me how to control CPU cores via maxscript when I got >32 cores?
It seems there is a bug and maximum cores that "sysinfo.processAffinity" can handle is 32...

2015-09-03, 17:19:37
Reply #5

Ondra

  • Administrator
  • Active Users
  • *****
  • Posts: 9048
  • Turning coffee to features since 2009
    • View Profile
I dont know about maxscript, but in C there is separate method for using more than 64 cores, available only in windows 7 and newer OS.
Rendering is magic.How to get minidumps for crashed/frozen 3ds Max | Sorry for short replies, brief responses = more time to develop Corona ;)

2015-09-03, 17:33:16
Reply #6

Nik

  • Active Users
  • **
  • Posts: 167
    • View Profile
    • HQ Details
Google and MaxScript documentation doesn't helped too much. I hope somebody will able to help me here.

Thanks for answer, Ondra. Can you please explain why Corona behaves so strange when I use "# of threads" feature?
If I set it to 1 then one thread must render my scene at full speed, and other threads must be free. This is how TaskManager Affinity behaves.
But Corona let all cores render, and total CPU loading is something about 13%. So it doesn't free threads? It just controls cpu loading?
Look at the attached screenshot. All cores are busy, but loading isn't full, it's kinda float in time. TaskMan shows total cpu load as 11-13%

2015-09-03, 22:08:51
Reply #7

Ondra

  • Administrator
  • Active Users
  • *****
  • Posts: 9048
  • Turning coffee to features since 2009
    • View Profile
You are confusing threads and cores. You typically have around 8 cores, and each one can run just one thread at single time. If an application spawns several threads, these are either waiting on something (such as user input), or want to run (e.g. render something). All runnable threads in the whole system - from all applications - compete for the fixed number of cores to run on. There are hundreds or thousands of threads, but most of them are waiting most of the time. If there are more threads that want to run than number of cores, then the threads take turns in running - 8 run at the same time, others wait and replace them after few milliseconds (200 by default in windows)

Setting number of threads to 1 makes Corona do heavy lifting (= rendering calculation) in just one thread. The operating system is free to schedule this one thread to run on any CPU core, and it usually periodically moves the thread around all available cores. You dont want to have only one CPU core to run all singlethreaded applications, as it could cause problems with for example overheating one part of the CPU die.

You can artificially limit which CPU core can each thread run on, but trust me, you dont want to do it - operating system does much better job at scheduling than you could do. If you limit Corona to just one specific core, and that core is not available, then it will have to wait, and you will lose performance
Rendering is magic.How to get minidumps for crashed/frozen 3ds Max | Sorry for short replies, brief responses = more time to develop Corona ;)

2015-09-03, 22:26:34
Reply #8

Nik

  • Active Users
  • **
  • Posts: 167
    • View Profile
    • HQ Details
I need to read this answer 3-4 times to totally understand it, and I will :) I know that threads != cores, but I didn't know what exactly the thread is. Thanks.
So maybe I don't need to change Affinity in this primitive manner. Maybe you can make ".system_numThreads" accessible during render? Because now changing this value while rendering doesn't change anything until I restart render.

Unfortunately Corona hangs other software while rendering, despite 3dsmax low priority and ".system_lowThreadPriority = true". Affinity "-1 thread" solves this problem very well for me.

2015-09-03, 22:39:54
Reply #9

Ondra

  • Administrator
  • Active Users
  • *****
  • Posts: 9048
  • Turning coffee to features since 2009
    • View Profile
Think of it as workers vs. workstations - an office has fixed number of seats, but variable number of people can come on each day. If too many come - some will have to wait for their turn (200 milliseconds), kick somebody out, and take his seat ;). If for some reason you forbid 2 people from sitting anywhere but 1 seat, they will have to fight for it even if other seats are empty - so you dont limit thread affinity ;)
Rendering is magic.How to get minidumps for crashed/frozen 3ds Max | Sorry for short replies, brief responses = more time to develop Corona ;)

2015-09-03, 23:00:41
Reply #10

Nik

  • Active Users
  • **
  • Posts: 167
    • View Profile
    • HQ Details
My example with only 1 thread was a mistake. I'm not insane and usually reserve only "one seat" for chrome + photoshop + ae etc :) It's enough.
Of course I don't want exactly 1 seat, but it seems Corona is a hardworker and she REALLY doesn't want to share any seat, she needs all of them! :) I like her aspiration to make render faster, but sometimes when I render I need to do something else. But not all the time. And I don't know when :) And then again I want to render as fast as she can. So, when I need one seat - I change affinity in taskmanager because she doesn't care about low priority. Kicking Corona off the seat is ok, but I need 5 clicks every time. Well, now I got script for myself. But it doesn't work on Xeons. I'm not sure I'm able to fix it.

Thats why I request a little feature - interactive "# of thread" while rendering. If it's possible of course.

P.S. You know, many people decrease affinity for Corona. I know that from forums.

2015-09-03, 23:12:47
Reply #11

romullus

  • Global Moderator
  • Active Users
  • ****
  • Posts: 8779
  • Let's move this topic, shall we?
    • View Profile
    • My Models
In my experience more often than not Corona behaves very nicely under low priority. Sometimes i even don't notice that rendering is going on. But there is times when it's really CPU hungry and makes working with pc nearly impossible. Not sure what causes this, maybe constant build change?
I'm not Corona Team member. Everything i say, is my personal opinion only.
My Models | My Videos | My Pictures

2015-09-04, 00:00:11
Reply #12

Ondra

  • Administrator
  • Active Users
  • *****
  • Posts: 9048
  • Turning coffee to features since 2009
    • View Profile
it may not work on xeon because they use hyperthreading, which allows 2 threads to share 1 core. It reports as 2 separate cores ("logical cores"), but if 1 is busy, the second one will get slower because it shares some stuff.
Rendering is magic.How to get minidumps for crashed/frozen 3ds Max | Sorry for short replies, brief responses = more time to develop Corona ;)

2015-09-04, 11:56:12
Reply #13

Nik

  • Active Users
  • **
  • Posts: 167
    • View Profile
    • HQ Details
I posted script on Scriptspot to find people who can help me. If somebody have idea how to fix this bug - please leave comments there.
http://www.scriptspot.com/3ds-max/scripts/affinity-priority-switch

2015-09-11, 13:31:37
Reply #14

Nik

  • Active Users
  • **
  • Posts: 167
    • View Profile
    • HQ Details
I fixed script and now it must work on >32 threads PC.
There was a bug in maxscript so I've used dotnet to control Affinity. Please try and tell me if bug is still there.