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

Replace pack function pointer with another version

that allows for better type safety in argument passing.
parent 838342a6
......@@ -49,12 +49,17 @@ char *Grids[] = {
int gridCompareP ( void * gridptr1, void * gridptr2 );
void gridDestroyP ( void * gridptr );
void gridPrintP ( void * gridptr );
size_t gridGetSizeP ( void * gridptr );
void gridPackP ( void * gridptr, void * buff, void * sizebuff, \
void * position, void * comm );
#ifdef USE_MPI
int gridGetSizeP ( void * gridptr );
void gridPackP ( void * gridptr, void * buff, int size,
int *position, MPI_Comm comm );
#endif
resOps gridOps = { gridCompareP, gridDestroyP, gridPrintP, gridGetSizeP, \
gridPackP };
resOps gridOps = { gridCompareP, gridDestroyP, gridPrintP
#ifdef USE_MPI
, gridGetSizeP, gridPackP
#endif
};
static int GRID_Debug = 0; /* If set to 1, debugging */
......@@ -3668,27 +3673,24 @@ void gridGetIndexArray ( int ngrids, int * gridIndexArray )
reshGetIndiceArrayOfType ( ngrids, gridIndexArray, &gridOps );
}
size_t gridGetSizeP ( void * gridptr )
#ifdef USE_MPI
int gridGetSizeP ( void * gridptr )
{
xdebug ();
return ( 2 * sizeof (int ));
}
void gridPackP ( void * gridptr, void * buff, void * sizebuff, void * position,
void * comm )
void gridPackP ( void * gridptr, void * buff, int size, int * pos,
MPI_Comm comm )
{
grid_t * gridP = ( grid_t * ) gridptr;
char * buffP = ( char * ) buff;
int * sizeP = ( int * ) sizebuff;
int * posP = ( int * ) position;
#ifdef USE_MPI
MPI_Comm * commP = ( MPI_Comm * ) comm;
MPI_Pack ( &gridP->type, 1, MPI_INT, buffP, * sizeP, posP, * commP );
MPI_Pack ( &gridP->size, 1, MPI_INT, buffP, * sizeP, posP, * commP );
#endif
MPI_Pack ( &gridP->type, 1, MPI_INT, buff, size, pos, comm );
MPI_Pack ( &gridP->size, 1, MPI_INT, buff, size, pos, comm );
return;
}
#endif
......@@ -31,11 +31,17 @@ institute_t;
static int instituteCompareP ( void * instituteptr1, void * instituteptr2 );
static void instituteDestroyP ( void * instituteptr );
static void institutePrintP ( void * instituteptr );
static size_t instituteGetSizeP ( void * instituteptr );
static void institutePackP ( void * instituteptr, void * position, void * buff );
#ifdef USE_MPI
static int instituteGetSizeP ( void * instituteptr );
static void institutePackP ( void * instituteptr, void *buf, int size,
int *position, MPI_Comm comm );
#endif
resOps instituteOps = { instituteCompareP, instituteDestroyP, institutePrintP, \
instituteGetSizeP, institutePackP };
resOps instituteOps = { instituteCompareP, instituteDestroyP, institutePrintP
#ifdef USE_MPI
,instituteGetSizeP, institutePackP
#endif
};
static
......@@ -318,18 +324,20 @@ void institutePrintP ( void * instituteptr )
}
static
size_t instituteGetSizeP ( void * instituteptr )
#ifdef USE_MPI
static
int instituteGetSizeP ( void * instituteptr )
{
xdebug ();
return 0;
}
static
void institutePackP ( void * instituteptr, void * position, void * buff )
static
void institutePackP ( void * instituteptr, void * buff, int size,
int *position, MPI_Comm comm )
{
xdebug ();
return;
}
#endif
......@@ -19,8 +19,8 @@ int COSMO = UNDEFID;
typedef struct
{
int self;
int used;
int instID;
int used;
int instID;
int modelgribID;
char *name;
}
......@@ -35,11 +35,17 @@ static void modelInit(void);
static int modelCompareP ( void * modelptr1, void * modelptr2 );
static void modelDestroyP ( void * modelptr );
static void modelPrintP ( void * modelptr );
static size_t modelGetSizeP ( void * modelptr );
static void modelPackP ( void * modelptr, void * position, void * buff );
#ifdef USE_MPI
static int modelGetSizeP ( void * modelptr );
static void modelPackP ( void * modelptr, void * buff, int size,
int *position, MPI_Comm comm);
#endif
resOps modelOps = { modelCompareP, modelDestroyP, modelPrintP, modelGetSizeP, \
modelPackP };
resOps modelOps = { modelCompareP, modelDestroyP, modelPrintP
#ifdef USE_MPI
, modelGetSizeP, modelPackP
#endif
};
static
void modelDefaultValue ( model_t *modelptr )
......@@ -141,30 +147,30 @@ int modelInq(int instID, int modelgribID, char *name)
modelptr = ( model_t * ) reshGetVal ( modelID, &modelOps );
if ( modelptr->used )
{
if ( name )
{
found = 1;
if ( instID != -1 && modelptr->instID != instID ) found = 0;
if ( modelgribID != 0 && modelptr->modelgribID != modelgribID ) found = 0;
if ( found )
{
if ( modelptr->name )
{
len = strlen(modelptr->name);
if ( memcmp(modelptr->name, name, len) == 0 ) break;
len = strlen(name);
if ( memcmp(modelptr->name, name, len) == 0 ) break;
}
}
}
else
{
if ( modelptr->instID == instID &&
modelptr->modelgribID == modelgribID ) break;
}
}
{
if ( name )
{
found = 1;
if ( instID != -1 && modelptr->instID != instID ) found = 0;
if ( modelgribID != 0 && modelptr->modelgribID != modelgribID ) found = 0;
if ( found )
{
if ( modelptr->name )
{
len = strlen(modelptr->name);
if ( memcmp(modelptr->name, name, len) == 0 ) break;
len = strlen(name);
if ( memcmp(modelptr->name, name, len) == 0 ) break;
}
}
}
else
{
if ( modelptr->instID == instID &&
modelptr->modelgribID == modelgribID ) break;
}
}
}
if ( modelID == modelCount ) modelID = UNDEFID;
......@@ -180,11 +186,11 @@ int modelDef(int instID, int modelgribID, const char *name)
model_t *modelptr;
modelInit ();
modelptr = modelNewEntry();
modelptr->instID = instID;
modelptr->modelgribID = modelgribID;
modelptr->modelgribID = modelgribID;
if ( name ) modelptr->name = strdupx(name);
return modelptr->self;
......@@ -198,7 +204,7 @@ int modelInqInstitut(int modelID)
modelInit ();
modelptr = ( model_t * ) reshGetVal ( modelID, &modelOps );
return modelptr ? modelptr->instID : UNDEFID;
}
......@@ -221,7 +227,7 @@ char *modelInqNamePtr(int modelID)
modelInit ();
modelptr = ( model_t * ) reshGetVal ( modelID, &modelOps );
modelptr = ( model_t * ) reshGetVal ( modelID, &modelOps );
return modelptr ? modelptr->name : NULL;
}
......@@ -247,7 +253,7 @@ void modelPrintP ( void * modelptr )
fprintf ( fp, "#\n");
fprintf ( fp, "# modelID %d\n", mp->self);
fprintf ( fp, "#\n");
fprintf ( fp, "#\n");
fprintf ( fp, "self = %d\n", mp->self );
fprintf ( fp, "used = %d\n", mp->used );
fprintf ( fp, "instID = %d\n", mp->instID );
......@@ -256,17 +262,21 @@ void modelPrintP ( void * modelptr )
}
static
size_t modelGetSizeP ( void * modelptr )
#ifdef USE_MPI
static
int modelGetSizeP ( void * modelptr )
{
xdebug ();
return 0;
return 0;
}
static
void modelPackP ( void * modelptr, void * position, void * buff )
static
void modelPackP ( void * modelptr, void * buff, int size,
int *position, MPI_Comm comm )
{
xdebug ();
return;
}
#endif
......@@ -333,6 +333,7 @@ int reshCountType ( resOps * ops )
/**************************************************************/
#ifdef USE_MPI
static
size_t getPackBufferSize ()
{
......@@ -371,7 +372,6 @@ void reshPackBufferDestroy ( char ** buffer )
/**************************************************************/
#ifdef USE_MPI
void reshPackBufferCreate ( char ** buffer, size_t * size, MPI_Comm comm )
{
int i, nsp, position = 0;
......@@ -392,28 +392,28 @@ void reshPackBufferCreate ( char ** buffer, size_t * size, MPI_Comm comm )
for ( i = 0; i < arraySizeAllocated[nsp]; i++ )
if ( arrayResources[nsp][i].ptr )
if ( ! arrayResources[nsp][i].sent )
{
curr = arrayResources[nsp] + i;
assert ( curr->ops );
if ( curr->ops != &gridOps )
continue;
MPI_Pack ( &type, 1, MPI_INT, * buffer, * size, &position, comm );
curr->ops->valPack (( void * ) curr->ptr,
( void * ) * buffer ,
( void * ) size,
( void * ) &position,
( void * ) comm );
MPI_Pack ( &sep, 1, MPI_INT, * buffer, * size, &position, comm );
xdebug ( "#### packed one resource with type and separator" );
curr->sent = 1;
}
{
curr = arrayResources[nsp] + i;
assert ( curr->ops );
if ( curr->ops != &gridOps )
continue;
MPI_Pack ( &type, 1, MPI_INT, * buffer, * size, &position, comm );
curr->ops->valPack ( curr->ptr,
* buffer ,
* size,
&position,
comm );
MPI_Pack ( &sep, 1, MPI_INT, * buffer, * size, &position, comm );
xdebug ( "#### packed one resource with type and separator" );
curr->sent = 1;
}
ARRAY_UNLOCK();
MPI_Pack ( &end, 1, MPI_INT, * buffer, * size, &position, comm );
......
......@@ -26,18 +26,23 @@ typedef int cdiResH;
typedef int ( * valCompareFunc )( void *, void * );
typedef void ( * valDestroyFunc )( void * );
typedef void ( * valPrintFunc )( void * );
typedef size_t ( * valGetSizeFunc )( void * );
typedef void ( * valPackFunc )( void *, void *, void *, void *, void * );
#ifdef USE_MPI
typedef int ( * valGetSizeFunc )( void * );
typedef void ( * valPackFunc )( void *, void *buf, int size, int *pos,
MPI_Comm comm );
#endif
typedef struct {
valCompareFunc valCompare;
valDestroyFunc valDestroy;
valPrintFunc valPrint;
#ifdef USE_MPI
valGetSizeFunc valGetSize;
valPackFunc valPack;
}resOps;
#endif
}resOps;
int reshPut ( void *, resOps * );
void reshRemove ( cdiResH, resOps * );
......
......@@ -68,11 +68,18 @@ static int cdiHaveMissval = 0;
static int streamCompareP ( void * streamptr1, void * streamptr2 );
static void streamDestroyP ( void * streamptr );
static void streamPrintP ( void * streamptr );
static size_t streamGetSizeP ( void * streamptr );
static void streamPackP ( void * streamptr, void * position, void * buff );
#ifdef USE_MPI
static int streamGetSizeP ( void * streamptr );
static void streamPackP ( void * streamptr, void * buff, int size,
int * position, MPI_Comm comm );
#endif
resOps streamOps = { streamCompareP, streamDestroyP, streamPrintP, streamGetSizeP, \
streamPackP };
resOps streamOps = { streamCompareP, streamDestroyP, streamPrintP,
#ifdef USE_MPI
streamGetSizeP,
streamPackP
#endif
};
long cdiGetenvInt(char *envName)
{
......@@ -564,17 +571,21 @@ void streamPrintP ( void * streamptr )
}
static
size_t streamGetSizeP ( void * streamptr )
#ifdef USE_MPI
static
int streamGetSizeP ( void * streamptr )
{
xdebug ();
return 0;
}
static
void streamPackP ( void * streamptr, void * position, void * buff )
static
void streamPackP ( void * streamptr, void * buff, int size, int * position,
MPI_Comm comm)
{
xdebug ();
return;
}
#endif
......@@ -37,10 +37,17 @@ char *Timeunits[] = {
static int taxisCompareP ( void * taxisptr1, void * taxisptr2 );
static void taxisDestroyP ( void * taxisptr );
static void taxisPrintP ( void * taxisptr );
static size_t taxisGetSizeP ( void * taxisptr );
static void taxisPackP ( void * taxisptr, void * position, void * buff );
#ifdef USE_MPI
static int taxisGetSizeP ( void * taxisptr );
static void taxisPackP ( void * taxisptr, void *buf, int size,
int *position, MPI_Comm comm );
#endif
resOps taxisOps = { taxisCompareP, taxisDestroyP, taxisPrintP, taxisGetSizeP, taxisPackP };
resOps taxisOps = { taxisCompareP, taxisDestroyP, taxisPrintP
#ifdef USE_MPI
, taxisGetSizeP, taxisPackP
#endif
};
static int TAXIS_Debug = 0; /* If set to 1, debugging */
......@@ -59,6 +66,7 @@ char *tunitNamePtr(int unitID)
return (name);
}
#if 0
static
void taxis_defaults(void)
{
......@@ -87,7 +95,7 @@ void taxis_defaults(void)
Warning("Unsupported TIMEUNIT %s!", timeunit);
}
}
#endif
static
void taxisDefaultValue ( taxis_t *taxisptr )
......@@ -138,7 +146,7 @@ void taxisInit (void)
if ( env ) TAXIS_Debug = atoi(env);
}
#if 0
static
void taxis_copy(taxis_t *taxisptr2, taxis_t *taxisptr1)
{
......@@ -148,6 +156,7 @@ void taxis_copy(taxis_t *taxisptr2, taxis_t *taxisptr1)
memcpy(taxisptr2, taxisptr1, sizeof(taxis_t));
taxisptr2->self = taxisID2;
}
#endif
static
void taxis_check_ptr(const char *caller, taxis_t *taxisptr)
......@@ -1261,8 +1270,9 @@ int taxisCompareP ( void * taxisptr1, void * taxisptr2 )
}
#ifdef USE_MPI
static
size_t taxisGetSizeP ( void * taxisptr )
int taxisGetSizeP ( void * taxisptr )
{
xdebug ();
return 0;
......@@ -1270,8 +1280,10 @@ size_t taxisGetSizeP ( void * taxisptr )
static
void taxisPackP ( void * taxisptr, void * position, void * buff )
void taxisPackP ( void * taxisptr, void * buff, int size, int *position,
MPI_Comm comm)
{
xdebug ();
return;
}
#endif
......@@ -47,16 +47,20 @@ vlist_compare(vlist_t *a, vlist_t *b)
static void
vlistPrintKernel(vlist_t *vlistptr);
static size_t vlistGetSizeP ( void * vlistptr );
static void vlistPackP ( void * vlistptr, void * position, void * buff );
#ifdef USE_MPI
static int vlistGetSizeP ( void * vlistptr );
static void vlistPackP ( void * vlistptr, void * buff, int size,
int *position, MPI_Comm comm );
#endif
resOps vlist_ops = {
(valCompareFunc)vlist_compare,
free,
(valPrintFunc)vlistPrintKernel,
vlistGetSizeP,
(valPrintFunc)vlistPrintKernel
#ifdef USE_MPI
, vlistGetSizeP,
vlistPackP
#endif
};
......@@ -1495,19 +1499,22 @@ int vlistHasTime(int vlistID)
}
#ifdef USE_MPI
static
size_t vlistGetSizeP ( void * vlistptr )
static
int vlistGetSizeP ( void * vlistptr )
{
xdebug ();
return 0;
}
static
void vlistPackP ( void * vlistptr, void * position, void * buff )
static
void vlistPackP ( void * vlistptr, void * buff, int size, int *position,
MPI_Comm comm )
{
xdebug ();
}
#endif
......@@ -64,16 +64,23 @@ static int CDI_MaxZaxistype = sizeof(ZaxistypeEntry) / sizeof(ZaxistypeEntry[0])
static int zaxisCompareP ( void * zaxisptr1, void * zaxisptr2 );
static void zaxisDestroyP ( void * zaxisptr );
static void zaxisPrintP ( void * zaxisptr );
static size_t zaxisGetSizeP ( void * zaxisptr );
static void zaxisPackP ( void * zaxisptr, void * position, void * buff );
#ifdef USE_MPI
static int zaxisGetSizeP ( void * zaxisptr );
static void zaxisPackP ( void * zaxisptr, void * buffer, int size,
int *pos, MPI_Comm comm);
#endif
resOps zaxisOps = { zaxisCompareP, zaxisDestroyP, zaxisPrintP, zaxisGetSizeP, zaxisPackP };
resOps zaxisOps = { zaxisCompareP, zaxisDestroyP, zaxisPrintP
#ifdef USE_MPI
, zaxisGetSizeP, zaxisPackP
#endif
};
static int ZAXIS_Debug = 0; /* If set to 1, debugging */
static
void zaxisDefaultValue ( zaxis_t *zaxisptr )
void zaxisDefaultValue ( zaxis_t *zaxisptr )
{
zaxisptr->self = CDI_UNDEFID;
zaxisptr->name[0] = 0;
......@@ -1189,21 +1196,24 @@ int zaxisCompareP ( void * zaxisptr1, void * zaxisptr2 )
}
static
size_t zaxisGetSizeP ( void * zaxisptr )
#ifdef USE_MPI
static
int zaxisGetSizeP ( void * zaxisptr )
{
xdebug ();
return 0;
}
static
void zaxisPackP ( void * zaxisptr, void * position, void * buff )
static
void zaxisPackP ( void * zaxisptr, void *buffer, int size,
int *pos, MPI_Comm comm)
{
xdebug ();
return;
}
#endif
void zaxisGetIndexArray ( int nzaxis, int * zaxisIndexArray )
{
......
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