1 stable release

Uses old Rust 2015

2.2.0 May 22, 2020

#239 in Caching

Download history 45/week @ 2023-11-27 19/week @ 2023-12-04 22/week @ 2023-12-11 16/week @ 2023-12-18 7/week @ 2023-12-25 20/week @ 2024-01-01 25/week @ 2024-01-08 20/week @ 2024-01-15 23/week @ 2024-01-22 42/week @ 2024-01-29 20/week @ 2024-02-05 164/week @ 2024-02-12 40/week @ 2024-02-19 87/week @ 2024-02-26 38/week @ 2024-03-04 27/week @ 2024-03-11

207 downloads per month
Used in 4 crates

MIT license

98KB
1.5K SLoC

hwloc2-rs

MIT licensed

This project is a successor to daschl/hwloc-rs, except that this library supports 2.x.x versions of hwloc. This library tries to maintain most of the API layer that daschl/hwloc-rs set forth.

Hwloc is a C library from Open MPI for detecting the hierarchical topology of modern architectures. This includes objects such as NUMA memory nodes, sockets, shared data & instruction caches, cores, and simultaneous multi threading.

Prerequisites

A system installed with hwloc 2.2.0.

Please note, this is not the default version installed by package managers of many mainstream distributions right now. You will probably have to install it from source:

You can download the source from https://www.open-mpi.org/projects/hwloc/

Usage

First, add the following to your Cargo.toml:

[dependencies]
hwloc2 = "2.2.0"

Next, add this to your crate root:

extern crate hwloc2;

Here is a quick example which walks the Topology and prints it out:

extern crate hwloc2;

use hwloc2::Topology;

fn main() {
	let topo = Topology::new().unwrap();

	for i in 0..topo.depth() {
		println!("*** Objects at level {}", i);

		for (idx, object) in topo.objects_at_depth(i).iter().enumerate() {
			println!("{}: {}", idx, object);
		}
	}
}

You can also look at more examples, if you want to run them check out the next section below.

Running Examples

The library ships with examples, and to run them you need to clone the repository and then run them through cargo run --example=.

$ git clone https://github.com/ichbinjoe/hwloc2-rs.git
$ cd hwloc-rs

To run an example (which will download the dependencies and build it) you can use cargo run -example=:

$ cargo run --example=walk_tree
   Compiling hwloc v2.2.0 (/directory/hwloc2-rs)
    Finished dev [unoptimized + debuginfo] target(s) in 0.54s
     Running `target/debug/examples/walk_tree`
*** Printing overall tree
Machine (): #0
 Package (): #0
  L3 (8192KB): #4294967295
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #0
      PU (): #0
      PU (): #8
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #1
      PU (): #1
      PU (): #9
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #2
      PU (): #2
      PU (): #10
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #3
      PU (): #3
      PU (): #11
  L3 (8192KB): #4294967295
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #4
      PU (): #4
      PU (): #12
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #5
      PU (): #5
      PU (): #13
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #6
      PU (): #6
      PU (): #14
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #7
      PU (): #7
      PU (): #15

License

This project uses the MIT license, please see the LICENSE file for more information.

Dependencies

~250–570KB