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

Make sure written file does not contain extra bytes.

parent 6035f626
......@@ -91,6 +91,7 @@ int destroyAFiledataMPINONB ( void *v )
MPI_Status status;
int rankNode = commInqRankNode ();
double startTime;
MPI_Offset endpos;
of = (aFiledataM * ) v;
......@@ -103,7 +104,8 @@ int destroyAFiledataMPINONB ( void *v )
xmpi ( MPI_Wait ( & ( of->request ), &status ));
xmpi(MPI_Barrier(commInqCommNode()));
accumWait += ( MPI_Wtime () - startTime );
iret = MPI_File_sync ( of->fh );
xmpi(MPI_File_get_position_shared(of->fh, &endpos));
xmpi(MPI_File_set_size(of->fh, endpos));
iret = MPI_File_close ( & ( of->fh ));
/* file closed, cleanup */
......
......@@ -150,6 +150,8 @@ destroyBFiledataPA ( void *v )
nextFinishOp = ( nextFinishOp + 1 ) % nPrefStreams;
}
if ((iret = ftruncate(bfd->handle, bfd->offset)) == -1)
xabort("failed to truncate file %s: %s", bfd->name, strerror(errno));
if (( iret = close ( bfd->handle )) == -1 )
xabort("failed to close %s", bfd->name);
......
......@@ -62,7 +62,8 @@ initBFiledataP(char *filename, size_t bs, int nc, int fileID)
if (( bfp->fp = fopen ( filename, "w" )) == NULL )
xabort("Failed to open %s", bfp->name);
int fd = fileno(bfp->fp);
ftruncate(fd, (off_t)0);
dbuffer_init ( & ( bfp->fb ), ( size_t )( bfp->size ));
bfp->finished = false;
......@@ -89,7 +90,6 @@ destroyBFiledataP(void *v)
xdebug ( "filename=%s, cleanup, in", bfp->name );
/* close file */
if (( iret = fclose ( bfp->fp )) == EOF )
xabort("Failed to close %s", bfp->name);
......
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