|
1 | 1 | # Difference between NetCDF4-python and PnetCDF-python
|
2 | 2 |
|
| 3 | +* [Supported File Formats](#supported-file-formats) |
| 4 | +* [Differences in Python Programming](#differences-in-python-programming) |
| 5 | +* [Blocking vs. Nonblocking APIs](#blocking-vs-nonblocking-apis) |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Supported File Formats |
| 10 | +* NetCDF4 supports both classic and HDF5-based file formats. |
| 11 | + + Classic file format (CDF-1) -- The ESDS Community Standard defined the file format |
| 12 | + to be used in the NetCDF user community in 1989. The file header bears a |
| 13 | + signature of character string 'CDF-1' and now is commonly referred to as |
| 14 | + 'CDF-1' file format. |
| 15 | + * 'CDF-2' format -- The CDF-1 format was later extended to support large |
| 16 | + file size (i.e. larger than 2GB) in 2004. See its specification in |
| 17 | + [ESDS-RFC-011v2.0](https://cdn.earthdata.nasa.gov/conduit/upload/496/ESDS-RFC-011v2.00.pdf). |
| 18 | + Because its file header bears a signature of 'CDF-2' and the format is |
| 19 | + also commonly referred to as 'CDF-2' format. |
| 20 | + * 'CDF-5' format -- The CDF-2 format was extended by PnetCDF developer team |
| 21 | + in 2009 to support large variables and additional large data types, such |
| 22 | + as 64-bit integer. |
| 23 | + + HDF5-based file format -- Starting from its version 4.0.0, NetCDF includes |
| 24 | + the format that is based on HDF5, which is referred to as NetCDF-4 format. |
| 25 | + This offer new features such as groups, compound types, variable length |
| 26 | + arrays, new unsigned integer types, etc. |
| 27 | +* PnetCDF supports only the classic file formats. |
| 28 | + + The classic files created by applications using NetCDF4 library can be read |
| 29 | + by the PnetCDF library and vice versa. |
| 30 | + + PnetCDF provides parallel I/O for accessing files in the classic format. |
| 31 | + NetCDF4's parallel I/O for classic files makes use of PnetCDF library |
| 32 | + underneath. Such feature can be enabled when building NetCDF4 library. |
| 33 | + |
3 | 34 | ---
|
4 |
| -## Programming differences |
5 |
| -* Table below shows two python example codes. |
| 35 | + |
| 36 | +## Differences in Python Programming |
| 37 | +* Table below shows two python example codes and their differences. |
6 | 38 | + Both example codes create a new file, define dimensions, define a variable
|
7 | 39 | named `WIND` of type `NC_DOUBLE` and then write to it in the collective I/O
|
8 | 40 | mode.
|
|
27 | 59 | | ... ||
|
28 | 60 | | # close file<br>f.close() | ditto NetCDF4 |
|
29 | 61 |
|
| 62 | +--- |
| 63 | + |
| 64 | +## Blocking vs Nonblocking APIs |
| 65 | +* Blocking APIs -- All NetCDF4 APIs are blocking APIs. A blocking API means the |
| 66 | + call to the API will not return until the operation is completed. For |
| 67 | + example, `nc_put_vara_float()` will return only when the write data has been |
| 68 | + stored at the system space, e.g. file systems. Similarly, |
| 69 | + `nc_get_vara_float()` will only return when the user read buffer containing |
| 70 | + the data retrieved from the file. Therefore, when a series of `put/get` |
| 71 | + blocking APIs are called, these calls will be committed by the NetCDF4 |
| 72 | + library one at a time, following the same order of the calls. |
| 73 | +* Nonblocking APIs -- In addition to blocking APIs, PnetCDF provides the |
| 74 | + nonblocking version of the APIs. A nonblocking API means the call to the API |
| 75 | + will return as soon as the `put/get` request has been registered in the |
| 76 | + PnetCDF library. The commitment of the request may happen later, when a call |
| 77 | + to `ncmpi_wait_all/ncmpi_wait` is made. |
| 78 | +* The advantage of using nonblocking APIs is when there are many small |
| 79 | + `put/get` requests and each of them has a small amount. PnetCDF tries to |
| 80 | + aggregate and coalesce multiple registered nonblocking requests into a large |
| 81 | + one, because I/O usually performs better when the request amounts are large |
| 82 | + and contiguous. [nonblocking_write.py](../examples/nonblocking_write.py) is |
| 83 | + an example that makes use of nonblocking APIs. |
| 84 | +* Table below shows the difference in python programming between using blocking |
| 85 | + and nonblocking APIs. |
| 86 | + |
| 87 | +| PnetCDF Blocking APIs | PnetCDF Nonblocking APIs | |
| 88 | +|:-------|:--------| |
| 89 | +| ...<br># define 3 variables of NC_DOUBLE type || |
| 90 | +| psfc = f.createVariable("PSFC", "f8", ("time", "lat", "lon"))<br>prcp = f.createVariable("prcp", "f8", ("time", "lat", "lon"))<br>snow = f.createVariable("SNOW", "f8", ("time", "lat", "lon")) | ditto | |
| 91 | +| ... || |
| 92 | +| # exit define mode and enter data mode<br>f.enddef() | ditto | |
| 93 | +| ...<br># Call blocking APIs to write 3 variables to the file | <br># Call nonblocking APIs to post 3 write requests | |
| 94 | +| psfc.put_var_al(psfc_buf, start, count)<br>prcp.put_var_al(prcp_buf, start, count)<br>snow.put_var_al(snow_buf, start, count)<br>| reqs = [0]*3<br>reqs[0] = psfc.iput_var(psfc_buf, start, count)<br>reqs[1] = prcp.iput_var(prcp_buf, start, count)<br>reqs[2] = snow.iput_var(snow_buf, start, count)| |
| 95 | +| | # Wait for nonblocking APIs to complete<br>errs = [0]*3<br>f.wait_all(3, reqs, errs)| |
| 96 | + |
| 97 | + |
0 commit comments