Write and read data with PIDX

Introduction

In these examples we describe how to write and read data using the PIDX library. We consider a global 3D regular grid domain that we will call global domain (g). This global domain represents the grid space where all the data resides.

In a parallel environment each core (e.g. MPI rank) owns a portion of the data that has to be written on the disk. We refer to this portion of the domain as local domain (l).

In this example we want to write in parallel data from a number of cores (N). For simplicity we define N local domains of equal size (i.e. calculate_per_process_offsets()). In a real case the local domains can have arbitrary size.

The data used for these examples are generated by a function (i.e. create_synthetic_simulation_data()) that fills the global grid with a gradient.

PIDX is an library that uses MPI, as such we need first of all to initialize MPI and get the some useful information (e.g. current rank and processors count). In this example is performed by the init_mpi() function.

If you want to write and read data in PIDX you just need to follow a few simple steps: - identify the per-process local domain - create a PIDX_access, it defines how you want to access the data (serial or parallel) - create or access a PIDX_file, it defines the dataset - define or read one or more PIDX_variable - write/read the variables

How to write

The data that we want to write from each processor can be considered as a box in the global domain. This box is represented by and offset (i.e. the position in the global domain) and a size (i.e. the number of elements in the box).

PIDX uses a struct called PIDX_point to represent a value in n-dimensional space. We can use this struct to define the global domain size, and the local box information.

The parameters that we use are: - output_file_name, the name of the file that we want to create - file_access_mode, in this case we create the file - pidx_access, the access configuration that we defined - global_size, the global domain size as we defined - file, the PIDX_file struct that we are creating

Other general settings that we want to do are setting the current timestep (i.e. logical time)using:

PIDX_set_current_time_step(file, ts);

and the current number of variables that we want to write, as following:

PIDX_set_variable_count(file, variable_count);

We are now ready to define these variables. A variable in PIDX is defined by: - a name - a number of bits, e.g. 32 for a 32 bit integer variable - a typename, e.g. "1*int32"

The number of bits is given by the product of number of bits per value (e.g. an int value has 32 bits) and values per sample (e.g. a vector of float with 3 components has 3 values per sample).

Also in this case we need to indicate the per-process local box information (i.e. local offset and local size) and the array where we want to store the data of this variable. When the PIDX_close(file) will be called the data of this variable will be copied to our local data array in row major order.