io/qio

Search:
Group by:

QIO-style parallel I/O for lattice field data

This module provides high-level parallel I/O facilities compatible with the QIO library format. It handles:

  • Parallel reading/writing with proper site ordering
  • Checksumming for data integrity
  • Byte swapping for portability

Site ordering in QIO files follows lexicographic order: site = x + Lx * (y + Ly * (z + Lz * t))

Reference: https://github.com/usqcd-software/qio

Types

ByteOrder = enum
  boNative, boBigEndian, boLittleEndian
GaugeField[T] = object
  dims*: array[4, int]
  data*: seq[T]
4D gauge field (4 SU(3) matrices per site)
PropagatorField[T] = object
  dims*: array[4, int]
  data*: seq[T]
Propagator field (12x12 complex per site)
QIOChecksum = object
  suma*: uint32
  sumb*: uint32
QIO uses a 32-bit checksum with two components
QIOFieldReader[T] = ref object
  fileInfo*: SciDACFileInfo
  recordInfo*: SciDACRecordInfo
QIOFieldWriter[T] = ref object
  fileInfo*: SciDACFileInfo

Procs

proc `$`(cs: QIOChecksum): string {....raises: [], tags: [], forbids: [].}
proc close[T](r: QIOFieldReader[T])
proc close[T](w: QIOFieldWriter[T]): LimeStatus
proc combine(cs1, cs2: QIOChecksum): QIOChecksum {....raises: [], tags: [],
    forbids: [].}
Combine two checksums (for parallel reduction)
proc dims[T](r: QIOFieldReader[T]): seq[int]
proc evenOddIndex(coords: openArray[int]; dims: openArray[int]): int {.
    ...raises: [], tags: [], forbids: [].}
Convert to even-odd (checkerboard) ordering Even sites first, then odd sites
proc initChecksum(): QIOChecksum {....raises: [], tags: [], forbids: [].}
proc lexCoords(index: int; dims: openArray[int]): seq[int] {....raises: [],
    tags: [], forbids: [].}
Convert lexicographic index to coordinates
proc lexIndex(coords: openArray[int]; dims: openArray[int]): int {....raises: [],
    tags: [], forbids: [].}
Convert lattice coordinates to lexicographic index. QIO order: x + Lx * (y + Ly * (z + Lz * t))
proc needsSwap(target: ByteOrder): bool {....raises: [], tags: [], forbids: [].}
Check if byte swapping is needed
proc newQIOFieldReader[T](filename: string): QIOFieldReader[T]
Open a QIO file for reading field data
proc newQIOFieldWriter[T](filename: string; dims: openArray[int]): QIOFieldWriter[
    T]
Create a new QIO file for writing
proc readField[T](r: QIOFieldReader[T]; targetOrder: ByteOrder = boBigEndian): seq[
    T]
Read a field from the file Data is returned in lexicographic site order
proc readGaugeField(filename: string): GaugeField[float64] {.
    ...raises: [IOError, OSError, ValueError, Exception, XmlError],
    tags: [ReadIOEffect, RootEffect, WriteIOEffect], forbids: [].}
Read a gauge configuration file
proc swapBytes32(data: var openArray[byte]) {....raises: [], tags: [], forbids: [].}
Swap bytes for 32-bit values in-place
proc swapBytes64(data: var openArray[byte]) {....raises: [], tags: [], forbids: [].}
Swap bytes for 64-bit values in-place
proc swapBytesFloat32(data: var openArray[float32]) {....raises: [], tags: [],
    forbids: [].}
Swap bytes for float32 array
proc swapBytesFloat64(data: var openArray[float64]) {....raises: [], tags: [],
    forbids: [].}
Swap bytes for float64 array
proc update(cs: var QIOChecksum; data: openArray[byte]; rank: uint32 = 0) {.
    ...raises: [], tags: [], forbids: [].}
Update checksum with data
proc volume(dims: array[4, int]): int {....raises: [], tags: [], forbids: [].}
proc writeField[T](w: QIOFieldWriter[T]; data: openArray[T]; colors: int = 3;
                   spins: int = 0; datacount: int = 4; userXml: string = "";
                   sourceOrder: ByteOrder = boNative): LimeStatus

Write a field to the file

Parameters: data: Field data in lexicographic site order colors: Number of colors (default 3 for SU(3)) spins: Number of spin components (0 for gauge, 4 for fermions) datacount: Number of data objects per site (4 for gauge links) userXml: Optional user metadata XML sourceOrder: Byte order of source data

proc writeGaugeField(filename: string; field: GaugeField[float64];
                     userXml: string = ""): LimeStatus {.
    ...raises: [IOError, OSError], tags: [WriteIOEffect], forbids: [].}
Write a gauge configuration file