petsc-3.4.5 2014-06-29

PetscBinaryWrite

Writes to a binary file.

Synopsis

PetscErrorCode  PetscBinaryWrite(int fd,void *p,PetscInt n,PetscDataType type,PetscBool  istemp)
Not Collective

Input Parameters

fd - the file
p - the buffer
n - the number of items to write
type - the type of items to read (PETSC_INT, PETSC_DOUBLE or PETSC_SCALAR)
istemp - PETSC_FALSE if buffer data should be preserved, PETSC_TRUE otherwise.

Notes

PetscBinaryWrite() uses byte swapping to work on all machines; the files are written using big-endian ordering to the file. On small-endian machines the numbers are converted to the big-endian format when they are written to disk. When PETSc is ./configure with --with-64bit-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-64bit-indices is used.

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. If the flag istemp is set to PETSC_TRUE, the second byte-swapping operation is not done, thus saving some computation, but the buffer is left corrupted.

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

See Also

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

Level:advanced
Location:
src/sys/fileio/sysio.c
Index of all Sys routines
Table of Contents for all manual pages
Index of all manual pages

Examples

src/vec/vec/examples/tutorials/ex6.c.html