Skip to main content
`Ctrl`+`K`

# PetscMemoryAccessMode

Describes the intended usage of a memory region

## Synopsis

    #include <petscdevicetypes.h>
    typedef enum {
      PETSC_MEMORY_ACCESS_READ       = 1, /* 01 */
      PETSC_MEMORY_ACCESS_WRITE      = 2, /* 10 */
      PETSC_MEMORY_ACCESS_READ_WRITE = 3  /* 11 */
    } PetscMemoryAccessMode;

## Values

- `PETSC_MEMORY_ACCESS_READ` - Read only

- `PETSC_MEMORY_ACCESS_WRITE` - Write only

- `PETSC_MEMORY_ACCESS_READ_WRITE` - Read and write

## Notes

This `enum` is a bitmask with the following encoding (assuming 2 bit):

      PETSC_MEMORY_ACCESS_READ       = 0b01
      PETSC_MEMORY_ACCESS_WRITE      = 0b10
      PETSC_MEMORY_ACCESS_READ_WRITE = 0b11

      // consequently
      PETSC_MEMORY_ACCESS_READ | PETSC_MEMORY_ACCESS_WRITE = PETSC_MEMORY_ACCESS_READ_WRITE

The following convenience macros are also provided:

- `PetscMemoryAccessRead(mode)` - `true` if `mode` is any kind of read, `false` otherwise

- `PetscMemoryAccessWrite(mode)` - `true` if `mode` is any kind of write, `false` otherwise

## Developer Note

This enum uses a function (`PetscMemoryAccessModeToString()`) to convert values to string representation, so cannot be used in `PetscOptionsEnum()`.

## See Also

`PetscMemoryAccessModeToString()`, `PetscDevice`, `PetscDeviceContext`

## Level

beginner

## Location

include/petscdevicetypes.h

Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages