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

Add post-setup function to call on I/O servers.

parent ddcfacb9
......@@ -8,7 +8,8 @@ CDI library routines:
\begin{verbatim}
MPI_Comm pioInit (MPI_Comm commSuper, int nProcsIO, int IOMode,
int *pioNamespace, float partInflate);
int *pioNamespace, float partInflate,
void (*postCommSetupActions)(void));
\end{verbatim}
initialize I/O server processes and communication.
......
......@@ -7,8 +7,9 @@ CDI library routines:
\section*{\tt \htmlref{pioInit}{pioInit}}
\begin{verbatim}
INTEGER FUNCTION pioInit (INTEGER commSuper, INTEGER nProcsIO, INTEGER IOMode,
INTEGER pioNamespace, REAL partInflate)
INTEGER FUNCTION pioInit (INTEGER commSuper, INTEGER nProcsIO, INTEGER IOMode,
INTEGER pioNamespace, REAL partInflate,
PROCEDURE postCommSetupActions)
\end{verbatim}
initialize I/O server processes and communication.
......
......@@ -221,7 +221,8 @@ int main (int argc, char *argv[])
}
}
commModel = pioInit(commGlob, nProcsIO, IOMode, &pioNamespace, 1.0f);
commModel = pioInit(commGlob, nProcsIO, IOMode, &pioNamespace, 1.0f,
cdiPioNoPostCommSetup);
pioNamespaceSetActive(pioNamespace);
#endif
......
......@@ -39,7 +39,8 @@ PROGRAM collectdata2003
! For parallel IO:
! Initialize environment.
commModel = pioInit(commGlob, nProcsIO, IOMode, pio_namespace, 1.1)
commModel = pioInit(commGlob, nProcsIO, IOMode, pio_namespace, 1.1, &
cdiPioNoPostCommSetup)
CALL pioNamespaceSetActive(pio_namespace)
#endif
......
......@@ -263,7 +263,8 @@ int main (int argc, char *argv[])
nProcsIO = nProcsIODef;
}
commModel = pioInit(commGlob, nProcsIO, IOMode, &pioNamespace, 1.0f);
commModel = pioInit(commGlob, nProcsIO, IOMode, &pioNamespace, 1.0f,
cdiPioNoPostCommSetup);
pioNamespaceSetActive(pioNamespace);
#endif
......
......@@ -243,7 +243,8 @@ int main (int argc, char *argv[])
if ( nProcsIO != 1 )
xabort ( "bad distribution of tasks on PEs" );
commModel = pioInit(commGlob, nProcsIO, IOMode, &pioNamespace, 1.0f);
commModel = pioInit(commGlob, nProcsIO, IOMode, &pioNamespace, 1.0f,
cdiPioNoPostCommSetup);
pioNamespaceSetActive(pioNamespace);
modelRun ( commModel );
......
......@@ -28,9 +28,13 @@
void pioEndDef ( void );
void pioEndTimestepping ( void );
void pioFinalize ( void );
/* Dummy function to use as argument to pioInit if no actions are
* ncecessary after I/O servers initialize communication */
void cdiPioNoPostCommSetup(void);
/* pioInit: initialize I/O server processes and communication */
MPI_Comm pioInit(MPI_Comm commSuper, int nProcsIO, int IOMode,
int *pioNamespace, float partInflate);
int *pioNamespace, float partInflate,
void (*postCommSetupActions)(void));
void pioWriteTimestep();
void cdiPioRDMAProgress();
......
......@@ -32,12 +32,16 @@
! pioFinalize
EXTERNAL pioFinalize
! cdiPioNoPostCommSetup
EXTERNAL cdiPioNoPostCommSetup
INTEGER pioInit
! (INTEGER commSuper,
! INTEGER nProcsIO,
! INTEGER IOMode,
! INTEGER pioNamespace,
! REAL partInflate)
! REAL partInflate,
! PROCEDURE postCommSetupActions)
EXTERNAL pioInit
! pioWriteTimestep
......
......@@ -27,18 +27,22 @@
FCALLSCSUB0 (pioEndDef, PIOENDDEF, pioenddef)
FCALLSCSUB0 (pioEndTimestepping, PIOENDTIMESTEPPING, pioendtimestepping)
FCALLSCSUB0 (pioFinalize, PIOFINALIZE, piofinalize)
static int pioInit_fwrap(int commSuper, int nProcsIO, int IOMode, int * pioNamespace, float partInflate)
FCALLSCSUB0 (cdiPioNoPostCommSetup, CDIPIONOPOSTCOMMSETUP, cdipionopostcommsetup)
#undef ROUTINE_5
#define ROUTINE_5 (void (*)(void))
static int pioInit_fwrap(int commSuper, int nProcsIO, int IOMode, int *pioNamespace, float partInflate, void (*postCommSetupActions)(void))
{
MPI_Comm v;
v = pioInit(MPI_Comm_f2c(commSuper), nProcsIO, IOMode, pioNamespace, partInflate);
v = pioInit(MPI_Comm_f2c(commSuper), nProcsIO, IOMode, pioNamespace, partInflate, postCommSetupActions);
return MPI_Comm_c2f(v);
}
FCALLSCFUN5 (INT, pioInit_fwrap, PIOINIT, pioinit, INT, INT, INT, PINT, FLOAT)
FCALLSCFUN6 (INT, pioInit_fwrap, PIOINIT, pioinit, INT, INT, INT, PINT, FLOAT, ROUTINE)
FCALLSCSUB0 (pioWriteTimestep, PIOWRITETIMESTEP, piowritetimestep)
FCALLSCSUB0 (cdiPioRDMAProgress, CDIPIORDMAPROGRESS, cdipiordmaprogress)
static void streamWriteVarPart_fwrap(int streamID, int varID, const void * data, int nmiss, void * partDesc)
static void streamWriteVarPart_fwrap(int streamID, int varID, const void *data, int nmiss, void *partDesc)
{
streamWriteVarPart( streamID, varID, data, nmiss, (*(Xt_idxlist *)partDesc));
streamWriteVarPart(streamID, varID, data, nmiss, (*(Xt_idxlist *)partDesc));
}
FCALLSCSUB5 (streamWriteVarPart_fwrap, STREAMWRITEVARPART, streamwritevarpart, INT, INT, PVOID, INT, PVOID)
FCALLSCSUB1 (pioNamespaceSetActive, PIONAMESPACESETACTIVE, pionamespacesetactive, INT)
......
......@@ -87,7 +87,7 @@ static void doctotxt(FILE *fp, Docu *doc, size_t ndoc)
enum cftype {ISVOID, ISCONSTSTRING, ISINT, ISREAL, ISDOUBLE, ISMPI_COMM,
ISXT_IDXLIST, ISCHOICE, ISINTP, ISINTV, ISINTVV, ISREALP,
ISDOUBLEP, ISCBUF, ISSTRING, ISSTRINGP,
ISDOUBLEP, ISCBUF, ISSTRING, ISSTRINGP, VOIDFUNCVOID,
NUM_KNOWN_ARG_TYPES};
enum conversionType { CONV_ARG, CONV_RET };
......@@ -95,6 +95,8 @@ enum conversionType { CONV_ARG, CONV_RET };
typedef int (*cfConversionEmitter)(FILE *outfp, const char *argName,
size_t argNameLen, enum conversionType part);
typedef int (*cfPrologueEmitter)(FILE *outfp, size_t argNum);
static int cfMPICommConvert(FILE *outfp, const char *argName,
size_t argNameLen, enum conversionType part);
......@@ -102,13 +104,16 @@ static int cfMPICommConvert(FILE *outfp, const char *argName,
static int cfXtIdxlistConvert(FILE *outfp, const char *argName,
size_t argNameLen, enum conversionType part);
static int cfVoidFuncPrologue(FILE *outfp, size_t argNum);
struct symbol {
const char *f77name, *cfint, *cfmt, *parseRE;
/* pair of parentheses which matches the argument name */
size_t nameMatch;
int needsExtraWrapper;
int needsExtraWrapper, needsPrologue;
cfConversionEmitter convert;
const char *convcfmt;
cfPrologueEmitter prologue;
regex_t preg;
};
......@@ -155,6 +160,10 @@ static struct symbol funArgSym[]
"^"WS"*const"WS"+char"WS"+\\*"WS"*"SYMRE"?"WS"*[,\\)]", 1, 0, 0 },
{ "CHARACTER*(*)", "PSTRING", "char *%.*s",
"^"WS"*char"WS"+\\*"SYMRE"?"WS"*[,\\)]", 1, 0, 0 },
{ "PROCEDURE", "ROUTINE", "void (*%.*s)(void)",
"^"WS"*void"WS"*\\("WS"*\\*"WS"*"SYMRE"?"WS"*\\)"
WS"*\\("WS"*void"WS"*\\)"WS"*[,\\)]", 1, 0, 1,
NULL, NULL, cfVoidFuncPrologue }
};
static struct symbol funRet[] = {
......@@ -324,7 +333,7 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint,
functype = ISVOID;
size_t funcargc = 0;
pline = line;
int needsExtraWrapper = 0;
int needsExtraWrapper = 0, needsPrologue = 0;
size_t funcnameLen;
enum decl declType = UNKNOWN_DECL;
do {
......@@ -361,24 +370,38 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint,
funcargname[funcargc].rm_so = (regoff_t)(pline - line);
{
ssize_t i = 0;
size_t innerParens = 0;
do {
ssize_t restLen = lineLen - (ssize_t)(pline - line);
for (; i < restLen; i++ )
{
if ( pline[i] == ',' )
switch (pline[i])
{
funcargc++;
funcargname[funcargc].rm_so
= (regoff_t)(pline - line + i + 1);
}
if ( pline[i] == ')' )
{
funcargc++;
funcargname[funcargc].rm_so
= (regoff_t)(pline - line + i + 1);
case ',':
if (!innerParens)
{
funcargc++;
funcargname[funcargc].rm_so
= (regoff_t)(pline - line + i + 1);
}
break;
case '(':
++innerParens;
break;
case ')':
if (!innerParens)
{
funcargc++;
funcargname[funcargc].rm_so
= (regoff_t)(pline - line + i + 1);
goto endOfArgSearch;
}
else
--innerParens;
break;
}
}
endOfArgSearch:
if (i < restLen)
break;
char *lineExtension = NULL;
......@@ -426,6 +449,8 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint,
funcargname[i].rm_eo = nameMatch->rm_eo + argStart;
needsExtraWrapper
= needsExtraWrapper || funArgSym[argtype].needsExtraWrapper;
needsPrologue = needsPrologue
|| funArgSym[argtype].needsPrologue;
break;
}
if (argtype == NUM_KNOWN_ARG_TYPES)
......@@ -471,6 +496,17 @@ static void fortran_interface(char *fname, char *fnameinc, char *fnameint,
const char *delegateName;
char delegateNameBuf[MAX_FUNC_NAME_LEN + 7];
size_t delegateNameLen = funcnameLen;
/* emit prologue if needed */
if (needsPrologue)
{
if (funRet[functype].needsPrologue)
funRet[functype].prologue(fpint, (size_t)-1);
for (size_t i = 0; i < funcargc; i++ )
{
if (funArgSym[funcargtype[i]].needsPrologue)
funArgSym[funcargtype[i]].prologue(fpint, i);
}
}
/* emit wrapper for type conversions if needed */
if (needsExtraWrapper)
{
......@@ -1006,6 +1042,16 @@ static int cfXtIdxlistConvert(FILE *outfp, const char *argName,
return retval;
}
static int cfVoidFuncPrologue(FILE *outfp, size_t argNum)
{
int retval
= fprintf(outfp, "\n#undef ROUTINE_%zu\n#define ROUTINE_%zu %s\n", argNum,
argNum, "(void (*)(void))");
return retval;
}
/*
* Local Variables:
* c-file-style: "Java"
......
......@@ -143,7 +143,7 @@ int pioFileOpen(const char *filename, const char *mode)
/***************************************************************/
void backendInit ( void )
void backendInit(void (*postCommSetupActions)(void))
{
int IOMode = commInqIOMode ();
......@@ -160,16 +160,16 @@ void backendInit ( void )
commDefCommsIO ();
break;
case PIO_MPI:
initMPINONB ();
initMPINONB(postCommSetupActions);
break;
#ifndef _SX
case PIO_ASYNCH:
#endif
case PIO_WRITER:
pioSendInitialize();
pioSendInitialize(postCommSetupActions);
break;
case PIO_FPGUARD:
initPOSIXFPGUARDSENDRECV ();
initPOSIXFPGUARDSENDRECV(postCommSetupActions);
break;
}
}
......
......@@ -12,7 +12,7 @@
#include "cdi_int.h"
void backendCleanup ( void );
void backendInit ( void );
void backendInit(void (*postCommSetupActions)(void));
void backendFinalize ( void );
int pioFileOpen(const char *filename, const char *mode);
int pioFileClose ( int );
......
......@@ -65,7 +65,7 @@ void listSetForeach(listSet *q, elemOp func, void *data);
int fowMPINONB ( const char * );
int fcMPINONB ( int );
size_t fwMPINONB( int, int, const void *, size_t );
void initMPINONB ( void );
void initMPINONB(void (*postCommSetupActions)(void));
void finalizeMPINONB ( void );
......@@ -73,7 +73,7 @@ void finalizeMPINONB ( void );
int pioSendClose(int);
int pioSendOpen(const char *);
size_t pioSendWrite(int, int, const void *, size_t);
void pioSendInitialize(void);
void pioSendInitialize(void (*postCommSetupActions)(void));
void pioSendFinalize(void);
......@@ -87,7 +87,7 @@ void fpgPOSIXFPGUARDSENDRECV ( void );
int fowPOSIXFPGUARDSENDRECV ( const char * );
int fcPOSIXFPGUARDSENDRECV ( int );
size_t fwPOSIXFPGUARDSENDRECV ( int, int, const void *, size_t );
void initPOSIXFPGUARDSENDRECV ( void );
void initPOSIXFPGUARDSENDRECV(void (*postCommSetupActions)(void));
void finalizePOSIXFPGUARDSENDRECV ( void );
/* pio_posixnonb.c */
......
......@@ -672,6 +672,12 @@ void pioBufferFuncCall(struct winHeaderEntry header,
#endif
void
cdiPioNoPostCommSetup(void)
{
}
/*****************************************************************************/
/* pioInit definition must currently compile even in non-MPI configurations */
......@@ -698,6 +704,8 @@ void pioBufferFuncCall(struct winHeaderEntry header,
@param partInflate allow for array partitions on comute
PE that are at most sized \f$ partInflate * \lceil arraySize /
numComputePEs \rceil \f$
@param postSetupActions function which is called by all I/O servers
after communicator split
@return int indicating wether the calling PE is a calcutator (1) or not (0)
*/
......@@ -708,7 +716,8 @@ static int xtInitByCDI = 0;
MPI_Comm
pioInit(MPI_Comm commGlob, int nProcsIO, int IOMode,
int *pioNamespace, float partInflate)
int *pioNamespace, float partInflate,
void (*postCommSetupActions)(void))
{
#ifdef USE_MPI
int sizeGlob;
......@@ -754,7 +763,7 @@ pioInit(MPI_Comm commGlob, int nProcsIO, int IOMode,
namespaceSwitchSet(NSSWITCH_ABORT, NSSW_FUNC(cdiAbortC_MPI));
namespaceSwitchSet(NSSWITCH_FILE_OPEN, NSSW_FUNC(pioFileOpen));
namespaceSwitchSet(NSSWITCH_FILE_CLOSE, NSSW_FUNC(pioFileClose));
IOServer ();
IOServer(postCommSetupActions);
namespaceDelete(0);
commDestroy ();
xt_finalize();
......
......@@ -323,13 +323,14 @@ void finalizeMPINONB(void)
/***************************************************************/
void initMPINONB ( void )
void
initMPINONB(void (*postCommSetupActions)(void))
{
commDefCommColl ( 1 );
commSendNodeInfo ();
commRecvNodeMap ();
commDefCommsIO ();
postCommSetupActions();
bibAFiledataM = listSetNew( destroyAFiledataMPINONB, compareNamesMPINONB );
if ( bibAFiledataM == NULL )
......
......@@ -519,7 +519,8 @@ finalizePOSIXFPGUARDSENDRECV(void)
/***************************************************************/
void initPOSIXFPGUARDSENDRECV ( void )
void
initPOSIXFPGUARDSENDRECV(void (*postCommSetupActions)(void))
{
if ( commInqSizeNode () < 2 )
xabort ( "USAGE: # IO PROCESSES ON A PHYSICAL NODE >= 2" );
......@@ -529,6 +530,7 @@ void initPOSIXFPGUARDSENDRECV ( void )
commSendNodeInfo ();
commRecvNodeMap ();
commDefCommsIO ();
postCommSetupActions();
if (!isCollector)
fpgPOSIXFPGUARDSENDRECV ();
else
......
......@@ -320,7 +320,7 @@ pioSendFinalize(void)
}
void
pioSendInitialize(void)
pioSendInitialize(void (*postCommSetupActions)(void))
{
if (commInqSizeNode() < 2)
xabort ( "USAGE: # IO PROCESSES ON A PHYSICAL NODE >= 2" );
......@@ -331,6 +331,7 @@ pioSendInitialize(void)
commSendNodeInfo();
commRecvNodeMap();
commDefCommsIO();
postCommSetupActions();
if (!isCollector)
switch ( commInqIOMode ())
{
......
......@@ -1044,7 +1044,7 @@ cdiPioCdfDefTimestep(stream_t *streamptr, int tsID)
@return
*/
void IOServer ()
void IOServer(void (*postCommSetupActions)(void))
{
int source, tag, size, nProcsModel=commInqNProcsModel();
static int nfinished = 0;
......@@ -1054,7 +1054,7 @@ void IOServer ()
xdebug("%s", "START");
backendInit ();
backendInit(postCommSetupActions);
if ( commInqRankNode () == commInqSpecialRankNode ())
backendFinalize ();
commCalc = commInqCommCalc ();
......
......@@ -9,7 +9,7 @@
#include <mpi.h>
void IOServer ();
void IOServer(void (*postCommSetupActions)(void));
#endif
......
......@@ -211,7 +211,8 @@ int main (int argc, char *argv[])
#ifdef USE_MPI
int pioNamespace;
commModel = pioInit(commGlob, nProcsIO, IOMode, &pioNamespace, 1.0);
commModel = pioInit(commGlob, nProcsIO, IOMode, &pioNamespace, 1.0,
cdiPioNoPostCommSetup);
pioNamespaceSetActive(pioNamespace);
#else
commModel = -1;
......
Markdown is supported
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