[netcdfgroup] thread safety

Hi,

I am using netcdf in a threaded C program. I found that when I use more than 1 thread an assert in POSIX I/O routine fails

   posixio.c:376: px_rel: Assertion `pxp->bf_offset <= offset && offset
   < pxp->bf_offset + (off_t) pxp->bf_extent' failed.

this lead me to the FAQ which explains that nstcdf is not thread safe. I have a few questions below about what is the best approach to use netcdf in a threaded program.

Here are some details about my use case. the files are in classic format (not hdf5). The access to the files is read only. Each file contains a number of time steps. in my code time steps are assigned to threads for processing in parallel. each thread may read and process a number of variables from a given time step before moving on to another time step. the threads are sharing the file handles, to avoid having to re-open the same file multiple times.

Do I need to lock every netcdf call ?
when a thread will read a list of variables in a loop, is it better to have the lock outside the loop, or just around the read call ? Should file handles be local to a thread, or is sharing them more efficient ?

Thanks
Burlen
  • 2015 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: