PetscBinaryWrite#

Writes to a binary file.

Synopsis#

PetscErrorCode PetscBinaryWrite(int fd, const void *p, PetscCount n, PetscDataType type)

Not Collective

Input Parameters#

  • fd - the file

  • p - the buffer, an array of the type that matches the value in type

  • n - the number of items to write

  • type - the type of items to read (PETSC_INT, PETSC_REAL or PETSC_SCALAR)

Notes#

PetscBinaryWrite() uses byte swapping to work on all machines; the files are written using big-endian ordering to the file. On little-endian machines the numbers are converted to the big-endian format when they are written to disk. When PETSc is configured using ./configure with --with-64-bit-indices the integers are written to the file as 64-bit integers, this means they can only be read back in when the option --with-64-bit-indices is used.

If running with __float128 precision the output of PETSC_REAL is in __float128 unless one uses the -binary_write_double option

The buffer p should be read-write buffer, and not static data. This way, byte-swapping is done in-place, and then the buffer is written to the file.

This routine restores the original contents of the buffer, after it is written to the file. This is done by byte-swapping in-place the second time.

Because byte-swapping may be done on the values in data it cannot be declared const

Fortran Note#

There are different functions for each datatype, for example PetscBinaryWriteInt()

See Also#

PetscBinaryRead(), PetscBinaryOpen(), PetscBinaryClose(), PetscViewerBinaryGetDescriptor(), PetscBinarySynchronizedWrite(), PetscBinarySynchronizedRead(), PetscBinarySynchronizedSeek()

Level#

advanced

Location#

src/sys/fileio/sysio.c

Examples#

src/vec/vec/tutorials/ex6f.F90
src/vec/vec/tutorials/ex6.c


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