Commit 9ad81459 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Move specialization of IO-server netCDF open to pio code.

parent a74dae9c
......@@ -818,6 +818,62 @@ void getTimeStepData ( int tsID, int vdate, int vtime )
/************************************************************************/
#if defined (HAVE_LIBNETCDF) && ! defined (HAVE_PARALLEL_NC4)
static int
cdiPioStreamCDFOpenWrap(const char *filename, const char *filemode,
int filetype, stream_t *streamptr,
int recordBufIsToBeCreated)
{
switch (filetype)
{
case FILETYPE_NC4:
case FILETYPE_NC4C:
{
int rank, fileID;
if (commInqIOMode() == PIO_NONE
|| commInqRankColl() == (rank = cdiPioNextOpenRank()))
fileID = cdiStreamOpenDefaultDelegate(filename, filemode, filetype,
streamptr,
recordBufIsToBeCreated);
if (commInqIOMode() != PIO_NONE)
xmpi(MPI_Bcast(&fileID, 1, MPI_INT, rank, commInqCommColl()));
streamptr->ownerRank = rank;
return fileID;
}
default:
return cdiStreamOpenDefaultDelegate(filename, filemode, filetype,
streamptr, recordBufIsToBeCreated);
}
}
static void
cdiPioStreamCDFCloseWrap(stream_t *streamptr, int recordBufIsToBeDeleted)
{
int fileID = streamptr->fileID;
int filetype = streamptr->filetype;
if ( fileID == CDI_UNDEFID )
Warning("File %s not open!", streamptr->filename);
else
switch (filetype)
{
case FILETYPE_NC:
case FILETYPE_NC2:
case FILETYPE_NC4:
case FILETYPE_NC4C:
{
int rank, rankOpen;
if (commInqIOMode() == PIO_NONE
|| ((rank = commInqRankColl())
== (rankOpen = cdiPioSerialOpenFileMap(streamptr->self))))
cdiStreamCloseDefaultDelegate(streamptr, recordBufIsToBeDeleted);
break;
}
default:
cdiStreamCloseDefaultDelegate(streamptr, recordBufIsToBeDeleted);
}
}
#endif
/**
@brief is encapsulated in CDI library and run on I/O PEs.
......@@ -847,6 +903,8 @@ void IOServer ()
#elif defined (HAVE_LIBNETCDF)
cdiSerialOpenFileCount = xcalloc(sizeof (cdiSerialOpenFileCount[0]),
commInqSizeColl());
namespaceSwitchSet(NSSWITCH_STREAM_OPEN_BACKEND, cdiPioStreamCDFOpenWrap);
namespaceSwitchSet(NSSWITCH_STREAM_CLOSE_BACKEND, cdiPioStreamCDFCloseWrap);
#endif
for ( ;; )
......
......@@ -652,11 +652,6 @@ int cdiInqContents(stream_t * streamptr)
return (status);
}
#if USE_MPI && ! HAVE_PARALLEL_NC4 && defined HAVE_LIBNETCDF
extern int cdiPioNextOpenRank();
extern int cdiPioSerialOpenFileMap(int streamID);
#endif
int cdiStreamOpenDefaultDelegate(const char *filename, const char *filemode,
int filetype, stream_t *streamptr,
int recordBufIsToBeCreated)
......@@ -734,17 +729,7 @@ int cdiStreamOpenDefaultDelegate(const char *filename, const char *filemode,
case FILETYPE_NC4:
case FILETYPE_NC4C:
{
#if USE_MPI && ! defined (HAVE_PARALLEL_NC4)
int rank;
if (commInqIOMode() == PIO_NONE
|| commInqRankColl() == (rank = cdiPioNextOpenRank()))
#endif
fileID = cdf4Open(filename, filemode, &filetype);
#if USE_MPI && ! defined (HAVE_PARALLEL_NC4)
if (commInqIOMode() != PIO_NONE)
xmpi(MPI_Bcast(&fileID, 1, MPI_INT, rank, commInqCommColl()));
streamptr->ownerRank = rank;
#endif
fileID = cdf4Open(filename, filemode, &filetype);
break;
}
#endif
......@@ -1141,13 +1126,7 @@ cdiStreamCloseDefaultDelegate(stream_t *streamptr, int recordBufIsToBeDeleted)
case FILETYPE_NC4:
case FILETYPE_NC4C:
{
#if USE_MPI && ! defined (HAVE_PARALLEL_NC4)
int rank, rankOpen;
if (commInqIOMode() == PIO_NONE
|| ((rank = commInqRankColl())
== (rankOpen = cdiPioSerialOpenFileMap(streamptr->self))))
#endif
cdfClose(fileID);
cdfClose(fileID);
break;
}
#endif
......
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