Jump to content
Sign in to follow this  

Setting Affinity.

Recommended Posts


Hello everyone,

I have a question. I've been trying to figure out how to make a script to set affinity. I've searched the forums and google for examples and have found a few but something is always missing or not working in every script.

I have a quad core processor (1 physical cpu with 4 cores).

I am trying to get my encoder to automatically map the cpu's based on how many instances are running.

I.E 1 instance = 4 cores, 2 instances = 1 cores 1 and 2, 2 cores 3 and 4.

I saw one that script that had an example for x264 but I changed the executable to HCenc_023.exe and it didn't work.

I saw a more universal script that uses asm.au3 but when I run it, I get asm.au3 not found, I checked the include script and it was not present. A google search for asm.au3 sends me to a million different places. Even adding download to the search still returned useless results.

Any help would be greatly appreciated.

I can answer any questions if you need more information. Thank you very much!


Share this post

Link to post
Share on other sites

Here's the script I am using. Thank you to Mr. Robert Walker for getting me halfway there.

#cs ----------------------------------------------------------------------------

AutoIt Version:
Author: Robert Walker

Script Function:
Multicore auto-task assigner

#ce ----------------------------------------------------------------------------

#Include <WinAPI.au3>

Const $c_H_executable="x264.exe"
Global $a_x264_PID_list, $h_x264

While 1

$a_x264_PID_list = ProcessList ($c_x264_executable)

Switch $a_x264_PID_list[0][0]
Case 1
$h_x264 = _WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION+$PROCESS_SET_INFORMATION, False, $a_x264_PID_list[1][1])
_WinAPI_SetProcessAffinityMask($h_x264, 0x03)
Case 2
$h_x264 = _WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION+$PROCESS_SET_INFORMATION, False, $a_x264_PID_list[1][1])
_WinAPI_SetProcessAffinityMask($h_x264, 0x01)
$h_x264 = _WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION+$PROCESS_SET_INFORMATION, False, $a_x264_PID_list[2][1])
_WinAPI_SetProcessAffinityMask($h_x264, 0x02)


My problem is when I change x264.exe to HCenc_023.exe I get an error.

Line 23 (File "C:\vidtools\New AutoIt v3.script.au3"
$h_x264=_WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION+$PROCESS_SET_INFORMATION, False, $a_x264_PID_list[1][1])

Error: Variable used without being declared

I only changed the exe name to match that of the encoder I am using, I did no touch any variables or change any other x264 instances in fear of breaking something (which I apparently already did just by changing the name of the executable)

I hope this offers more help.


Share this post

Link to post
Share on other sites

You are missing:

#Include <Constants.au3>

OMG! that was so simple and fixed it!. Thank you so much. I think I would have abandoned the entire thing from my lack of understanding.

Thank you again!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this