pygsti.tools.sharedmemtools.create_shared_ndarray

pygsti.tools.sharedmemtools.create_shared_ndarray#

create_shared_ndarray(resource_alloc, shape, dtype, zero_out=False, memory_tracker=None)#

Creates a numpy.ndarray that is potentially shared between processors.

A shared memory array is created when resource_alloc.host_comm is not None, in which case it indicates which processors belong to the same host and have access to the same shared memory.

Parameters:
  • resource_alloc (ResourceAllocation) – The resource allocation object containing information about whether or not to create shared memory arrays and how to do so (see above).

  • shape (tuple) – The shape of the returned array

  • dtype (numpy.dtype) – The numpy data type of the returned array.

  • zero_out (bool, optional) – Whether to initialize the array to all zeros. When True, this function behaves as numpy.zeros; when False as numpy.empty.

  • memory_tracker (ResourceAllocation, optional) – If not none, callc memory_tracker.add_tracked_memory to track the size of the allocated array.

Returns:

  • ar (numpy.ndarray) – The potentially shared-memory array.

  • shm (multiprocessing.shared_memory.SharedMemory) – A shared memory object needed to cleanup the shared memory. If a normal array is created, this is None. Provide this to cleanup_shared_ndarray() to ensure ar is deallocated properly.