lattice/indexing

Procs

proc coordsToFlat[D: static[int]](coords: array[D, int]; dims: array[D, int]): int

Convert D-dimensional coordinates to flat index

Parameters:

  • coords: Array of D coordinates
  • dims: Dimensions of the local lattice portion

Returns: Flat index

proc flatToCoords[D: static[int]](idx: int; dims: array[D, int]): array[D, int]

Convert flat index to D-dimensional coordinates

Parameters:

  • idx: Flat index (0..numSites-1)
  • dims: Dimensions of the local lattice portion

Returns: Array of D coordinates

proc globalFlatToLocalFlat[D: static[int]](globalIdx: int;
    localDims: array[D, int]; globalDims: array[D, int]; lo: array[D, int]): int

Convert global flat index to local flat index

This function converts a flat index in the global lattice to the corresponding flat index within a process's local portion.

Parameters:

  • globalIdx: Flat index in global lattice (0..numGlobalSites-1)
  • localDims: Dimensions of the local lattice portion
  • globalDims: Dimensions of the full global lattice
  • lo: Lower bounds of this process's global array portion

Returns: Local flat index within this process's portion

proc globalToLocalCoords[D: static[int]](globalCoords: array[D, int];
    lo: array[D, int]): array[D, int]

Convert global coordinates to local coordinates

Parameters:

  • globalCoords: Global coordinates in the full lattice
  • lo: Lower bounds of this process's global array portion

Returns: Local coordinates within this process's portion

proc localFlatToGlobalFlat[D: static[int]](localIdx: int;
    localDims: array[D, int]; globalDims: array[D, int]; lo: array[D, int]): int

Convert local flat index to global flat index

This function converts a flat index within a process's local portion to the corresponding flat index in the global lattice.

Parameters:

  • localIdx: Flat index within local portion (0..numLocalSites-1)
  • localDims: Dimensions of the local lattice portion
  • globalDims: Dimensions of the full global lattice
  • lo: Lower bounds of this process's global array portion

Returns: Global flat index

Example:

# For a process with lo = [0, 8], localDims = [4, 4], globalDims = [4, 16]
# local index 0 -> local coords [0, 0] -> global coords [0, 8] -> global index 8
let globalIdx = localFlatToGlobalFlat(0, [4, 4], [4, 16], [0, 8])

proc localToGlobalCoords[D: static[int]](localCoords: array[D, int];
    lo: array[D, int]): array[D, int]

Convert local coordinates to global coordinates

Parameters:

  • localCoords: Local coordinates within the process's portion
  • lo: Lower bounds of this process's global array portion

Returns: Global coordinates