Commit 4fb82e34 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Replace small allocation with stack-returned struct.

parent bd36c8ef
......@@ -41,27 +41,18 @@ int setTag ( int ID, int sc )
/***************************************************************/
tag_t * getTag ( int tag )
struct fileOpTag getTag(int tag)
{
tag_t *rtag;
struct fileOpTag rtag;
rtag = ( tag_t * ) xmalloc ( sizeof ( tag_t ));
rtag->id = tag / tagKey;
rtag->command = tag % tagKey;
rtag.id = tag / tagKey;
rtag.command = tag % tagKey;
return rtag;
}
/***************************************************************/
void ungetTag ( tag_t *rtag )
{
free ( rtag );
return;
}
/***************************************************************/
size_t pioFileWrite ( int fileID, int tsID, const void *buffer, size_t len )
{
size_t iret = CDI_UNDEFID;
......
......@@ -32,16 +32,15 @@ typedef bool (*eqPredicate)(void *, void *);
typedef struct queue_t queue_t;
typedef struct
struct fileOpTag
{
int id;
int command;
} tag_t;
};
/* pio.c */
int setTag ( int, int );
tag_t * getTag ( int );
void ungetTag ( tag_t * );
int setTag(int, int);
struct fileOpTag getTag(int);
/* pio_dbuffer.c */
int dbuffer_init ( struct dBuffer **, size_t );
......
......@@ -257,7 +257,7 @@ void pioWriterAIO(void)
long amount, buffersize;
char *messageBuffer, *pMB, *filename, *temp;
int messagesize, source, tag, i, id;
tag_t *rtag;
struct fileOpTag rtag;
MPI_Status status;
MPI_Comm commNode = commInqCommNode ();
int nProcsCollNode = commInqSizeNode () - commInqSizeColl ();
......@@ -276,16 +276,15 @@ void pioWriterAIO(void)
source = status.MPI_SOURCE;
tag = status.MPI_TAG;
rtag = getTag ( tag );
rtag = getTag(tag);
xmpi ( MPI_Get_count ( &status, MPI_CHAR, &messagesize ));
xdebug ( "receive message from source=%d, id=%d, command=%d ( %s ), "
"messagesize=%d",
source, rtag->id, rtag->command,
command2charP [ rtag->command ], messagesize);
"messagesize=%d", source, rtag.id, rtag.command,
command2charP[rtag.command], messagesize);
switch ( rtag->command )
switch (rtag.command)
{
case IO_Open_file:
......@@ -303,21 +302,20 @@ void pioWriterAIO(void)
pMB += ( strlen ( temp ) + 1 );
amount = ( long ) ( messageBuffer + messagesize - pMB );
xdebug ( "command %s, filename=%s, buffersize=%ld, amount=%ld",
command2charP [ rtag->command ], filename,
buffersize, amount );
xdebug("command %s, filename=%s, buffersize=%ld, amount=%ld",
command2charP[rtag.command], filename, buffersize, amount);
if (!(bfd = queueGet(bibBFiledataPA, fileIDTest,
(void *)(intptr_t)rtag->id)))
(void *)(intptr_t)rtag.id)))
{
queueForeach(bibBFiledataPA, elemCheck, filename);
bfd = initBFiledataPA(filename, buffersize, nProcsCollNode);
if ((id = queueAdd(bibBFiledataPA, bfd)) < 0)
xabort("fileID=%d not unique", rtag->id);
xabort("fileID=%d not unique", rtag.id);
}
else
if (strcmp(filename, bfd->name) != 0)
xabort("filename is not consistent, fileID=%d", rtag->id);
xabort("filename is not consistent, fileID=%d", rtag.id);
bfd->currOpIndex = bfd->nextOpIndex;
bfd->nextOpIndex = ( bfd->nextOpIndex + 1 ) % nPrefStreams;
......@@ -334,13 +332,13 @@ void pioWriterAIO(void)
case IO_Send_buffer:
if (!(bfd = queueGet(bibBFiledataPA, fileIDTest,
(void *)(intptr_t)rtag->id)))
xabort("fileID=%d is not in queue", rtag->id);
(void *)(intptr_t)rtag.id)))
xabort("fileID=%d is not in queue", rtag.id);
amount = messagesize;
xdebug ( "command: %s, id=%d, name=%s",
command2charP [ rtag->command ], rtag->id, bfd->name );
xdebug("command: %s, id=%d, name=%s",
command2charP[rtag.command], rtag.id, bfd->name );
bfd->currOpIndex = bfd->nextOpIndex;
bfd->nextOpIndex = ( bfd->nextOpIndex + 1 ) % nPrefStreams;
......@@ -355,13 +353,13 @@ void pioWriterAIO(void)
case IO_Close_file:
if (!(bfd = queueGet(bibBFiledataPA, fileIDTest,
(void *)(intptr_t)rtag->id)))
xabort("fileID=%d is not in queue", rtag->id );
(void *)(intptr_t)rtag.id)))
xabort("fileID=%d is not in queue", rtag.id);
amount = messagesize;
xdebug ( " command %s, id=%d, name=%s",
command2charP [ rtag->command ], rtag->id, bfd->name );
xdebug(" command %s, id=%d, name=%s",
command2charP[rtag.command], rtag.id, bfd->name);
bfd->currOpIndex = bfd->nextOpIndex;
......@@ -384,9 +382,9 @@ void pioWriterAIO(void)
if ( bfd->finished )
{
xdebug ( "all are finished with file %d, delete node", rtag->id );
xdebug ( "all are finished with file %d, delete node", rtag.id);
queueDelNode(bibBFiledataPA, fileIDTest,
(void *)(intptr_t)rtag->id);
(void *)(intptr_t)rtag.id);
}
break;
case IO_Finalize:
......@@ -412,7 +410,6 @@ void pioWriterAIO(void)
" return");
queueDestroy ( bibBFiledataPA );
}
if ( rtag ) ungetTag ( rtag );
return;
}
}
......
......@@ -191,7 +191,7 @@ bool compareNamesAPF ( void *v1, void *v2 )
void fpgPOSIXFPGUARDSENDRECV ( void )
{
int i, source, iret;
tag_t *rtag;
struct fileOpTag rtag;
MPI_Status status;
bFiledataPF *bfd;
queue_t *bibBFiledataPF;
......@@ -209,31 +209,28 @@ void fpgPOSIXFPGUARDSENDRECV ( void )
{
xmpi ( MPI_Probe ( MPI_ANY_SOURCE, MPI_ANY_TAG, commNode, &status ));
source = status.MPI_SOURCE;
rtag = getTag ( status.MPI_TAG );
rtag = getTag(status.MPI_TAG);
xdebug ( "receive message from source=%d, id=%d, command=%d ( %s )",
source, rtag->id, rtag->command,
command2charP [ rtag->command ]);
xdebug("receive message from source=%d, id=%d, command=%d ( %s )",
source, rtag.id, rtag.command, command2charP[rtag.command]);
switch ( rtag->command )
switch (rtag.command)
{
case IO_Open_file:
if (!(bfd = queueGet(bibBFiledataPF, fileIDTestB,
(void *)(intptr_t)rtag->id)))
(void *)(intptr_t)rtag.id)))
{
bfd = ( bFiledataPF * ) initBFiledataPF ( rtag->id,
nProcsCollNode );
bfd = initBFiledataPF(rtag.id, nProcsCollNode);
if ((iret = queueAdd(bibBFiledataPF, bfd)) < 0)
xabort("fileID=%d not unique", rtag->id);
xabort("fileID=%d not unique", rtag.id);
}
*( bfd->nfinished + source ) = false;
xdebug ( "id=%d, command=%d ( %s ), send offset=%ld",
rtag->id, rtag->command,
command2charP [ rtag->command ], bfd->offset );
xdebug("id=%d, command=%d ( %s ), send offset=%ld", rtag.id,
rtag.command, command2charP[rtag.command], bfd->offset);
xmpi ( MPI_Sendrecv ( &( bfd->offset ), 1, MPI_LONG, source, status.MPI_TAG,
&amount, 1, MPI_LONG, source, status.MPI_TAG,
......@@ -241,21 +238,20 @@ void fpgPOSIXFPGUARDSENDRECV ( void )
bfd->offset += amount;
xdebug ( "id=%d, command=%d ( %s ), recv amount=%ld, set offset=%ld",
rtag->id, rtag->command,
command2charP [ rtag->command ], amount, bfd->offset );
xdebug("id=%d, command=%d ( %s ), recv amount=%ld, set offset=%ld",
rtag.id, rtag.command, command2charP[rtag.command], amount,
bfd->offset);
break;
case IO_Set_fp:
if (!(bfd = queueGet(bibBFiledataPF, fileIDTestB,
(void *)(intptr_t)rtag->id)))
xabort("fileId=%d not in queue", rtag->id);
(void *)(intptr_t)rtag.id)))
xabort("fileId=%d not in queue", rtag.id);
xdebug ( "id=%d, command=%d ( %s ), send offset=%ld",
rtag->id, rtag->command,
command2charP [ rtag->command ], bfd->offset );
xdebug("id=%d, command=%d ( %s ), send offset=%ld", rtag.id,
rtag.command, command2charP[rtag.command], bfd->offset);
xmpi ( MPI_Sendrecv ( &( bfd->offset ), 1, MPI_LONG, source, status.MPI_TAG,
&amount, 1, MPI_LONG, source, status.MPI_TAG,
......@@ -263,21 +259,20 @@ void fpgPOSIXFPGUARDSENDRECV ( void )
bfd->offset += amount;
xdebug ( "id=%d, command=%d ( %s ), recv amount=%ld, set offset=%ld",
rtag->id, rtag->command,
command2charP [ rtag->command ], amount, bfd->offset );
xdebug("id=%d, command=%d ( %s ), recv amount=%ld, set offset=%ld",
rtag.id, rtag.command, command2charP[rtag.command], amount,
bfd->offset);
break;
case IO_Close_file:
if (!(bfd = queueGet(bibBFiledataPF, fileIDTestB,
(void *)(intptr_t)rtag->id)))
xabort("fileId=%d not in queue", rtag->id);
(void *)(intptr_t)rtag.id)))
xabort("fileId=%d not in queue", rtag.id);
xdebug ( "id=%d, command=%d ( %s )), send offset=%ld",
rtag->id, rtag->command,
command2charP [ rtag->command ], bfd->offset );
xdebug("id=%d, command=%d ( %s )), send offset=%ld", rtag.id,
rtag.command, command2charP[rtag.command], bfd->offset);
xmpi ( MPI_Sendrecv ( &( bfd->offset ), 1, MPI_LONG, source, status.MPI_TAG,
&amount, 1, MPI_LONG, source, status.MPI_TAG,
......@@ -285,9 +280,9 @@ void fpgPOSIXFPGUARDSENDRECV ( void )
bfd->offset += amount;
xdebug ( "id=%d, command=%d ( %s ), recv amount=%ld, set offset=%ld",
rtag->id, rtag->command,
command2charP [ rtag->command ], amount, bfd->offset );
xdebug("id=%d, command=%d ( %s ), recv amount=%ld, set offset=%ld",
rtag.id, rtag.command, command2charP[rtag.command], amount,
bfd->offset);
bfd->nfinished[source] = true;
......@@ -301,7 +296,7 @@ void fpgPOSIXFPGUARDSENDRECV ( void )
}
if ( bfd->finished )
queueDelNode(bibBFiledataPF, fileIDTestB, (void *)(intptr_t)rtag->id);
queueDelNode(bibBFiledataPF, fileIDTestB, (void *)(intptr_t)rtag.id);
break;
case IO_Finalize:
{
......@@ -326,7 +321,6 @@ void fpgPOSIXFPGUARDSENDRECV ( void )
xdebug("%s", "cleanup queue");
queueDestroy ( bibBFiledataPF );
}
if ( rtag ) ungetTag ( rtag );
return;
}
}
......
......@@ -152,7 +152,7 @@ pioWriterStdIO(void)
char *messageBuffer = NULL;
char *pMB, *filename, *temp;
int messagesize, source, tag, i, id;
tag_t *rtag = NULL;
struct fileOpTag rtag;
MPI_Status status;
MPI_Comm commNode = commInqCommNode ();
int nProcsCollNode = commInqSizeNode () - commInqSizeColl ();
......@@ -173,18 +173,15 @@ pioWriterStdIO(void)
source = status.MPI_SOURCE;
tag = status.MPI_TAG;
if ( rtag ) ungetTag ( rtag );
if (( rtag = getTag ( tag )) == NULL )
xabort ( "getTag () failed" );
rtag = getTag(tag);
xmpi ( MPI_Get_count ( &status, MPI_CHAR, &messagesize ));
xdebug ( "RECEIVE MESSAGE FROM SOURCE=%d, ID=%d, COMMAND=%d ( %s ),"
"MESSAGESIZE=%d",
source, rtag->id, rtag->command,
command2charP [ rtag->command ], messagesize);
"MESSAGESIZE=%d", source, rtag.id, rtag.command,
command2charP[rtag.command], messagesize);
switch ( rtag->command )
switch (rtag.command)
{
case IO_Open_file:
......@@ -204,23 +201,22 @@ pioWriterStdIO(void)
amount = (size_t)(messageBuffer + messagesize - pMB);
xdebug("command %s, filename=%s, buffersize=%zu, amount=%zu",
command2charP [ rtag->command ], filename,
buffersize, amount);
command2charP[rtag.command], filename, buffersize, amount);
if (!(bfd = queueGet(bibBFiledataP, fileIDTest,
(void *)(intptr_t)rtag->id)))
(void *)(intptr_t)rtag.id)))
{
queueForeach(bibBFiledataP, elemCheck, filename);
bfd = initBFiledataP(filename, buffersize, nProcsCollNode,
rtag->id);
rtag.id);
if ((id = queueAdd(bibBFiledataP, bfd)) < 0)
xabort("fileID=%d not unique", rtag->id);
xabort("fileID=%d not unique", rtag.id);
}
else
if (strcmp(filename, bfd->name) != 0)
xabort("filename is not consistent, fileID=%d", rtag->id);
xabort("filename is not consistent, fileID=%d", rtag.id);
memcpy(bfd->fb->buffer, pMB, amount);
......@@ -233,14 +229,13 @@ pioWriterStdIO(void)
case IO_Send_buffer:
if (!(bfd = queueGet(bibBFiledataP, fileIDTest,
(void *)(intptr_t)rtag->id)))
xabort("fileID=%d is not in queue", rtag->id );
(void *)(intptr_t)rtag.id)))
xabort("fileID=%d is not in queue", rtag.id );
amount = messagesize;
xdebug ( "COMMAND %s, ID=%d, NAME=%s",
command2charP [ rtag->command ],
rtag->id, bfd->name );
xdebug("COMMAND %s, ID=%d, NAME=%s", command2charP[rtag.command],
rtag.id, bfd->name);
xmpi ( MPI_Recv ( bfd->fb->buffer, amount, MPI_CHAR, source, tag,
commNode, &status ));
......@@ -251,21 +246,20 @@ pioWriterStdIO(void)
case IO_Close_file:
xdebug ( "COMMAND %s, FILE%d, SOURCE%d",
command2charP [ rtag->command ], rtag->id, source );
xdebug("COMMAND %s, FILE%d, SOURCE%d",
command2charP[rtag.command], rtag.id, source);
if (!(bfd = queueGet(bibBFiledataP, fileIDTest,
(void *)(intptr_t)rtag->id)))
xabort("fileID=%d is not in queue", rtag->id);
(void *)(intptr_t)rtag.id)))
xabort("fileID=%d is not in queue", rtag.id);
amount = messagesize;
xdebug("COMMAND %s, ID=%d, NAME=%s, AMOUNT=%zu",
command2charP [ rtag->command ], rtag->id, bfd->name,
amount);
command2charP[rtag.command], rtag.id, bfd->name, amount);
xmpi ( MPI_Recv ( bfd->fb->buffer, amount, MPI_CHAR, source, tag,
commNode, &status ));
xmpi(MPI_Recv(bfd->fb->buffer, amount, MPI_CHAR, source, tag,
commNode, &status ));
writeP ( bfd, amount );
......@@ -283,8 +277,9 @@ pioWriterStdIO(void)
if ( bfd->finished )
{
xdebug ( "all are finished with file %d, delete node", rtag->id );
queueDelNode(bibBFiledataP, fileIDTest, (void *)(intptr_t)rtag->id);
xdebug("all are finished with file %d, delete node", rtag.id);
queueDelNode(bibBFiledataP, fileIDTest,
(void *)(intptr_t)rtag.id);
}
break;
case IO_Finalize:
......@@ -313,8 +308,6 @@ pioWriterStdIO(void)
" return");
queueDestroy ( bibBFiledataP );
}
if ( rtag ) ungetTag ( rtag );
return;
}
}
......
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