SCORPIO  1.7.0
Macros | Functions | Variables
put_var.c File Reference

A simple C example for the ParallelIO Library using PIOc_put_vara() More...

#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <mpi.h>
#include <pio.h>
Include dependency graph for put_var.c:

Macros

#define NUM_NETCDF_FLAVORS   5
 The number of possible output netCDF output flavors available to the ParallelIO library. More...
 
#define NDIM   2
 The number of dimensions in the example data. More...
 
#define DIM_LEN_X   16
 The length of our sample data. More...
 
#define DIM_LEN_Y   5
 
#define DIM_NAME_X   "x"
 The name of the dimension in the netCDF output file. More...
 
#define DIM_NAME_Y   "y"
 
#define VAR_NAME_D0   "d0"
 The name of the variables in the netCDF output file. More...
 
#define VAR_NAME_D1   "d1"
 
#define VAR_NAME_D2   "d2"
 
#define ERR_BAD   1001
 Return code when netCDF output file does not match expectations. More...
 
#define MPIERR(e)
 Handle MPI errors. More...
 
#define ERR(e)
 Handle non-MPI errors by finalizing the MPI library and exiting with an exit code. More...
 

Functions

int main (int argc, char *argv[])
 Main execution of code. More...
 

Variables

const int START_DATA_VAL = 42
 The meaning of life, the universe, and everything. More...
 
char err_buffer [MPI_MAX_ERROR_STRING]
 Global err buffer for MPI. More...
 
int resultlen
 This is the length of the most recent MPI error message, stored int the global error string. More...
 

Detailed Description

A simple C example for the ParallelIO Library using PIOc_put_vara()

This example creates a netCDF output file with one dimension and one variable. It first writes, then reads the sample file using the ParallelIO library.

This example can be run in parallel for 1, 2, 4, 8, or 16 processors.

Macro Definition Documentation

◆ DIM_LEN_X

#define DIM_LEN_X   16

The length of our sample data.

There will be a total of 16x16 integers in our data, and responsibility for writing and reading them will be spread between all the processors used to run this example.

◆ DIM_LEN_Y

#define DIM_LEN_Y   5

◆ DIM_NAME_X

#define DIM_NAME_X   "x"

The name of the dimension in the netCDF output file.

◆ DIM_NAME_Y

#define DIM_NAME_Y   "y"

◆ ERR

#define ERR (   e)
Value:
do { \
MPI_Finalize(); \
return e; \
} while (0)

Handle non-MPI errors by finalizing the MPI library and exiting with an exit code.

◆ ERR_BAD

#define ERR_BAD   1001

Return code when netCDF output file does not match expectations.

◆ MPIERR

#define MPIERR (   e)
Value:
do { \
MPI_Error_string(e, err_buffer, &resultlen); \
printf("MPI error, line %d, file %s: %s\n", __LINE__, __FILE__, err_buffer); \
MPI_Finalize(); \
return 2; \
} while (0)
char err_buffer[MPI_MAX_ERROR_STRING]
Global err buffer for MPI.
Definition: put_var.c:73
int resultlen
This is the length of the most recent MPI error message, stored int the global error string.
Definition: put_var.c:77

Handle MPI errors.

This should only be used with MPI library function calls.

◆ NDIM

#define NDIM   2

The number of dimensions in the example data.

In this simple example, we are using one-dimensional data.

◆ NUM_NETCDF_FLAVORS

#define NUM_NETCDF_FLAVORS   5

The number of possible output netCDF output flavors available to the ParallelIO library.

◆ VAR_NAME_D0

#define VAR_NAME_D0   "d0"

The name of the variables in the netCDF output file.

◆ VAR_NAME_D1

#define VAR_NAME_D1   "d1"

◆ VAR_NAME_D2

#define VAR_NAME_D2   "d2"

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main execution of code.

Executes the functions to:

  • create a new examplePioClass instance
  • initialize MPI and the ParallelIO libraries
  • create the decomposition for this example
  • create the netCDF output file
  • define the variable in the file
  • write data to the variable in the file using decomposition
  • read the data back from the file using decomposition
  • close the file
  • clean up resources

The example can be run from the command line (on system that support it) like this:

    mpiexec -n 3 ./put_var
    

The sample file created by this program is a small netCDF file. It has the following contents (as shown by ncdump) for a 4-processor run:

    netcdf put_var_0 {
dimensions:
        x = 16 ;
        y = 16 ;
variables:
        int d0 ;
        int d1(x) ;
        int d2(x,y) ;
data:

 d0 = 42 ;

 d1 = 42, 42, 42, 42, 42, 42, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44 ;

 d2 =
  42, 42, 42, 42, 42,
  42, 42, 42, 42, 42,
  42, 42, 42, 42, 42,
  42, 42, 42, 42, 42,
  42, 42, 42, 42, 42,
  42, 42, 42, 42, 42,
  43, 43, 43, 43, 43,
  43, 43, 43, 43, 43,
  43, 43, 43, 43, 43,
  43, 43, 43, 43, 43,
  43, 43, 43, 43, 43,
  44, 44, 44, 44, 44,
  44, 44, 44, 44, 44,
  44, 44, 44, 44, 44,
  44, 44, 44, 44, 44,
  44, 44, 44, 44, 44 ;

    }
    
Parameters
[in]argcargument count (should be zero)
[in]argvargument array (should be NULL)
Return values
examplePioClass*Pointer to self.

Set to non-zero to get output to stdout.

Zero-based rank of processor.

Number of processors involved in current execution.

Different output flavors. The example file is written (and then read) four times. The first two flavors, parallel-netcdf, and netCDF serial, both produce a netCDF classic format file (but with different libraries). The last two produce netCDF4/HDF5 format files, written with and without using netCDF-4 parallel I/O.

Number of processors that will do IO. In this example we will do IO from all processors.

Stride in the mpi rank between io tasks. Always 1 in this example.

Zero based rank of first processor to be used for I/O.

The dimension ID.

Array index per processing unit. This is the number of elements of the data array that will be handled by each processor. In this example there are 16 data elements. If the example is run on 4 processors, then arrIdxPerPe will be 4.

Start/Count in two dimension for this process' output in a global array

The ID for the parallel I/O system. It is set by PIOc_Init_Intracomm(). It references an internal structure containing the general IO subsystem data and MPI structure. It is passed to PIOc_finalize() to free associated resources, after all I/O, but before MPI_Finalize is called.

The ncid of the netCDF file created in this example.

The IDs of the netCDF variables in the example file.

A buffer for sample data. The size of this array will vary depending on how many processors are involved in the execution of the example code. It's length will be the same as elements_per_pe.

Test filename.

The number of netCDF flavors available in this build.

Used for command line processing.

Return value.

Variable Documentation

◆ err_buffer

char err_buffer[MPI_MAX_ERROR_STRING]

Global err buffer for MPI.

When there is an MPI error, this buffer is used to store the error message that is associated with the MPI error.

◆ resultlen

int resultlen

This is the length of the most recent MPI error message, stored int the global error string.

◆ START_DATA_VAL

const int START_DATA_VAL = 42

The meaning of life, the universe, and everything.