Commit afac9e41 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Virtualize cdfDefTimestep.

parent 9ad81459
......@@ -10,12 +10,13 @@
#include "cdf_int.h"
#include "file.h"
#include "cdi_int.h"
#include "stream_cdf.h"
static int nNamespaces = 1;
static int activeNamespace = 0;
#ifdef HAVE_LIBNETCDF
#define CDI_NETCDF_SWITCHES nc__create,cdf_def_var_serial,
#define CDI_NETCDF_SWITCHES nc__create,cdf_def_var_serial,cdfDefTimestep,
#else
#define CDI_NETCDF_SWITCHES
#endif
......
......@@ -35,6 +35,7 @@ enum namespaceSwitch
#ifdef HAVE_LIBNETCDF
NSSWITCH_NC__CREATE,
NSSWITCH_CDF_DEF_VAR,
NSSWITCH_CDF_DEF_TIMESTEP,
#endif
NUM_NAMESPACE_SWITCH,
};
......
......@@ -768,6 +768,13 @@ static int pioNamespace_ = -1;
static int xtInitByCDI = 0;
#endif
#if defined USE_MPI && defined HAVE_LIBNETCDF
static void
cdiPioCdfDefTimestepNOP(stream_t *streamptr, int tsID)
{
}
#endif
MPI_Comm
pioInit(MPI_Comm commGlob, int nProcsIO, int IOMode,
int *pioNamespace, float partInflate)
......@@ -837,6 +844,9 @@ pioInit(MPI_Comm commGlob, int nProcsIO, int IOMode,
namespaceSwitchSet(NSSWITCH_STREAM_WRITE_VAR_CHUNK_,
cdiPioStreamWriteVarChunk_);
namespaceSwitchSet(NSSWITCH_STREAM_CLOSE_BACKEND, cdiPioStreamClose);
#ifdef HAVE_LIBNETCDF
namespaceSwitchSet(NSSWITCH_CDF_DEF_TIMESTEP, cdiPioCdfDefTimestepNOP);
#endif
pioNamespaceSetActive(callerCDINamespace);
}
......
......@@ -31,6 +31,7 @@
#include "pio_cdf_int.h"
#include "resource_handle.h"
#include "resource_unpack.h"
#include "stream_cdf.h"
#include "vlist_var.h"
......@@ -830,12 +831,13 @@ cdiPioStreamCDFOpenWrap(const char *filename, const char *filemode,
case FILETYPE_NC4C:
{
int rank, fileID;
if (commInqIOMode() == PIO_NONE
int ioMode = commInqIOMode();
if (ioMode == PIO_NONE
|| commInqRankColl() == (rank = cdiPioNextOpenRank()))
fileID = cdiStreamOpenDefaultDelegate(filename, filemode, filetype,
streamptr,
recordBufIsToBeCreated);
if (commInqIOMode() != PIO_NONE)
if (ioMode != PIO_NONE)
xmpi(MPI_Bcast(&fileID, 1, MPI_INT, rank, commInqCommColl()));
streamptr->ownerRank = rank;
return fileID;
......@@ -872,6 +874,17 @@ cdiPioStreamCDFCloseWrap(stream_t *streamptr, int recordBufIsToBeDeleted)
cdiStreamCloseDefaultDelegate(streamptr, recordBufIsToBeDeleted);
}
}
static void
cdiPioCdfDefTimestep(stream_t *streamptr, int tsID)
{
int rank, rankOpen, streamID = streamptr->self;
if (commInqIOMode() == PIO_NONE
|| ((rank = commInqRankColl())
== (rankOpen = cdiPioSerialOpenFileMap(streamID))))
cdfDefTimestep(streamptr, tsID);
}
#endif
/**
......@@ -905,6 +918,7 @@ void IOServer ()
commInqSizeColl());
namespaceSwitchSet(NSSWITCH_STREAM_OPEN_BACKEND, cdiPioStreamCDFOpenWrap);
namespaceSwitchSet(NSSWITCH_STREAM_CLOSE_BACKEND, cdiPioStreamCDFCloseWrap);
namespaceSwitchSet(NSSWITCH_CDF_DEF_TIMESTEP, cdiPioCdfDefTimestep);
#endif
for ( ;; )
......
......@@ -1359,21 +1359,18 @@ int streamDefTimestep(int streamID, int tsID)
streamptr->ntsteps = tsID + 1;
if (namespaceHasLocalFile(namespaceGetActive())
&& (streamptr->filetype == FILETYPE_NC ||
streamptr->filetype == FILETYPE_NC2 ||
streamptr->filetype == FILETYPE_NC4 ||
streamptr->filetype == FILETYPE_NC4C)
#ifdef HAVE_LIBNETCDF
if ((streamptr->filetype == FILETYPE_NC ||
streamptr->filetype == FILETYPE_NC2 ||
streamptr->filetype == FILETYPE_NC4 ||
streamptr->filetype == FILETYPE_NC4C)
&& vlistHasTime(vlistID))
{
#if USE_MPI && defined (HAVE_LIBNETCDF) && ! defined (HAVE_PARALLEL_NC4)
int rank, rankOpen;
if (commInqIOMode() == PIO_NONE
|| ((rank = commInqRankColl())
== (rankOpen = cdiPioSerialOpenFileMap(streamID))))
#endif
cdfDefTimestep(streamptr, tsID);
void (*myCdfDefTimestep)(stream_t *streamptr, int tsID)
= namespaceSwitchGet(NSSWITCH_CDF_DEF_TIMESTEP);
myCdfDefTimestep(streamptr, tsID);
}
#endif
cdi_create_records(streamptr, tsID);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment