Skip to main content
`Ctrl`+`K`

# PetscPOpen

Runs a program on MPI rank 0 and sends either its input or output to a file.

## Synopsis

    #include "petscsys.h"
    PetscErrorCode PetscPOpen(MPI_Comm comm, const char machine[], const char program[], const char mode[], FILE **fp)

Logically Collective, but only MPI rank 0 runs the command

## Input Parameters

- comm - MPI communicator, only processor zero runs the program

- machine - machine to run command on or `NULL`, or a string with 0 in first location

- program - name of program to run

- mode - either “r” or “w”

## Output Parameter

- fp - the file pointer where program input or output may be read or `NULL` if results are not needed

## Notes

Use `PetscPClose()` to close the file pointer when you are finished with it

Does not work under Microsoft Windows

If machine is not provided will use the value set with `PetscPOpenSetMachine()` if that was provided, otherwise will use the machine running MPI rank 0 of the communicator

The program string may contain \({DISPLAY}, \){HOMEDIRECTORY} or ${WORKINGDIRECTORY}; these will be replaced with relevant values.

## See Also

`PetscFOpen()`, `PetscFClose()`, `PetscPClose()`, `PetscPOpenSetMachine()`

## Level

intermediate

## Location

src/sys/fileio/mpiuopen.c

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