Previous: NF90_RENAME_VAR, Up: Variables


6.13 Change between Collective and Independent Parallel Access: NF90_VAR_PAR_ACCESS

The function NF90_VAR_PAR_ACCESS changes whether read/write operations on a parallel file system are performed collectively or independently (the default) on the variable. This function can only be called if the file was created (see NF90_CREATE) or opened (see NF90_OPEN) for parallel I/O.

This function is only available if the netCDF library was built with parallel I/O enabled.

Calling this function affects only the open file - information about whether a variable is to be accessed collectively or independently is not written to the data file. Every time you open a file on a parallel file system, all variables default to independent operations. The change of a variable to collective access lasts only as long as that file is open.

The variable can be changed from collective to independent, and back, as often as desired.

Classic and 64-bit offset files, when opened for parallel access, use the parallel-netcdf (a.k.a. pnetcdf) library, which does not allow per-variable changes of access mode - the entire file must be access independently or collectively. For classic and 64-bit offset files, the nf90_var_par_access function changes the access for all variables in the file.

Usage

       function nf90_var_par_access(ncid, varid, access)
         integer, intent(in) :: ncid
         integer, intent(in) :: varid
         integer, intent(in) :: access
         integer :: nf90_var_par_access
       end function nf90_var_par_access
ncid
NetCDF ID, from a previous call to NF90_OPEN (see NF90_OPEN) or NF90_CREATE (see NF90_CREATE).
varid
Variable ID.
access
NF90_INDEPENDENT to set this variable to independent operations. NF90_COLLECTIVE to set it to collective operations.

Return Values

NF90_NOERR
No error.
NF90_ENOTVAR
No variable found.
NF90_NOPAR
File not opened for parallel access.

Example

This example comes from test program nf_test/f90tst_parallel.f90. For this test to be run, netCDF must have been built with a parallel-enabled HDF5, and –enable-parallel-tests must have been used when configuring netcdf.

       ! Reopen the file.
       call handle_err(nf90_open(FILE_NAME, nf90_nowrite, ncid, comm = MPI_COMM_WORLD, &
            info = MPI_INFO_NULL))
     
       ! Set collective access on this variable. This will cause all
       ! reads/writes to happen together on every processor.
       call handle_err(nf90_var_par_access(ncid, varid, nf90_collective))
     
       ! Read this processor's data.
       call handle_err(nf90_get_var(ncid, varid, data_in, start = start, count = count))