Jump to content

Running a process on a specific core


Recommended Posts

Can you explain to me how to use that? What should I put for iMask if theres 4 cores

It Works like that:each bit of the mask specifies a processor/core,starting from index 0.Example: i want cores 0 and 2,flag must be '1010' in bit notation.

To achieve this,we BitOr powers of two,as they work like this: 2^0=1='1' 2^1=2='10' 2^2=4='100'.

If want cores 0 and 2,then you must pass BitOR(1,4), as 2^0 = 1 And 2^2 = 4.

Link to comment
Share on other sites

It Works like that:each bit of the mask specifies a processor/core,starting from index 0.Example: i want cores 0 and 2,flag must be '1010' in bit notation.

To achieve this,we BitOr powers of two,as they work like this: 2^0=1='1' 2^1=2='10' 2^2=4='100'.

If want cores 0 and 2,then you must pass BitOR(1,4), as 2^0 = 1 And 2^2 = 4.

I'm still kind of confused with that :)
Link to comment
Share on other sites

Alright, it's clear you've never done any programming before. :(

The value you pass for iMask is a "mask" value that represents how you wish to set the process affinity (in layman's terms, on which cores you wish to run a process.)

A mask is simply a binary representation of a value. The way it works is this: The LSB (least significant bit) of the byte represents the first core (i.e. Core #1), the next significant bit represents the next core, and so on. When a particular bit location is set to 1, it means you wish to set the affinity TRUE for this particular core, i.e. run it on this core.

So you say you have 4 cores. This means that only the 4 least significant bits of the byte have any meaning.

So let's say you want your process to run on cores 2 and 4. This means you're using bits 1 and 3, because remember, the LSB is bit 0 and NOT bit 1.

So here's your binary number...

MSB (most significant bit) --> 00001010 <-- LSB (least significant bit)

If you start counting from the right, the least significant bit is Core 1, the next position is Core 2, and so on. So you see, since bits 1 and 3 are set to ones, the process will run on Cores 2 and 4.

Now of course you have to convert this binary representation to either decimal or hexadecimal. Well that's easy, bit locations 1 and 3 correspond to values 2 and 8 respectively, so 2 + 8 = 10. So you would pass a value of 10 and voila, your process' affinity is now set for Cores 2 and 4.

If you're confused by any of the above, I suggest you read up on binary first, since it's a very important thing to know for programmers. :)

http://en.wikipedia.org/wiki/Binary_numeral_system

Link to comment
Share on other sites

@ACS

Very nice explanation !

For those of you who want to convert DEC -> HEX -> BIN and visa versa.

I will drop in a converter in the example scripts section.

EDIT : Converter is available -> New"]Converter @ Dec - Hex - Bin

regards

ptrex

Edited by ptrex
Link to comment
Share on other sites

  • 1 month later...

I can't quite figure out how to get a handle to a process. Any tips?

Would it be the PID of the process? When you use the run() function, it will return the PID of the new program:

$calcpid=run("calc.exe")

Then use $calcpid as the handle.

If the process is already running, and you know the process name, try ProcessExists() or ProcessList()

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...