Skip to main content
`Ctrl`+`K`

# petsc4py.PETSc.DeviceContext

class petsc4py.PETSc.DeviceContext

  Bases: `Object`

  DeviceContext object.

  Represents an abstract handle to a device context.

  See also

  `Device`, `PetscDeviceContext`

  Enumerations

  `DeviceJoinMode` | The type of join to perform.
  `StreamType` | The type of stream.

  Methods Summary

  `create`() | Create an empty DeviceContext.
  `destroy`() | Destroy a device context.
  `duplicate`() | Duplicate a the device context.
  `fork`(n[, stream_type]) | Create multiple device contexts which are all logically dependent on this one.
  `getCurrent`() | Return the current device context.
  `getDevice`() | Get the `Device` which this instance is attached to.
  `getStreamType`() | Return the `StreamType`.
  `idle`() | Return whether the underlying stream for the device context is idle.
  `join`(join_mode, py_sub_ctxs) | Join a set of device contexts on this one.
  `setCurrent`(dctx) | Set the current device context.
  `setDevice`(device) | Set the `Device` which this `DeviceContext` is attached to.
  `setFromOptions`([comm]) | Configure the `DeviceContext` from the options database.
  `setStreamType`(stream_type) | Set the `StreamType`.
  `setUp`() | Set up the internal data structures for using the device context.
  `synchronize`() | Synchronize a device context.
  `waitFor`(other) | Make this instance wait for `other`.

  Attributes Summary

  `current` | The current global device context.
  `device` | The device associated to the device context.
  `stream_type` | The stream type.

  Methods Documentation

  create()

    Create an empty DeviceContext.

    Not collective.

    See also

    `destroy`, `Device`, `PetscDeviceContextCreate`

    Source code at petsc4py/PETSc/Device.pyx:240

    Return type:

      Self

  destroy()

    Destroy a device context.

    Not collective.

    See also

    `create`, `PetscDeviceContextDestroy`

    Source code at petsc4py/PETSc/Device.pyx:255

    Return type:

      Self

  duplicate()

    Duplicate a the device context.

    Not collective.

    See also

    `create`, `PetscDeviceContextDuplicate`

    Source code at petsc4py/PETSc/Device.pyx:348

    Return type:

      DeviceContext

  fork(n, stream_type=None)

    Create multiple device contexts which are all logically dependent on this one.

    Not collective.

    Parameters:

      - n (int) – The number of device contexts to create.

      - stream_type (StreamType | str | None) – The type of stream of the forked device context.

    Return type:

      list[DeviceContext]

    Examples

    The device contexts created must be destroyed using `join`.

        >>> dctx = PETSc.DeviceContext().getCurrent()
        >>> dctxs = dctx.fork(4)
        >>> ... # perform computations
        >>> # we can mix various join modes
        >>> dctx.join(PETSc.DeviceContext.JoinMode.SYNC, dctxs[0:2])
        >>> dctx.join(PETSc.DeviceContext.JoinMode.SYNC, dctxs[2:])
        >>> ... # some more computations and joins
        >>> # dctxs must be all destroyed with joinMode.DESTROY
        >>> dctx.join(PETSc.DeviceContext.JoinMode.DESTROY, dctxs)

    See also

    `join`, `waitFor`, `PetscDeviceContextFork`

    Source code at petsc4py/PETSc/Device.pyx:399

  static getCurrent()

    Return the current device context.

    Not collective.

    See also

    `current`, `setCurrent`, `PetscDeviceContextGetCurrentContext`

    Source code at petsc4py/PETSc/Device.pyx:519

    Return type:

      DeviceContext

  getDevice()

    Get the `Device` which this instance is attached to.

    Not collective.

    See also

    `setDevice`, `device`, `Device`, `PetscDeviceContextGetDevice`

    Source code at petsc4py/PETSc/Device.pyx:302

    Return type:

      Device

  getStreamType()

    Return the `StreamType`.

    Not collective.

    See also

    `stream_type`, `setStreamType`, `PetscDeviceContextGetStreamType`

    Source code at petsc4py/PETSc/Device.pyx:268

    Return type:

      str

  idle()

    Return whether the underlying stream for the device context is idle.

    Not collective.

    See also

    `synchronize`, `PetscDeviceContextQueryIdle`

    Source code at petsc4py/PETSc/Device.pyx:363

    Return type:

      bool

  join(join_mode, py_sub_ctxs)

    Join a set of device contexts on this one.

    Not collective.

    Parameters:

      - join_mode (DeviceJoinMode | str) – The type of join to perform.

      - py_sub_ctxs (list[DeviceContext]) – The list of device contexts to join.

    Return type:

      None

    See also

    `fork`, `waitFor`, `PetscDeviceContextJoin`

    Source code at petsc4py/PETSc/Device.pyx:448

  static setCurrent(dctx)

    Set the current device context.

    Not collective.

    Parameters:

      dctx (DeviceContext | None) – The `DeviceContext` to set as current (or `None` to use the default context).

    Return type:

      None

    See also

    `current`, `getCurrent`, `PetscDeviceContextSetCurrentContext`

    Source code at petsc4py/PETSc/Device.pyx:535

  setDevice(device)

    Set the `Device` which this `DeviceContext` is attached to.

    Collective.

    Parameters:

      device (Device) – The `Device` to which this instance is attached to.

    Return type:

      None

    See also

    `getDevice`, `device`, `Device`, `PetscDeviceContextSetDevice`

    Source code at petsc4py/PETSc/Device.pyx:317

  setFromOptions(comm=None)

    Configure the `DeviceContext` from the options database.

    Collective.

    Parameters:

      comm (Comm | None) – MPI communicator, defaults to `Sys.getDefaultComm`.

    Return type:

      None

    See also

    `Sys.getDefaultComm`, `PetscDeviceContextSetFromOptions`

    Source code at petsc4py/PETSc/Device.pyx:500

  setStreamType(stream_type)

    Set the `StreamType`.

    Not collective.

    Parameters:

      stream_type (StreamType | str) – The type of stream to set

    Return type:

      None

    See also

    `stream_type`, `getStreamType`, `PetscDeviceContextSetStreamType`

    Source code at petsc4py/PETSc/Device.pyx:283

  setUp()

    Set up the internal data structures for using the device context.

    Not collective.

    See also

    `create`, `PetscDeviceContextSetUp`

    Source code at petsc4py/PETSc/Device.pyx:336

    Return type:

      None

  synchronize()

    Synchronize a device context.

    Not collective.

    Notes

    The underlying stream is considered idle after this routine returns, i.e. `idle` will return `True`.

    See also

    `idle`, `PetscDeviceContextSynchronize`

    Source code at petsc4py/PETSc/Device.pyx:483

    Return type:

      None

  waitFor(other)

    Make this instance wait for `other`.

    Not collective.

    Parameters:

      other (DeviceContext | None) – The other `DeviceContext` to wait for

    Return type:

      None

    See also

    `fork`, `join`, `PetscDeviceContextWaitForContext`

    Source code at petsc4py/PETSc/Device.pyx:378

  Attributes Documentation

  current

    The current global device context.

    Source code at petsc4py/PETSc/Device.pyx:574

  device

    The device associated to the device context.

    Source code at petsc4py/PETSc/Device.pyx:566

  stream_type

    The stream type.

    Source code at petsc4py/PETSc/Device.pyx:558