---
name: "hwlocality_binding"
section: "3"
platform: "linux"
package: "libhwloc-doc"
version: "1.0.2-2"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/hwlocality_binding"
---

# hwlocality\_binding(3)

## NAME

Binding -

### Enumerations

enum **hwloc\_cpubind\_policy\_t** { **HWLOC\_CPUBIND\_PROCESS**, **HWLOC\_CPUBIND\_THREAD**, **HWLOC\_CPUBIND\_STRICT** }\
 *Process/Thread binding policy.*

### Functions

HWLOC\_DECLSPEC int **hwloc\_set\_cpubind** (**hwloc\_topology\_t** topology, **hwloc\_const\_cpuset\_t** set, int policy)\
 *Bind current process or thread on cpus given in cpuset* `set`*.*  HWLOC\_DECLSPEC int **hwloc\_get\_cpubind** (**hwloc\_topology\_t** topology, **hwloc\_cpuset\_t** set, int policy)\
 *Get current process or thread binding.*  HWLOC\_DECLSPEC int **hwloc\_set\_proc\_cpubind** (**hwloc\_topology\_t** topology, hwloc\_pid\_t pid, **hwloc\_const\_cpuset\_t** set, int policy)\
 *Bind a process* `pid` *on cpus given in cpuset* `set`*.*  HWLOC\_DECLSPEC int **hwloc\_get\_proc\_cpubind** (**hwloc\_topology\_t** topology, hwloc\_pid\_t pid, **hwloc\_cpuset\_t** set, int policy)\
 *Get the current binding of process* `pid`*.*  HWLOC\_DECLSPEC int **hwloc\_set\_thread\_cpubind** (**hwloc\_topology\_t** topology, hwloc\_thread\_t tid, **hwloc\_const\_cpuset\_t** set, int policy)\
 *Bind a thread* `tid` *on cpus given in cpuset* `set`*.*  HWLOC\_DECLSPEC int **hwloc\_get\_thread\_cpubind** (**hwloc\_topology\_t** topology, hwloc\_thread\_t tid, **hwloc\_cpuset\_t** set, int policy)\
 *Get the current binding of thread* `tid`*.*

## Detailed Description

It is often useful to call **hwloc\_cpuset\_singlify()** first so that a single CPU remains in the set. This way, the process will not even migrate between different CPUs. Some OSes also only support that kind of binding.

**Note:**

Some OSes do not provide all ways to bind processes, threads, etc and the corresponding binding functions may fail. ENOSYS is returned when it is not possible to bind the requested kind of object processes/threads). EXDEV is returned when the requested cpuset can not be enforced (e.g. some systems only allow one CPU, and some other systems only allow one NUMA node)

The most portable version that should be preferred over the others, whenever possible, is

```
 hwloc_set_cpubind(topology, set, 0),
```

as it just binds the current program, assuming it is monothread, or

```
 hwloc_set_cpubind(topology, set, HWLOC_CPUBIND_THREAD),
```

which binds the current thread of the current program (which may be multithreaded).

**Note:**

To unbind, just call the binding function with either a full cpuset or a cpuset equal to the system cpuset.

## Enumeration Type Documentation

### enum hwloc\_cpubind\_policy\_t

Process/Thread binding policy. These flags can be used to refine the binding policy.

The default (0) is to bind the current process, assumed to be mono-thread, in a non-strict way. This is the most portable way to bind as all OSes usually provide it.

**Enumerator:**

- *HWLOC\_CPUBIND\_PROCESS*

  *Bind all threads of the current multithreaded process. This may not be supported by some OSes (e.g. Linux).*

- *HWLOC\_CPUBIND\_THREAD*

  *Bind current thread of current process.*

- *HWLOC\_CPUBIND\_STRICT*

  *Request for strict binding from the OS. By default, when the designated CPUs are all busy while other CPUs are idle, OSes may execute the thread/process on those other CPUs instead of the designated CPUs, to let them progress anyway. Strict binding means that the thread/process will \_never\_ execute on other cpus than the designated CPUs, even when those are busy with other tasks and other CPUs are idle.*

**Note:**

*Depending on OSes and implementations, strict binding may not be possible (implementation reason) or not allowed (administrative reasons), and the function will fail in that case.*

*When retrieving the binding of a process, this flag checks whether all its threads actually have the same binding. If the flag is not given, the binding of each thread will be accumulated.*

**Note:**

*This flag is meaningless when retrieving the binding of a thread.*

## Function Documentation

### HWLOC\_DECLSPEC int hwloc\_get\_cpubind (hwloc\_topology\_t topology, hwloc\_cpuset\_t set, int policy)

*Get current process or thread binding.*

### HWLOC\_DECLSPEC int hwloc\_get\_proc\_cpubind (hwloc\_topology\_t topology, hwloc\_pid\_t pid, hwloc\_cpuset\_t set, int policy)

*Get the current binding of process* `pid`*.* **Note:**

*hwloc\_pid\_t is pid\_t on unix platforms, and HANDLE on native Windows platforms*

*HWLOC\_CPUBIND\_THREAD can not be used in* `policy`*.*

### HWLOC\_DECLSPEC int hwloc\_get\_thread\_cpubind (hwloc\_topology\_t topology, hwloc\_thread\_t tid, hwloc\_cpuset\_t set, int policy)

*Get the current binding of thread* `tid`*.* **Note:**

*hwloc\_thread\_t is pthread\_t on unix platforms, and HANDLE on native Windows platforms*

*HWLOC\_CPUBIND\_PROCESS can not be used in* `policy`*.*

### HWLOC\_DECLSPEC int hwloc\_set\_cpubind (hwloc\_topology\_t topology, hwloc\_const\_cpuset\_t set, int policy)

*Bind current process or thread on cpus given in cpuset* `set`*.* **Returns:**

*ENOSYS if the action is not supported*

*EXDEV if the binding cannot be enforced*

### HWLOC\_DECLSPEC int hwloc\_set\_proc\_cpubind (hwloc\_topology\_t topology, hwloc\_pid\_t pid, hwloc\_const\_cpuset\_t set, int policy)

*Bind a process* `pid` *on cpus given in cpuset* `set`*.* **Note:**

*hwloc\_pid\_t is pid\_t on unix platforms, and HANDLE on native Windows platforms*

*HWLOC\_CPUBIND\_THREAD can not be used in* `policy`*.*

### HWLOC\_DECLSPEC int hwloc\_set\_thread\_cpubind (hwloc\_topology\_t topology, hwloc\_thread\_t tid, hwloc\_const\_cpuset\_t set, int policy)

*Bind a thread* `tid` *on cpus given in cpuset* `set`*.* **Note:**

*hwloc\_thread\_t is pthread\_t on unix platforms, and HANDLE on native Windows platforms*

*HWLOC\_CPUBIND\_PROCESS can not be used in* `policy`*.*

## Author

*Generated automatically by Doxygen for Hardware Locality (hwloc) from the source code.*
