Skip to content

Commit bbdd6bd

Browse files
committed
Merge pull request #1750 from edgargabriel/pr/get_byte_offset_fix
io/ompio: fix the get_byte_offset code
2 parents 9f9f70e + d6af544 commit bbdd6bd

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

ompi/mca/io/ompio/io_ompio_file_open.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -769,35 +769,36 @@ mca_io_ompio_file_get_byte_offset (ompi_file_t *fh,
769769
{
770770
mca_io_ompio_data_t *data;
771771
int i, k, index;
772-
size_t position;
773-
size_t total_bytes;
774772
size_t temp_offset;
775773

776774
data = (mca_io_ompio_data_t *) fh->f_io_selected_data;
777775

778776
temp_offset = data->ompio_fh.f_view_extent *
779777
(offset*data->ompio_fh.f_etype_size / data->ompio_fh.f_view_size);
778+
780779

781-
position = 0;
782-
total_bytes = (offset*data->ompio_fh.f_etype_size) % data->ompio_fh.f_view_size;
780+
i = (offset*data->ompio_fh.f_etype_size) % data->ompio_fh.f_view_size;
783781
index = 0;
784-
i = total_bytes;
785782
k = 0;
786783

787784
while (1) {
788-
k += data->ompio_fh.f_decoded_iov[index].iov_len;
785+
k = data->ompio_fh.f_decoded_iov[index].iov_len;
789786
if (i >= k) {
790-
i = i - data->ompio_fh.f_decoded_iov[index].iov_len;
791-
position += data->ompio_fh.f_decoded_iov[index].iov_len;
792-
index = index+1;
787+
i -= k;
788+
index++;
789+
if ( 0 == i ) {
790+
k=0;
791+
break;
792+
}
793793
}
794794
else {
795+
k=i;
795796
break;
796797
}
797798
}
798799

799800
*disp = data->ompio_fh.f_disp + temp_offset +
800-
(OMPI_MPI_OFFSET_TYPE)(intptr_t)data->ompio_fh.f_decoded_iov[index].iov_base;
801+
(OMPI_MPI_OFFSET_TYPE)(intptr_t)data->ompio_fh.f_decoded_iov[index].iov_base + k;
801802

802803
return OMPI_SUCCESS;
803804
}

0 commit comments

Comments
 (0)