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

Commit d722cc4

Browse files
authored
Merge pull request #1212 from edgargabriel/pr/get_byte_offset_fix
io/ompio: fix the get_byte_offset code
2 parents cabc66e + 1e79adc commit d722cc4

File tree

1 file changed

+49
-29
lines changed

1 file changed

+49
-29
lines changed

ompi/mca/io/ompio/io_ompio_file_open.c

Lines changed: 49 additions & 29 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

@@ -768,35 +787,36 @@ mca_io_ompio_file_get_byte_offset (ompi_file_t *fh,
768787
{
769788
mca_io_ompio_data_t *data;
770789
int i, k, index;
771-
size_t position;
772-
size_t total_bytes;
773790
size_t temp_offset;
774791

775792
data = (mca_io_ompio_data_t *) fh->f_io_selected_data;
776793

777794
temp_offset = data->ompio_fh.f_view_extent *
778795
(offset*data->ompio_fh.f_etype_size / data->ompio_fh.f_view_size);
796+
779797

780-
position = 0;
781-
total_bytes = (offset*data->ompio_fh.f_etype_size) % data->ompio_fh.f_view_size;
798+
i = (offset*data->ompio_fh.f_etype_size) % data->ompio_fh.f_view_size;
782799
index = 0;
783-
i = total_bytes;
784800
k = 0;
785801

786802
while (1) {
787-
k += data->ompio_fh.f_decoded_iov[index].iov_len;
803+
k = data->ompio_fh.f_decoded_iov[index].iov_len;
788804
if (i >= k) {
789-
i = i - data->ompio_fh.f_decoded_iov[index].iov_len;
790-
position += data->ompio_fh.f_decoded_iov[index].iov_len;
791-
index = index+1;
805+
i -= k;
806+
index++;
807+
if ( 0 == i ) {
808+
k=0;
809+
break;
810+
}
792811
}
793812
else {
813+
k=i;
794814
break;
795815
}
796816
}
797817

798818
*disp = data->ompio_fh.f_disp + temp_offset +
799-
(OMPI_MPI_OFFSET_TYPE)(intptr_t)data->ompio_fh.f_decoded_iov[index].iov_base;
819+
(OMPI_MPI_OFFSET_TYPE)(intptr_t)data->ompio_fh.f_decoded_iov[index].iov_base + k;
800820

801821
return OMPI_SUCCESS;
802822
}

0 commit comments

Comments
 (0)