.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/membind.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_membind.py: Example of using membind ======================== .. GENERATED FROM PYTHON SOURCE LINES 7-46 .. code-block:: Python from pyhwloc import Topology from pyhwloc.topology import MemBindFlags, MemBindPolicy def bind_np_array() -> None: """Show how to bind a numpy array.""" try: import numpy as np except ImportError: print("Numpy is not available.") return array = np.arange(0, 8196) with Topology.from_this_system() as topo: if not topo.get_support().membind.set_area_membind: return nodeset, policy = topo.get_area_membind(array.data, MemBindFlags.BYNODESET) print(MemBindPolicy(policy).name, nodeset) # >>> FIRSTTOUCH 0 # Use to the first node. nodeset.only(0) topo.set_area_membind(array.data, nodeset, MemBindPolicy.BIND, 0) nodeset, policy = topo.get_area_membind(array.data, MemBindFlags.BYNODESET) print(MemBindPolicy(policy).name, nodeset) # >>> BIND 0 assert policy == MemBindPolicy.BIND def main() -> None: bind_np_array() if __name__ == "__main__": main() .. _sphx_glr_download_examples_membind.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: membind.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: membind.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: membind.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_