Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

Use of mmap() for netcdf I/O - contributed source available

On Jul 18,  4:29pm, Laurent LE GAL wrote:

> Subject: Re: Use of NcVar::Put method
> ...
> still using NetCDF, I'd like to know if there's a way to memory map
> (mmap) a NetCDF matrix to accelerate data access. In our application we
> manipulate large amounts of data (typically 50Mb of sonar data) and need
> to access them very quickly. We use to memory map these data but with
> NetCDF, the only solution we found is to read the data matrix (without
> all the header information) in a memory mapped file and then use this
> file to access the data. This copy stage is of course not very
> effective. So we are looking for an other solution avoiding this copy
> operation.
>
>-- End of excerpt from Laurent LE GAL

On Jul 18, 12:04pm, Glenn P. Davis replied:

> The main reason I've avoided putting mmap access in netcdf is that it
> is a portability nightmare. We have a product, LDM, which we support
> on a much more restricted set of platforms than netcdf. It does use mmap
> where it can. The main problem beyond portabilty is shakey interoperability
> when one mmap()'s a NFS file. Sometimes it works, sometimes it doesn't
> depending on which NFS client and which NFS server. Many netcdf users
> aren't aware which files are NFS mounted on their systems :-).
>
> Having said all that, netcdf-3 _is_ layered so that an mmap-based "ncio"
> layer could be easily slid in underneath. For read-only, non-shared
> access, it would be a simple as mmap'ping the whole file in ncio_open()
> and calculating an offset for ncio->get().
> The interface is defined in libsrc/ncio.h and an implementation is
> libsrc/posixio.c.
>
>-- End of excerpt from Glenn P. Davis

There is now an implementation of the netcdf-3 internal "ncio"
which is built on the mmap() call available on many UNIX systems.
This should be pretty much invisible to users; it completely implements
the current interface.

It is available as
ftp://ftp.unidata.ucar.edu/pub/netcdf/contrib/mmapio.c

This is a "drop in" replacement for libsrc/ncio.c.
To use it, move ncio.c out of way, put this file in it's place, and recompile.

I have tested this on IRIX 6.2, SunOS 5.3, and HPUX 9.
Althought this does not have the same level of support as our entire netcdf
distribution, I'm interested in hearing if this does speed things up.
I will provide some support on a time available basis.
I did not run into any NFS problems using a SunOS 5.3 server with SunOS 5 or
HPUX clients. Perhaps implementations have improved.

Note for SGI users:
 On the IRIX platforms, we make use of their MAP_AUTOGROW flag to
eliminated some system calls. Among other things, this means that the file
will be rounded up in size to the nearest pagesize boundary as compared to a
netcdf file built with the posixio.c version of ncio. This may confuse you
when using 'cmp' to compare binary netcdf files.

Note for HPUX users:
 You will need to use the flag -D_HPUX_SOURCE when compiling mmapio.c.
Using this flag for all the cc compilations (CC='c89 -D_HPUX_SOURCE')
should work fine, but you will see some warnings which can be ignored.
The warnings will go away in the next general netcdf release.

-glenn




 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690