Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit 1e79adc

Browse files
committed
io/ompio: fix the preallocate function
handle preallocating sizes less than the current file size correctly.
1 parent 98bc218 commit 1e79adc

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

ompi/mca/io/ompio/io_ompio_file_open.c

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,29 @@ mca_io_ompio_file_preallocate (ompi_file_t *fh,
430430

431431
tmp = diskspace;
432432

433-
data->ompio_fh.f_comm->c_coll.coll_bcast (&tmp,
434-
1,
435-
OMPI_OFFSET_DATATYPE,
436-
OMPIO_ROOT,
437-
data->ompio_fh.f_comm,
438-
data->ompio_fh.f_comm->c_coll.coll_bcast_module);
433+
ret = data->ompio_fh.f_comm->c_coll.coll_bcast (&tmp,
434+
1,
435+
OMPI_OFFSET_DATATYPE,
436+
OMPIO_ROOT,
437+
data->ompio_fh.f_comm,
438+
data->ompio_fh.f_comm->c_coll.coll_bcast_module);
439+
if ( OMPI_SUCCESS != ret ) {
440+
return OMPI_ERROR;
441+
}
439442

440443
if (tmp != diskspace) {
441444
return OMPI_ERROR;
442445
}
446+
ret = data->ompio_fh.f_fs->fs_file_get_size (&data->ompio_fh,
447+
&current_size);
448+
if ( OMPI_SUCCESS != ret ) {
449+
return OMPI_ERROR;
450+
}
451+
452+
if ( current_size > diskspace ) {
453+
return OMPI_SUCCESS;
454+
}
455+
443456

444457
/* ROMIO explanation
445458
On file systems with no preallocation function, we have to
@@ -449,8 +462,8 @@ mca_io_ompio_file_preallocate (ompi_file_t *fh,
449462
preallocation is needed.
450463
*/
451464
if (OMPIO_ROOT == data->ompio_fh.f_rank) {
452-
ret = data->ompio_fh.f_fs->fs_file_get_size (&data->ompio_fh,
453-
&current_size);
465+
OMPI_MPI_OFFSET_TYPE prev_offset;
466+
ompio_io_ompio_file_get_position (&data->ompio_fh, &prev_offset );
454467

455468
size = diskspace;
456469
if (size > current_size) {
@@ -462,7 +475,8 @@ mca_io_ompio_file_preallocate (ompi_file_t *fh,
462475
buf = (char *) malloc (OMPIO_PREALLOC_MAX_BUF_SIZE);
463476
if (NULL == buf) {
464477
opal_output(1, "OUT OF MEMORY\n");
465-
return OMPI_ERR_OUT_OF_RESOURCE;
478+
ret = OMPI_ERR_OUT_OF_RESOURCE;
479+
goto exit;
466480
}
467481
written = 0;
468482

@@ -473,11 +487,11 @@ mca_io_ompio_file_preallocate (ompi_file_t *fh,
473487
}
474488
ret = mca_io_ompio_file_read (fh, buf, len, MPI_BYTE, status);
475489
if (ret != OMPI_SUCCESS) {
476-
return OMPI_ERROR;
490+
goto exit;
477491
}
478492
ret = mca_io_ompio_file_write (fh, buf, len, MPI_BYTE, status);
479493
if (ret != OMPI_SUCCESS) {
480-
return OMPI_ERROR;
494+
goto exit;
481495
}
482496
written += len;
483497
}
@@ -494,20 +508,25 @@ mca_io_ompio_file_preallocate (ompi_file_t *fh,
494508
}
495509
ret = mca_io_ompio_file_write (fh, buf, len, MPI_BYTE, status);
496510
if (ret != OMPI_SUCCESS) {
497-
return OMPI_ERROR;
511+
goto exit;
498512
}
499513
written += len;
500514
}
501515
}
502-
if (NULL != buf) {
503-
free (buf);
504-
buf = NULL;
505-
}
516+
517+
// This operation should not affect file pointer position.
518+
ompi_io_ompio_set_explicit_offset ( &data->ompio_fh, prev_offset);
519+
}
520+
521+
exit:
522+
free ( buf );
523+
fh->f_comm->c_coll.coll_bcast ( &ret, 1, MPI_INT, OMPIO_ROOT, fh->f_comm,
524+
fh->f_comm->c_coll.coll_bcast_module);
525+
526+
if ( diskspace > current_size ) {
527+
data->ompio_fh.f_fs->fs_file_set_size (&data->ompio_fh, diskspace);
506528
}
507-
ret = data->ompio_fh.f_fs->fs_file_set_size (&data->ompio_fh, diskspace);
508529

509-
fh->f_comm->c_coll.coll_barrier (fh->f_comm,
510-
fh->f_comm->c_coll.coll_barrier_module);
511530
return ret;
512531
}
513532

0 commit comments

Comments
 (0)