next up previous contents
Next: NEMO AGRIF nested model Up: NEMO V3.0 Previous: Performance of NEMO V3.0   Contents

Converting NEMO to use netCDF 4.0

This section describes the procedure for adapting NEMO V3.0 to use netCDF 4.0. To compile NEMO V3.0 with netCDF 4.0 the main NEMO Makefile must be altered such that the NCDF_INC and NCDF_LIB variables point to the location of the netCDF 4.0 include files and libraries. The paths to the HDF5, zlib or szip include files and libraries must also be added. E.g. including the following in the three main NEMO Makefiles ensures that the netCDF 4.0 library is used:
H5HOME = /work/n01/n01/fionanem/local/noparallel
ZLIBHOME = /work/n01/n01/fionanem/local
NCDF_INC = /work/n01/n01/fionanem/local/noparallel/include \
  -I$(H5HOME)/include -I$(ZLIBHOME)/include 
NCDF_LIB = -L/work/n01/n01/fionanem/local/noparallel/lib \ 
  -lnetcdf -L$(H5HOME)/lib -lhdf5 -lhdf5_hl -L$(ZLIBHOME)/lib \ 
  -lz -lsz -L$(H5HOME)/lib -lhdf5
After re-compilation the code is executed and the output verified as being correct using the method described in section 5.3.

The procedure above uses netCDF 4.0 in classic mode and is the first step in converting NEMO to use netCDF 4.0. However, what we actually want to do is to convert NEMO to use netCDF 4.0 with compression and chunking enabled. This is best tackled as a two stage process. The first step is to generate netCDF 4.0 format output files without any compression/chunking. The second step is to add chunking and/or compression and thus take advantage of the full functionality of netCDF 4.0.

For step one we need to tell netCDF that we want to take advantage of the new features. This can be achieved by making some minor modifications to the NEMO code. In particular, all subroutine calls to NF90_CREATE need to be modified such that each instance of NF90_NOCLOBBER is replaced with NF90_HDF5. The two source files which require alteration are:-

In addition, the file IOIPSL/src/fliocom.f90 also requires the variable m_c to be set to NF90_HDF5. At present the mode of this variable has been set directly after the conditional block from lines 859-884. E.g. we replace
  i_rc = NF90_CREATE(f_nw,m_c,f_e)
  m_c = NF90_HDF5
  i_rc = NF90_CREATE(f_nw,m_c,f_e)
With these modifications the code is then recompiled and tested. The main output files should now be in netCDF 4.0 format which can be verified by attempting to read one of the output files with versions of ncdump 1which have been compiled with netCDF 3.6.2 and with netCDF 4.0, e.g.
  1. Using ncdump from version 3.6.2 of netCDF (e.g. module load netcdf/3.6.2) attempt to read one of the NEMO output files,
    e.g. ncdump if this is successful (i.e. the contents of the file are displayed) then the file is a classic netCDF 3.X format file. If it is not an netCDF 3.X file then you'll get an error message of the form: ncdump: NetCDF: Unknown file format
  2. Now try ncdump from netCDF 4.0. The version installed under
    /work/n01/n01/fionanem/local/noparallel/bin/ncdump can be used or that added to your path when the new centrally installed netCDF 4.0 is loaded (use module load netcdf to achieve this). If the file is in netCDF 4.0 format then the contents of the file will be displayed. Please note: netCDF 4.0 can also read netCDF 3.X files so just testing with one version of ncdump is not sufficient.

The modifications described above allow netCDF 4.0 format files to be output from NEMO. However, as yet no compression or chunking has been included. To use the chunking/compression features of netCDF 4.0 additional modifications must be made to the code. These modifications are outlined below:

  1. Declare new variables relating to the chunking and compression, e.g.
      INTEGER, dimension(4) :: chunksizes 
      INTEGER :: chunkalg, shuffle, deflate, deflate_level
    chunksizes is an array containing the chunksize to be used for each dimension of the dataset.
  2. Initialise the chunking and compression variables, e.g.
      chunksizes(1) = 10
      chunksizes(2) = 10
      chunksizes(3) = 10
      chunksizes(4) = 1
      deflate_level = 1 ! Turn compression on
      deflate = 1       ! Level of compression
      shuffle = 1       ! Allow shuffling
      chunkalg = 0      ! Turn chunking on
    Here chunksize is chosen such that it is less than the number of data points within that dimension. It should be noted that for three-dimensional fields such as the ice data (i.e. *icemod*.nc files) this may not be ideal.
  3. Following each call to nf90_def_var, add new calls to nf90_def_var_chunking and
    nf90_def_var_deflate to ensure that chunking and compression is applied to each output variable. An example of the original code would be:
    iret = NF90_DEF_VAR (ncid,lon_name,NF90_FLOAT,dims(1:ndim),nlonid)
    with the modified code example including the following two lines immediately after the call to NF90_DEF_VAR, e.g.
    iret = NF90_DEF_VAR_CHUNKING(ncid,nlonid,chunkalg,chunksizes)
    iret = NF90_DEF_VAR_DEFLATE(ncid,nlonid,shuffle,deflate, deflate_level)
Modifications were made to ../../IOIPSL/restcom.f90, ../../IOIPSL/histcom.f90 and ../../IOIPSL/fliocom.f90. However, after testing the code it became apparent than only the changes to the ../../IOIPSL/histcom.f90 file are actually required for the test model. Furthermore, the changes were not added for the NF90_DEF_VAR call at line 1022 (unmodified code) as this was found to truncate the *icemod*.nc file.

The code was then re-tested and the size of the output files compared with those created without and chunking/compression. For the original code some sample output file sizes were as follows:

ls -l *
-rw-r--r--  1 fionanem n01 47364120 Apr 17 09:40
-rw-r--r--  1 fionanem n01  2286160 Apr 17 09:40
-rw-r--r--  1 fionanem n01  7102636 Apr 17 09:40
-rw-r--r--  1 fionanem n01  3246008 Apr 17 09:40
-rw-r--r--  1 fionanem n01  3246013 Apr 17 09:40
-rw-r--r--  1 fionanem n01 15709982 Apr 17 09:40
-rw-r--r--  1 fionanem n01  1118067 Apr 17 09:40
For the modified version the corresponding files sizes were:
ls -l *
-rw-r--r--  1 fionanem n01 47364120 Apr 21 13:01
-rw-r--r--  1 fionanem n01  2286160 Apr 21 13:01
-rw-r--r--  1 fionanem n01  1765659 Apr 21 13:01
-rw-r--r--  1 fionanem n01   932602 Apr 21 13:01
-rw-r--r--  1 fionanem n01   939433 Apr 21 13:01
-rw-r--r--  1 fionanem n01  2569717 Apr 21 13:01
-rw-r--r--  1 fionanem n01   536500 Apr 21 13:01
Comparing the output file sizes we see that the four *grid*.nc and *icemod*.nc files have reduced in size by up to 3.55 times relative to the original data. The two restart files are not affected as no compression/chunking has been applied to these. The overall effect of the chunking/compression for the test model is summarised by table 11.

Table 11: Effect of chunking and compression on the size of the NEMO 3.0 output files. For each file name the usage is the sum of all 221 individual processor output files.
File name Disk usage for netCDF 3.X (MBytes) Disk usage for netCDF 4.0 (Mbytes) Reduction factor
*grid_T*.nc 1500 586 2.56
*grid_U*.nc 677 335 2.02
*grid_V*.nc 677 338 2.00
*grid_W*.nc 3300 929 3.55
*icemod*.nc 208 145 1.43

The results presented in table 11 demonstrate that a significant reduction in disk usage ($\sim$4 Gbytes for this example) can be achieved by using the chunking and or compression features of netCDF 4.0 within NEMO. For the test model, no significant improvement in the runtime is observed however this is to be expected as the restart files dominate in terms of their size. In our test model we run for 60 time steps, outputting data every 30 time steps with a restart model written output after 60 time steps. However, for a production run of NEMO the model would typically run for in excess of 10,000 time steps with output every 300 steps and a restart file written every 1800 time steps. Therefore an improvement in runtime would be expected due to the reduction in output file size. The actual size of any improvement will depend on the output frequency chosen, which in turn depends on the parameters being modelled and the particular science studied.

Conversion of the restart files to netCDF 4.0 and a full investigation of the optimal chunksize/compression parameters were not possible due to a shift in focus requested by the researchers where we were asked to concentrate on the nested AGRIF models.

next up previous contents
Next: NEMO AGRIF nested model Up: NEMO V3.0 Previous: Performance of NEMO V3.0   Contents