Coder Social home page Coder Social logo

hwloc-rs's Introduction

hwloc-rs

MIT licensed crates.io

Build Status Build status

This project is a rust binding to the hwloc C library, which provides a portable abstraction of the hierarchical topology of modern architectures, including NUMA memory nodes, sockets, shared caches, cores and simultaneous multithreading.

Prerequisites

Since this binding depends on the c library, you need to have it installed. The easiest way is to install it system-wide.

Here is a table of the version compatibility that we try to test for:

hwloc-rs libhwloc
0.4 1.11.5
0.3 1.11.2
0.2 1.11.1
0.1 1.11.1

Install hwloc on OS X

The easiest way is to download, build and install the sources from the website.

  1. Download the artifact.
  2. tar -xvzpf hwloc-1.11.5.tar.gz
  3. cd hwloc-1.11.5
  4. ./configure && make && sudo make install

You can check if it works by trying the lstopo command. Here is the sample output for a Mid 2012 MacBook Pro with 16GB of RAM:

~ $ lstopo
Machine (16GB total) + NUMANode L#0 (P#0 16GB) + L3 L#0 (6144KB)
  L2 L#0 (256KB) + L1d L#0 (32KB) + L1i L#0 (32KB) + Core L#0
    PU L#0 (P#0)
    PU L#1 (P#1)
  L2 L#1 (256KB) + L1d L#1 (32KB) + L1i L#1 (32KB) + Core L#1
    PU L#2 (P#2)
    PU L#3 (P#3)
  L2 L#2 (256KB) + L1d L#2 (32KB) + L1i L#2 (32KB) + Core L#2
    PU L#4 (P#4)
    PU L#5 (P#5)
  L2 L#3 (256KB) + L1d L#3 (32KB) + L1i L#3 (32KB) + Core L#3
    PU L#6 (P#6)
    PU L#7 (P#7)

Install hwloc on Linux (Ubuntu 14.04)

On Ubuntu 14.04 installing it through apt is probably the easiest.

~ $ sudo apt-get install hwloc libhwloc-dev

You can again check with lstopo. The following is a 2-core virtual machine:

ubuntu-trusty-64:~$ lstopo
Machine (490MB)
  Socket L#0 + L2d L#0 (6144KB)
    L1d L#0 (32KB) + Core L#0 + PU L#0 (P#0)
    L1d L#1 (32KB) + Core L#1 + PU L#1 (P#1)
  HostBridge L#0
    PCI 80ee:beef
    PCI 8086:100e
      Net L#0 "eth0"
    PCI 8086:100e
      Net L#1 "eth1"
    PCI 8086:2829
      Block L#2 "sda"

Usage

First, add the following to your Cargo.toml:

[dependencies]
hwloc = "0.3.0"

Next, add this to your crate root:

extern crate hwloc;

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

extern crate hwloc;

use hwloc::Topology;

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

	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/daschl/hwloc-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 libc v0.2.3
   ...
   Compiling hwloc v0.2.0 (file:///vagrant/hwloc-rs)
     Running `target/debug/examples/walk_tree`
*** Printing overall tree
Machine (490MB): #0
 Socket (): #0
  L2d (6144KB): #4294967295
   L1d (32KB): #4294967295
    Core (): #0
     PU (): #0
   L1d (32KB): #4294967295
    Core (): #1
     PU (): #1

License

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

hwloc-rs's People

Contributors

daschl avatar fsck avatar trolldemorted avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.