petsc4py.PETSc.DeviceContext#
- class petsc4py.PETSc.DeviceContext#
Bases:
ObjectDeviceContext object.
Represents an abstract handle to a device context.
Use
create,getCurrent, orgetDefaultbefore calling context operations.See also
Enumerations
The type of join to perform.
The type of stream.
Methods Summary
create()Create an empty DeviceContext.
destroy()Destroy a device context.
Duplicate a the device context.
fork(n[, stream_type])Create multiple device contexts which are all logically dependent on this one.
Return the current device context.
Return the default-stream context for the current device.
Get the
Devicewhich this instance is attached to.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
Devicewhich thisDeviceContextis attached to.setFromOptions([comm])Configure the
DeviceContextfrom the options database.setStreamType(stream_type)Set the
StreamType.setUp()Set up the internal data structures for using the device context.
Synchronize a device context.
waitFor(other)Make this instance wait for
other.Attributes Summary
The current global device context.
The device associated to the device context.
The stream type.
Methods Documentation
- create()#
Create an empty DeviceContext.
Not collective.
See also
Source code at petsc4py/PETSc/Device.pyx:229
- Return type:
- destroy()#
Destroy a device context.
Not collective.
See also
Source code at petsc4py/PETSc/Device.pyx:244
- Return type:
- duplicate()#
Duplicate a the device context.
Not collective.
See also
Source code at petsc4py/PETSc/Device.pyx:337
- Return type:
- 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 | None) – The type of stream of the forked device context.
- Return type:
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
- static getCurrent()#
Return the current device context.
Not collective.
See also
Source code at petsc4py/PETSc/Device.pyx:509
- Return type:
- static getDefault()#
Return the default-stream context for the current device.
Not collective.
The context is created lazily. This wrapper holds a reference to a concrete context, even if the current device subsequently changes. Do not change its device or stream type, or configure it from options. Use
duplicateto create an independently configurable context. Destroying this wrapper releases its reference; PETSc retains ownership.Source code at petsc4py/PETSc/Device.pyx:525
- Return type:
- getDevice()#
Get the
Devicewhich this instance is attached to.Not collective.
See also
Source code at petsc4py/PETSc/Device.pyx:291
- Return type:
- getStreamType()#
Return the
StreamType.Not collective.
Source code at petsc4py/PETSc/Device.pyx:257
- Return type:
- idle()#
Return whether the underlying stream for the device context is idle.
Not collective.
See also
Source code at petsc4py/PETSc/Device.pyx:352
- Return type:
- join(join_mode, py_sub_ctxs)#
Join a set of device contexts on this one.
Not collective.
- Parameters:
join_mode (JoinMode) – The type of join to perform.
py_sub_ctxs (list[DeviceContext]) – The list of initialized device contexts to join; entries cannot be
None.
- Return type:
See also
- static setCurrent(dctx)#
Set the current device context.
Not collective.
- Parameters:
dctx (DeviceContext) – The initialized
DeviceContextto set as current. Save the previous context withgetCurrentand pass it here to restore it.- Return type:
See also
- setDevice(device)#
Set the
Devicewhich thisDeviceContextis attached to.Collective.
See also
- setFromOptions(comm=None)#
Configure the
DeviceContextfrom the options database.Collective.
- Parameters:
comm (Comm | None) – MPI communicator, defaults to
Sys.getDefaultComm.- Return type:
- setStreamType(stream_type)#
Set the
StreamType.Not collective.
- Parameters:
stream_type (StreamType) – The type of stream to set
- Return type:
- setUp()#
Set up the internal data structures for using the device context.
Not collective.
See also
Source code at petsc4py/PETSc/Device.pyx:325
- Return type:
- synchronize()#
Synchronize a device context.
Not collective.
Notes
The underlying stream is considered idle after this routine returns, i.e.
idlewill returnTrue.See also
Source code at petsc4py/PETSc/Device.pyx:473
- Return type:
- waitFor(other)#
Make this instance wait for
other.Not collective.
- Parameters:
other (DeviceContext) – The initialized
DeviceContextto wait for.- Return type:
See also
Attributes Documentation
- current#
The current global device context.
- device#
The device associated to the device context.
- stream_type#
The stream type.