Next: , Previous: , Up: Files   [Index]


2.14 Synchronize an Opened NetCDF File to Disk: ncmpi_sync

The function ncmpi_sync offers a way to flush system cache (both on client and server sides) to the storage devices in file systems. Use this API to minimize data loss in case of system crash.

Note this API is expensive in term of timing, as it will not return until the data cached in client- and server-side file systems are safely stored in the storage devices of the file systems.

This API does not flush the pending nonblocking requests. Flushing pending nonblocking requests, users should use ncmpi_wait_all or ncmpi_wait.

Operational Mode

This API is a collective subroutine.

This API must be called while the file is in data mode (collective or independent).

Usage

int ncmpi_sync(int ncid);
ncid

NetCDF ID, from a previous call to ncmpi_open or ncmpi_create.

Return Error Codes

ncmpi_sync returns the value NC_NOERR if no errors occurred. Otherwise, the returned status indicates an error. Possible causes of errors include:

Example

Here is an example using ncmpi_sync to synchronize the disk writes of a netCDF file named foo.nc:

#include <pnetcdf.h>
   ... 
int status;
int ncid;
   ... 
status = ncmpi_open(MPI_COMM_WORLD, "foo.nc", NC_WRITE, MPI_INFO_NULL, &ncid); /* open for writing */
if (status != NC_NOERR) handle_error(status);

   ...           /* write data or change attributes */

status = ncmpi_redef(ncid);      /* enter define mode */
if (status != NC_NOERR) handle_error(status);

   ...           /* define or change dimensions, variables, and attributes */
     
status = ncmpi_enddef(ncid);      /* exit define mode */
if (status != NC_NOERR) handle_error(status);

   ...           /* write data or change attributes */

status = ncmpi_sync(ncid);      /* synchronize to disk */
if (status != NC_NOERR) handle_error(status);

Next: , Previous: , Up: Files   [Index]