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

Change return type of resource counts to unsigned.

* Also rename some functions to include cdi prefix.
parent cee15588
......@@ -389,12 +389,6 @@ const char *strfiletype(int filetype)
}
int streamSize(void)
{
return reshCountType ( &streamOps );
}
void cdiDefGlobal(const char *string, int val)
{
if ( strcmp(string, "REGULARGRID") == 0 ) cdiDataUnreduced = val;
......
......@@ -318,8 +318,7 @@ int cdiInqAccesstype(int streamID);
int getByteswap(int byteorder);
int streamSize ();
void streamGetIndexList ( int, int * );
void cdiStreamGetIndexList(unsigned numIDs, int IDs[numIDs]);
void cdiInitialize(void);
......
......@@ -201,9 +201,9 @@ void grid_copy(grid_t *gridptr2, grid_t *gridptr1)
gridptr2->self = gridID2;
}
int gridSize(void)
unsigned cdiGridCount(void)
{
return reshCountType ( &gridOps );
return reshCountType(&gridOps);
}
// used also in CDO
......@@ -3860,9 +3860,9 @@ void gridInqUUID(int gridID, unsigned char uuid[CDI_UUID_SIZE])
}
void gridGetIndexList ( int ngrids, int * gridIndexList )
void cdiGridGetIndexList(unsigned ngrids, int * gridIndexList)
{
reshGetResHListOfType ( ngrids, gridIndexList, &gridOps );
reshGetResHListOfType(ngrids, gridIndexList, &gridOps);
}
......
......@@ -76,7 +76,7 @@ grid_t;
void grid_init(grid_t *gridptr);
void grid_free(grid_t *gridptr);
int gridSize(void);
unsigned cdiGridCount(void);
const double *gridInqXvalsPtr(int gridID);
const double *gridInqYvalsPtr(int gridID);
......@@ -88,7 +88,7 @@ const double *gridInqAreaPtr(int gridID);
int gridCompare(int gridID, const grid_t *grid);
int gridGenerate(const grid_t *grid);
void gridGetIndexList( int, int * );
void cdiGridGetIndexList(unsigned, int * );
void
gridUnpack(char * unpackBuffer, int unpackBufferSize,
......
......@@ -88,12 +88,6 @@ void instituteDefaultEntries ( void )
}
int instituteCount ( void )
{
return reshCountType ( &instituteOps );
}
static int
instituteCompareKernel(institute_t * ip1, institute_t * ip2)
{
......
......@@ -132,11 +132,6 @@ void modelInit(void)
if ( env ) MODEL_Debug = atoi(env);
}
int modelSize ( void )
{
return reshCountType ( &modelOps );
}
struct modelLoc
{
char *name;
......
......@@ -155,7 +155,7 @@ in order of vSizes
static void
varMapGen(int *vSizes, int *sSizes, int *varMapping,
int nStreams, int *nodeSizes, int nNodes)
unsigned nStreams, int *nodeSizes, int nNodes)
{
int weightsStreams[nStreams];
......@@ -170,9 +170,9 @@ varMapGen(int *vSizes, int *sSizes, int *varMapping,
int buckets[nProcsColl];
for ( i = 0; i < nStreams; i++ )
for (unsigned i = 0; i < nStreams; i++ )
{
nVars += * ( sSizes + i );
nVars += sSizes[i];
weightsStreams[i] = 0;
for ( j = 0; j < * ( sSizes + i ); j++ )
weightsStreams[i] += * ( vSizes + offset++ );
......@@ -185,13 +185,13 @@ varMapGen(int *vSizes, int *sSizes, int *varMapping,
for ( j = 0; j < nNodes; j++ )
w[j] = ( double ) * ( nodeSizes + j ) / ( double ) nPEs;
mapProblems ( weightsStreams, streamMapping, nStreams, nNodes, w );
mapProblems(weightsStreams, streamMapping, (int)nStreams, nNodes, w);
free ( w );
for ( i = 0; i < nNodes; i++ )
{
nVarsNode = 0;
for ( j = 0; j < nStreams; j++ )
for (unsigned j = 0; j < nStreams; j++)
if ( * ( streamMapping + j ) == i )
nVarsNode += * ( sSizes + j );
......@@ -201,12 +201,12 @@ varMapGen(int *vSizes, int *sSizes, int *varMapping,
offset = 0;
offsetN = 0;
for ( j = 0; j < nStreams; j++ )
if ( * ( streamMapping + j ) == i )
for (unsigned j = 0; j < nStreams; j++ )
if (streamMapping[j] == i)
for ( k = 0; k < * ( sSizes + j ); k ++ )
* ( weightsVarsNode + offsetN++ ) = * ( vSizes + offset++ );
weightsVarsNode[offsetN++] = vSizes[offset++];
else
offset += * ( sSizes + j );
offset += sSizes[j];
for ( j = 0; j < * ( nodeSizes + i ); j ++ )
w[j] = 1.0 / ( double ) * ( nodeSizes + i );
......@@ -217,7 +217,7 @@ varMapGen(int *vSizes, int *sSizes, int *varMapping,
offset = 0;
offsetN = 0;
for ( j = 0; j < nStreams; j++ )
for (unsigned j = 0; j < nStreams; j++)
if ( * ( streamMapping + j ) == i )
for ( k = 0; k < * ( sSizes + j ); k ++ )
* ( varMapping + offset ++ ) =
......@@ -249,28 +249,28 @@ varMapGen(int *vSizes, int *sSizes, int *varMapping,
static void
varsMapNDeco(int nNodes, int *nodeSizes)
{
int nStreams, nVars, * resHs, * streamSizes, * varSizes, * varMapping,
int nVars, * resHs, * streamSizes, * varSizes, * varMapping,
* collectsData;
int k = 0;
int nProcsColl = commInqNProcsColl ();
xdebug ( "START, nProcsColl=%d", nProcsColl );
nStreams = streamSize ();
unsigned nStreams = reshCountType(&streamOps);
resHs = xmalloc((size_t)nStreams * sizeof (resHs[0]));
streamSizes = xmalloc((size_t)nStreams * sizeof (streamSizes[0]));
resHs = xmalloc(nStreams * sizeof (resHs[0]));
streamSizes = xmalloc(nStreams * sizeof (streamSizes[0]));
collectsData = xmalloc((size_t)nProcsColl * sizeof (collectsData[0]));
streamGetIndexList ( nStreams, resHs );
cdiStreamGetIndexList(nStreams, resHs);
for (int i = 0; i < nStreams; i++ )
streamSizes[i] = streamInqNvars ( * ( resHs + i ));
for (unsigned i = 0; i < nStreams; i++ )
streamSizes[i] = streamInqNvars(resHs[i]);
nVars = sum_int((size_t)nStreams, streamSizes);
varSizes = xcalloc((size_t)nVars, sizeof (varSizes[0]));
varMapping = xmalloc((size_t)nVars * sizeof (varMapping[0]));
for (int i = 0; i < nStreams; i++ )
for (unsigned i = 0; i < nStreams; i++ )
{
int vlistID = streamInqVlist(resHs[i]);
for (int j = 0; j < streamSizes[i]; j++ )
......@@ -283,7 +283,7 @@ varsMapNDeco(int nNodes, int *nodeSizes)
nStreams, nodeSizes, nNodes );
k = 0;
for (int i = 0; i < nStreams; i++ )
for (unsigned i = 0; i < nStreams; i++ )
for (int j = 0; j < * ( streamSizes + i ); j++ )
{
vlistDefVarIOrank ( streamInqVlist ( * ( resHs + i )), j,
......@@ -343,7 +343,7 @@ struct collDesc
static void
modelWinDefBufferSizes(void)
{
int collID, nstreams, * streamIndexList, streamNo, nvars, varID;
int collID, * streamIndexList, nvars, varID;
size_t sumWinBufferSize = 0;
int nProcsColl = commInqNProcsColl ();
int rankGlob = commInqRankGlob ();
......@@ -353,11 +353,11 @@ modelWinDefBufferSizes(void)
xdebug("%s", "START");
xassert(txWin != NULL);
nstreams = reshCountType ( &streamOps );
unsigned nstreams = reshCountType ( &streamOps );
streamIndexList = xmalloc((size_t)nstreams * sizeof (streamIndexList[0]));
collIndex = xcalloc((size_t)nProcsColl, sizeof (collIndex[0]));
reshGetResHListOfType ( nstreams, streamIndexList, &streamOps );
for ( streamNo = 0; streamNo < nstreams; streamNo++ )
for (unsigned streamNo = 0; streamNo < nstreams; streamNo++ )
{
// memory required for data
int streamID = streamIndexList[streamNo];
......
......@@ -76,7 +76,7 @@ void serverWinCleanup ()
static size_t
collDefBufferSizes()
{
int nstreams, * streamIndexList, streamNo, vlistID, nvars, varID, iorank;
int *streamIndexList, vlistID, nvars, varID, iorank;
int modelID;
size_t sumGetBufferSizes = 0;
int rankGlob = commInqRankGlob ();
......@@ -85,10 +85,10 @@ collDefBufferSizes()
xassert(rxWin != NULL);
nstreams = reshCountType ( &streamOps );
unsigned nstreams = reshCountType ( &streamOps );
streamIndexList = xmalloc((size_t)nstreams * sizeof (streamIndexList[0]));
reshGetResHListOfType ( nstreams, streamIndexList, &streamOps );
for ( streamNo = 0; streamNo < nstreams; streamNo++ )
for (unsigned streamNo = 0; streamNo < nstreams; streamNo++)
{
// space required for data
vlistID = streamInqVlist ( streamIndexList[streamNo] );
......@@ -575,18 +575,18 @@ buildStreamMap(struct winHeaderEntry *winDict)
/* join with list of streams written to in total */
{
int *streamIDs, *streamIsWritten;
int numTotalStreamIDs = streamSize();
streamIDs = (int*) xmalloc(2 * sizeof (streamIDs[0]) * (size_t)numTotalStreamIDs);
streamGetIndexList(numTotalStreamIDs, streamIDs);
unsigned numTotalStreamIDs = reshCountType(&streamOps);
streamIDs = xmalloc(2 * sizeof (streamIDs[0]) * (size_t)numTotalStreamIDs);
cdiStreamGetIndexList(numTotalStreamIDs, streamIDs);
streamIsWritten = streamIDs + numTotalStreamIDs;
for (int i = 0; i < numTotalStreamIDs; ++i)
for (unsigned i = 0; i < numTotalStreamIDs; ++i)
streamIsWritten[i] = streamIsInList(streamMap, numStreamIDs,
streamIDs[i]);
/* Find what streams are written to at all on any process */
xmpi(MPI_Allreduce(MPI_IN_PLACE, streamIsWritten, numTotalStreamIDs,
xmpi(MPI_Allreduce(MPI_IN_PLACE, streamIsWritten, (int)numTotalStreamIDs,
MPI_INT, MPI_BOR, commInqCommColl()));
/* append streams written to on other tasks to mapping */
for (int i = 0; i < numTotalStreamIDs; ++i)
for (unsigned i = 0; i < numTotalStreamIDs; ++i)
if (streamIsWritten[i] && !streamIsInList(streamMap, numStreamIDs,
streamIDs[i]))
numStreamIDs = inventorizeStream(streamMap, numStreamIDs,
......@@ -1096,13 +1096,13 @@ void cdiPioServer(void (*postCommSetupActions)(void))
if ( nfinished == nProcsModel )
{
{
int nStreams = streamSize ();
unsigned nStreams = reshCountType(&streamOps);
if ( nStreams > 0 )
{
int * resHs = xmalloc((size_t)nStreams * sizeof (resHs[0]));
streamGetIndexList ( nStreams, resHs );
for (int streamNo = 0; streamNo < nStreams; ++streamNo)
int *resHs = xmalloc(nStreams * sizeof (resHs[0]));
cdiStreamGetIndexList(nStreams, resHs);
for (unsigned streamNo = 0; streamNo < nStreams; ++streamNo)
streamClose(resHs[streamNo]);
free(resHs);
}
......
......@@ -431,19 +431,17 @@ void *reshGetValue(const char * caller, const char* expressionString, cdiResH re
/**************************************************************/
void reshGetResHListOfType ( int c, int * resHs, const resOps * ops )
void reshGetResHListOfType(unsigned numIDs, int resHs[numIDs], const resOps *ops)
{
int i, j = 0, nsp;
xassert ( resHs && ops );
LIST_INIT(1);
LIST_LOCK();
nsp = namespaceGetActive ();
for ( i = 0; i < resHList[nsp].size && j < c; i++ )
int nsp = namespaceGetActive();
unsigned j = 0;
for (int i = 0; i < resHList[nsp].size && j < numIDs; i++ )
if ((resHList[nsp].resources[i].status & RESH_IN_USE_BIT)
&& resHList[nsp].resources[i].res.v.ops == ops)
resHs[j++] = namespaceIdxEncode2(nsp, i);
......@@ -500,20 +498,21 @@ cdiResHFilterApply(const resOps *p,
/**************************************************************/
int reshCountType ( const resOps * ops )
unsigned reshCountType(const resOps *ops)
{
int i, nsp, countType = 0;
unsigned countType = 0;
xassert ( ops );
xassert(ops);
LIST_INIT(1);
LIST_LOCK();
nsp = namespaceGetActive ();
int nsp = namespaceGetActive ();
listElem_t *r = resHList[nsp].resources;
for ( i = 0; i < resHList[nsp].size; i++ )
size_t len = (size_t)resHList[nsp].size;
for (size_t i = 0; i < len; i++ )
countType += ((r[i].status & RESH_IN_USE_BIT) && r[i].res.v.ops == ops);
LIST_UNLOCK();
......
......@@ -57,13 +57,13 @@ void reshRemove ( cdiResH, const resOps * );
/*> doesn't check resource type */
void reshDestroy(cdiResH);
int reshCountType ( const resOps * );
unsigned reshCountType(const resOps *resTypeOps);
void * reshGetValue(const char* caller, const char* expressionString, cdiResH id, const resOps* ops);
#define reshGetVal(resH, ops) reshGetValue(__func__, #resH, resH, ops)
void reshGetResHListOfType ( int, int *, const resOps * );
void reshGetResHListOfType(unsigned numIDs, int IDs[numIDs], const resOps *ops);
enum cdiApplyRet {
CDI_APPLY_ERROR = -1,
......
......@@ -2174,9 +2174,9 @@ void cdiStreamSetupVlist(stream_t *streamptr, int vlistID, int vlistIDorig)
}
void streamGetIndexList ( int nstreams, int * streamIndexList )
void cdiStreamGetIndexList(unsigned numIDs, int IDs[numIDs])
{
reshGetResHListOfType ( nstreams, streamIndexList, &streamOps );
reshGetResHListOfType(numIDs, IDs, &streamOps);
}
int streamInqNvars ( int streamID )
......@@ -2279,7 +2279,6 @@ void streamPrintP ( void * streamptr, FILE * fp )
fprintf ( fp, "vlistIDorig = %d\n", sp->vlistIDorig );
}
enum {
streamNint = 11,
};
......
......@@ -750,19 +750,17 @@ int varDefGrid(int vlistID, const grid_t *grid, int mode)
*/
int gridglobdefined = FALSE;
int griddefined;
int ngrids;
int gridID = CDI_UNDEFID;
int index;
vlist_t *vlistptr;
int * gridIndexList, i;
int * gridIndexList;
vlistptr = vlist_to_pointer(vlistID);
griddefined = FALSE;
ngrids = vlistptr->ngrids;
unsigned ngrids = (unsigned)vlistptr->ngrids;
if ( mode == 0 )
for ( index = 0; index < ngrids; index++ )
for (unsigned index = 0; index < ngrids; index++ )
{
gridID = vlistptr->gridIDs[index];
if ( gridID == UNDEFID )
......@@ -777,12 +775,12 @@ int varDefGrid(int vlistID, const grid_t *grid, int mode)
if ( ! griddefined )
{
ngrids = gridSize();
ngrids = cdiGridCount();
if ( ngrids > 0 )
{
gridIndexList = (int*)xmalloc((size_t)ngrids * sizeof(int));
gridGetIndexList ( ngrids, gridIndexList );
for ( i = 0; i < ngrids; i++ )
cdiGridGetIndexList ( ngrids, gridIndexList );
for (unsigned i = 0; i < ngrids; i++ )
{
gridID = gridIndexList[i];
if ( gridCompare(gridID, grid) == 0 )
......@@ -791,12 +789,12 @@ int varDefGrid(int vlistID, const grid_t *grid, int mode)
break;
}
}
if ( gridIndexList ) free ( gridIndexList );
free(gridIndexList);
}
ngrids = vlistptr->ngrids;
ngrids = (unsigned)vlistptr->ngrids;
if ( mode == 1 )
for ( index = 0; index < ngrids; index++ )
for (unsigned index = 0; index < ngrids; index++ )
if ( vlistptr->gridIDs[index] == gridID )
{
gridglobdefined = FALSE;
......@@ -807,7 +805,7 @@ int varDefGrid(int vlistID, const grid_t *grid, int mode)
if ( ! griddefined )
{
if ( ! gridglobdefined ) gridID = gridGenerate(grid);
ngrids = vlistptr->ngrids;
ngrids = (unsigned)vlistptr->ngrids;
vlistptr->gridIDs[ngrids] = gridID;
vlistptr->ngrids++;
}
......@@ -871,17 +869,15 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbo
mode: 0 search in vlist and zaxis table
1 search in zaxis table
*/
int zaxisdefined;
int zaxisdefined = 0;
int nzaxis;
int zaxisID = UNDEFID;
int index;
int zaxisglobdefined = 0;
vlist_t *vlistptr;
int i;
vlistptr = vlist_to_pointer(vlistID);
zaxisdefined = 0;
nzaxis = vlistptr->nzaxis;
if ( mode == 0 )
......@@ -898,13 +894,14 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbo
if ( ! zaxisdefined )
{
nzaxis = zaxisSize();
reshLock();
unsigned nzaxis = cdiZaxisCount();
if ( nzaxis > 0 )
{
int *zaxisIndexList;
zaxisIndexList = (int *)xmalloc((size_t)nzaxis * sizeof (int));
zaxisGetIndexList(nzaxis, zaxisIndexList);
for ( i = 0; i < nzaxis; i++ )
cdiZaxisGetIndexList ( nzaxis, zaxisIndexList );
for (unsigned i = 0; i < nzaxis; i++ )
{
zaxisID = zaxisIndexList[i];
if ( zaxisCompare(zaxisID, zaxistype, nlevels, lbounds, levels, longname, units, ltype1) == 0 )
......@@ -913,12 +910,13 @@ int varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbo
break;
}
}
if ( zaxisIndexList ) free ( zaxisIndexList );
free(zaxisIndexList);
}
reshUnlock();
nzaxis = vlistptr->nzaxis;
nzaxis = (unsigned)vlistptr->nzaxis;
if ( mode == 1 )
for ( index = 0; index < nzaxis; index++ )
for (unsigned index = 0; index < nzaxis; index++ )
if ( vlistptr->zaxisIDs[index] == zaxisID )
{
zaxisglobdefined = FALSE;
......
......@@ -23,8 +23,6 @@ int cdiNAdditionalGRIBKeys = 0;
char* cdiAdditionalGRIBKeys[MAX_OPT_GRIB_ENTRIES];
#endif
extern void zaxisGetIndexList ( int, int * );
static int VLIST_Debug = 0;
static void vlist_initialize(void);
......@@ -445,13 +443,13 @@ int vlist_generate_zaxis(int vlistID, int zaxistype, int nlevels, const double *
if ( ! zaxisdefined )
{
nzaxis = zaxisSize();
unsigned nzaxis = cdiZaxisCount();
if ( nzaxis > 0 )
{
int *zaxisIndexList = (int *)xmalloc((size_t)nzaxis * sizeof (int));
reshLock();
zaxisGetIndexList ( nzaxis, zaxisIndexList );
for ( int index = 0; index < nzaxis; ++index )
cdiZaxisGetIndexList(nzaxis, zaxisIndexList);
for (unsigned index = 0; index < nzaxis; ++index)
{
zaxisID = zaxisIndexList[index];
if ( zaxisCompare(zaxisID, zaxistype, nlevels, has_bounds, levels, NULL, NULL, 0) == 0 )
......
......@@ -172,9 +172,9 @@ void zaxis_copy(zaxis_t *zaxisptr2, zaxis_t *zaxisptr1)
zaxisptr2->self = zaxisID2;
}
int zaxisSize(void)
unsigned cdiZaxisCount(void)
{
return reshCountType ( &zaxisOps );
return reshCountType(&zaxisOps);
}
static int
......@@ -1636,9 +1636,9 @@ zaxisPack(void * voidP, void * packBuffer, int packBufferSize,
}
void zaxisGetIndexList ( int nzaxis, int * zaxisResHs )
void cdiZaxisGetIndexList(unsigned nzaxis, int zaxisResHs[nzaxis])
{
reshGetResHListOfType ( nzaxis, zaxisResHs, &zaxisOps );
reshGetResHListOfType(nzaxis, zaxisResHs, &zaxisOps);
}
#undef ZAXIS_STR_SERIALIZE
......
#ifndef _ZAXIS_H
#define _ZAXIS_H
int zaxisSize(void);
unsigned cdiZaxisCount(void);
void cdiZaxisGetIndexList(unsigned numIDs, int IDs[numIDs]);
void
zaxisUnpack(char * unpackBuffer, int unpackBufferSize,
int * unpackBufferPos, int originNamespace, void *context,
int force_id);
void zaxisDefLtype2(int zaxisID, int ltype2);
#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