SCORPIO
1.7.0
|
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>
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... | |
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.
#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.
#define DIM_LEN_Y 5 |
#define DIM_NAME_X "x" |
The name of the dimension in the netCDF output file.
#define DIM_NAME_Y "y" |
#define ERR | ( | e | ) |
Handle non-MPI errors by finalizing the MPI library and exiting with an exit code.
#define ERR_BAD 1001 |
Return code when netCDF output file does not match expectations.
#define MPIERR | ( | e | ) |
Handle MPI errors.
This should only be used with MPI library function calls.
#define NDIM 2 |
The number of dimensions in the example data.
In this simple example, we are using one-dimensional data.
#define NUM_NETCDF_FLAVORS 5 |
The number of possible output netCDF output flavors available to the ParallelIO library.
#define VAR_NAME_D0 "d0" |
The name of the variables in the netCDF output file.
#define VAR_NAME_D1 "d1" |
#define VAR_NAME_D2 "d2" |
int main | ( | int | argc, |
char * | argv[] | ||
) |
Main execution of code.
Executes the functions to:
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 ; }
[in] | argc | argument count (should be zero) |
[in] | argv | argument array (should be NULL) |
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.
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.
int resultlen |
This is the length of the most recent MPI error message, stored int the global error string.
const int START_DATA_VAL = 42 |
The meaning of life, the universe, and everything.