:orphan:
# PetscViewerBinaryOpen
Opens a file for binary input/output. 
## Synopsis
```
#include "petscviewer.h"   
PetscErrorCode PetscViewerBinaryOpen(MPI_Comm comm, const char name[], PetscFileMode mode, PetscViewer *viewer)
```
Collective


## Input Parameters

- ***comm -*** MPI communicator
- ***name -*** name of file
- ***mode -*** open mode of file


```none
    FILE_MODE_WRITE - create new file for binary output
    FILE_MODE_READ - open existing file for binary input
    FILE_MODE_APPEND - open existing file for binary output
```



## Output Parameter

- ***viewer -*** PetscViewer for binary input/output to use with the specified file



## Options Database Keys

- ***-viewer_binary_filename <name> -*** name of file to use
- ***-viewer_binary_skip_info -*** true to skip opening an info file
- ***-viewer_binary_skip_options -*** true to not use options database while creating viewer
- ***-viewer_binary_skip_header -*** true to skip output object headers to the file
- ***-viewer_binary_mpiio -*** true to use MPI-IO for input and output to the file (more scalable for large problems)





## Note
This `PetscViewer` should be destroyed with `PetscViewerDestroy()`.

For reading files, the filename may begin with ftp:// or http:// and/or
end with .gz; in this case file is brought over and uncompressed.

For creating files, if the file name ends with .gz it is automatically
compressed when closed.


## See Also
 [](sec_viewers), `PETSCVIEWERBINARY`, `PetscViewerASCIIOpen()`, `PetscViewerPushFormat()`, `PetscViewerDestroy()`,
`VecView()`, `MatView()`, `VecLoad()`, `MatLoad()`, `PetscViewerBinaryGetDescriptor()`,
`PetscViewerBinaryGetInfoPointer()`, `PetscFileMode`, `PetscViewer`, `PetscViewerBinaryRead()`, `PetscViewerBinarySetUseMPIIO()`,
`PetscViewerBinaryGetUseMPIIO()`, `PetscViewerBinaryGetMPIIOOffset()`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/classes/viewer/impls/binary/binv.c.html#PetscViewerBinaryOpen">src/sys/classes/viewer/impls/binary/binv.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex7.c.html">src/dm/tutorials/ex7.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex10.c.html">src/ksp/ksp/tutorials/ex10.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex27.c.html">src/ksp/ksp/tutorials/ex27.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex42.c.html">src/ksp/ksp/tutorials/ex42.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex54f.F90.html">src/ksp/ksp/tutorials/ex54f.F90</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex72.c.html">src/ksp/ksp/tutorials/ex72.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex75.c.html">src/ksp/ksp/tutorials/ex75.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex75f.F90.html">src/ksp/ksp/tutorials/ex75f.F90</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex76.c.html">src/ksp/ksp/tutorials/ex76.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex76f.F90.html">src/ksp/ksp/tutorials/ex76f.F90</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex77.c.html">src/ksp/ksp/tutorials/ex77.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/sys/classes/viewer/impls/binary/binv.c)


[Index of all Viewer routines](index.md)  
[Table of Contents for all manual pages](/manualpages/index.md)  
[Index of all manual pages](/manualpages/singleindex.md)  
