globalarrays/gatypes

Search:
Group by:

Types

GlobalArray[D; T] = object

Represents a Global Array

This object encapsulates a Global Array (GA) handle along with metadata about its globalGrid dimensions, MPI grid configuration, and ghost cell widths.

Fields:

  • handle: The underlying GA handle.
  • globalGrid: An array specifying the size of each dimension of the global array.
  • mpiGrid: An array specifying the distribution of the global array across MPI ranks.
  • ghostGrid: An array specifying the width of ghost cells for each dimension.

Note: The type parameter T indicates the data type of the elements in the global array.

Procs

proc `=copy`[D: static[int]; T](dest: var GlobalArray[D, T];
                                src: GlobalArray[D, T])

Copy semantics for GlobalArray

Creates a copy of the source GlobalArray into the destination. All data and fields are copied, except for the handle, which is preserved to ensure that each GlobalArray instance manages its own GA resource.

Parameters:

  • dest: The destination GlobalArray to copy into.
  • src: The source GlobalArray to copy from.
proc `=destroy`[D: static[int]; T](ga: GlobalArray[D, T]) {....raises: [].}

Destructor for GlobalArray

Frees the resources associated with the GlobalArray.

Parameters:

  • ga: The GlobalArray instance to be destroyed.
proc accessGhosts[D: static[int]; T](ga: GlobalArray[D, T]): (
    ptr UncheckedArray[T], array[D, int], array[D, int])

Access local data including ghost regions

Returns a pointer to the raw data (including ghosts), the padded dimensions (local + 2 x ghost in each dim), and the leading dimensions. The pointer is valid until releaseLocal is called.

Parameters:

  • ga: The GlobalArray instance

Returns: A tuple of (data pointer, padded dimensions, leading dimensions)

proc accessLocal[D: static[int]; T](ga: GlobalArray[D, T]): (
    ptr UncheckedArray[T], array[D, int])

Access local data segment of the GlobalArray (no ghosts)

Returns a pointer to the raw local data and the leading dimensions (strides). The pointer is valid until releaseLocal is called.

Parameters:

  • ga: The GlobalArray instance

Returns: A tuple of (data pointer, leading dimensions array)

proc conformable[D: static[int]; T](a, b: GlobalArray[D, T]): bool

Checks if two GlobalArrays are conformable

Two GlobalArrays are conformable if they have the same lattice dimensions, MPI grid configuration, and ghost cell widths.

Parameters:

  • a: The first GlobalArray.
  • b: The second GlobalArray.

Returns: true if the two GlobalArrays are conformable, false otherwise.

proc getBounds[D: static[int]; T](ga: GlobalArray[D, T]): (array[D, int],
    array[D, int])

Get the local bounds for this process

Parameters:

  • ga: The GlobalArray instance

Returns: A tuple containing two arrays: the lower and upper bounds of the local segment

proc getGhostGrid[D: static[int]; T](ga: GlobalArray[D, T]): array[D, int]

Accessor for the ghost cell widths

Returns the ghost cell widths of the GlobalArray.

Parameters:

  • ga: The GlobalArray instance.

Returns: An array representing the ghost cell widths.

proc getGlobalGrid[D: static[int]; T](ga: GlobalArray[D, T]): array[D, int]

Accessor for the lattice dimensions

Returns the lattice dimensions of the GlobalArray.

Parameters:

  • ga: The GlobalArray instance.

Returns: An array representing the lattice dimensions.

proc getHandle[D: static[int]; T](ga: GlobalArray[D, T]): cint

Accessor for the GA handle

Returns the underlying GA handle associated with the GlobalArray.

Parameters:

  • ga: The GlobalArray instance.

Returns: The GA handle as a cint.

proc getLocalGrid[D: static[int]; T](ga: GlobalArray[D, T]): array[D, int]

Accessor for the lattice dimensions

Returns the lattice dimensions of the GlobalArray.

Parameters:

  • a: The GlobalArray or HostView instance.

Returns: An array representing the lattice dimensions.

proc getMPIGrid[D: static[int]; T](ga: GlobalArray[D, T]): array[D, int]

Accessor for the MPI grid configuration

Returns the MPI grid configuration of the GlobalArray.

Parameters:

  • ga: The GlobalArray instance.

Returns: An array representing the MPI grid configuration.

proc isInitialized[D: static[int]; T](ga: GlobalArray[D, T]): bool

Checks if the GlobalArray is initialized

A GlobalArray is considered initialized if its GA handle is valid (not zero).

Parameters:

  • ga: The GlobalArray instance.

Returns: true if the GlobalArray is initialized, false otherwise.

proc newGlobalArray[D: static[int]](globalGrid: array[D, SomeInteger];
                                    mpiGrid: array[D, SomeInteger];
                                    ghostGrid: array[D, SomeInteger];
                                    T: typedesc): GlobalArray[D, T]

Constructor for GlobalArray

Creates a new GlobalArray with the specified globalGrid dimensions, MPI grid configuration, ghost cell widths, and data type.

Parameters:

  • globalGrid: Array specifying the size of each dimension of the global array.
  • mpiGrid: Array specifying distribution of the global array across MPI ranks.
  • ghostGrid: An array specifying the width of ghost cells for each dimension.
  • T: The data type of the elements in the global array.

Returns: A new instance of GlobalArray[D, T].

Raises:

  • ValueError: If the GA allocation fails.

Example:

let globalGrid = [8, 8, 8, 16]
let mpigrid = [1, 1, 1, 2]
let ghostgrid = [1, 1, 1, 1]
var myGA = newGlobalArray(globalGrid, mpigrid, ghostgrid): float

proc numSites[D: static[int]; T](ga: GlobalArray[D, T]): int

Get the number of local sites for this process

Parameters:

  • ga: The GlobalArray instance

Returns: The number of local sites for the current process

proc releaseLocal[D: static[int]; T](ga: GlobalArray[D, T])

Release local data access obtained via accessLocal or accessGhosts

Must be called after finishing direct memory access.

proc updateGhostDirection[D: static[int]; T](ga: GlobalArray[D, T];
    dir: SomeInteger; side: SomeInteger; update_corners: bool = true)

Update ghost cells in a specific direction and side

This procedure updates the ghost cells of the GlobalArray in a specified direction and side (lower or upper). It can also optionally update corner ghost cells.

Parameters:

  • ga: The GlobalArray instance.
  • dir: The direction index for the ghost cell update.
  • side: The side index (0 for lower, 1 for upper).
  • update_corners: Whether to update corner ghost cells (default: true).
proc updateGhosts[D: static[int]; T](ga: GlobalArray[D, T];
                                     update_corners: bool = true)

Update the ghost cells of the GlobalArray

This procedure triggers a ghost cell update for the GlobalArray, ensuring that the ghost cells contain up-to-date data from neighboring processes.

Parameters:

  • ga: The GlobalArray instance.