Skip to content
Snippets Groups Projects
Commit bc876d6c authored by Thomas Jahns's avatar Thomas Jahns :cartwheel: Committed by Sergey Kosukhin
Browse files

Refine NC_PNETCDF work-around.

* Versions 4.1 to 4.3.2 of netcdf do not provide programmatically useful
  pre-processor predicate if the pnetcdf layer is available and report
  success when the nc_create call actually failed.
parent 55b892bc
No related branches found
No related tags found
2 merge requests!34Version 2.2.0,!13Consolidation with CDI-PIO (develop)
......@@ -292,7 +292,17 @@ main(int argc, char **argv)
CPPFLAGS=$saved_CPPFLAGS
],
[enable_ppm=no])
dnl
dnl NC_HAS_PNETCDF is useful when available to short-circuit some tests
AS_IF([test x"$ENABLE_NETCDF" = xyes],
[AC_CHECK_HEADERS([netcdf_meta.h])
AS_IF([test "x$NC_CONFIG" != "x"],
[AC_MSG_CHECKING([parallel netcdf's pnetcdf support])
acx_temp=`$NC_CONFIG --has-pnetcdf`
AS_IF([test "x$acx_temp" = "xyes"],
[AC_DEFINE([HAVE_NETCDF_PAR_PNETCDF],[1],
[Defined to 1 if NetCDF parallel open supports NC_PNETCDF])])
AC_MSG_RESULT([$acx_temp])])])
AS_IF([test x"$ENABLE_NC4" = xyes],
[AC_CHECK_HEADERS([netcdf_par.h],
[AC_CHECK_DECL([MPI_Bcast],
......
......@@ -7,10 +7,15 @@
#include <setjmp.h>
#include <stdbool.h>
#include <mpi.h>
#include <netcdf.h>
#if defined HAVE_PARALLEL_NC4 && defined HAVE_NETCDF_PAR_H
#include <netcdf_par.h>
#endif
#ifdef HAVE_NETCDF_META_H
#include <netcdf_meta.h>
#endif
#include "namespace.h"
#include "pio.h"
......@@ -29,15 +34,27 @@ pthread_key_t cdiPioCdfJmpKey;
TLS struct cdiPioNcCreateLongJmpRetBuf *cdiPioCdfJmpBuf;
#endif
#if defined NC_HAS_PNETCDF && NC_HAS_PNETCDF
/* NetCDF 4.3.3 introduced the NC_HAS_PNETCDF define so we can deduce
* reliably in this and later versions if parallel opening of
* classic, 64bit-offset and CDF-5 files can even succeed at all. */
#define CDI_PIO_TRY_PNETCDF 1
#elif defined NC_PNETCDF && defined HAVE_NETCDF_PAR_PNETCDF
#define CDI_PIO_TRY_PNETCDF HAVE_NETCDF_PAR_PNETCDF
#else
#define CDI_PIO_TRY_PNETCDF 0
#endif
static int
cdiPio_nc__create(const char *path, int cmode, size_t initialsz, size_t *chunksizehintp, int *ncidp)
{
int status, ioMode = commInqIOMode();
if (ioMode != PIO_NONE)
{
#ifdef NC_PNETCDF
#if CDI_PIO_TRY_PNETCDF
#if !defined TLS && defined HAVE_PTHREAD
struct cdiPioNcCreateLongJmpRetBuf *cdiPioCdfJmpBuf = pthread_getspecific(cdiPioCdfJmpKey);
#endif
#endif
if (cmode & NC_NETCDF4)
{
......@@ -47,6 +64,8 @@ cdiPio_nc__create(const char *path, int cmode, size_t initialsz, size_t *chunksi
}
else
{
int rank = commInqRankColl();
#if CDI_PIO_TRY_PNETCDF
/* which combination of cmode flags has already been tested? */
static bool pnetcdfWontWork[] = {
false, /* CDF-1 */
......@@ -62,7 +81,6 @@ cdiPio_nc__create(const char *path, int cmode, size_t initialsz, size_t *chunksi
else
cdfIdx = 2;
MPI_Comm collComm = commInqCommColl();
int rank = commInqRankColl();
cmode |= NC_PNETCDF;
if (!pnetcdfWontWork[cdfIdx])
{
......@@ -88,7 +106,7 @@ cdiPio_nc__create(const char *path, int cmode, size_t initialsz, size_t *chunksi
status = nc__create(path, cmode, initialsz, chunksizehintp, ncidp);
else
longjmp(cdiPioCdfJmpBuf->jmpBuf, 1);
#ifdef NC_PNETCDF
#if CDI_PIO_TRY_PNETCDF
}
#endif
}
......@@ -113,7 +131,7 @@ cdiPioCdfDefVar(int ncid, const char *name, nc_type xtype, int ndims, const int
}
}
#ifdef NC_PNETCDF
#if CDI_PIO_TRY_PNETCDF
static void
cdiPio_enable_nc_par_access(int ncid, int streamID)
{
......@@ -156,14 +174,13 @@ cdiPio_nc__enddef(int ncid, int streamID, size_t hdr_pad, size_t v_align, size_t
if (statusEndDef == NC_NOERR) cdiPio_enable_nc_par_access(ncid, streamID);
return statusEndDef;
}
#endif
#endif /* CDI_PIO_TRY_PNETCDF */
void
cdiPioEnableNetCDFParAccess(void)
{
namespaceSwitchSet(NSSWITCH_NC__CREATE, NSSW_FUNC(cdiPio_nc__create));
#ifdef NC_PNETCDF
#if CDI_PIO_TRY_PNETCDF
namespaceSwitchSet(NSSWITCH_NC_ENDDEF, NSSW_FUNC(cdiPio_nc_enddef));
namespaceSwitchSet(NSSWITCH_NC__ENDDEF, NSSW_FUNC(cdiPio_nc__enddef));
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment