Skip to content

Commit 2d4b280

Browse files
committed
common/ompio: replicate fview on request
need to replicate the file view and the file pointer position on the request. This is required to correctly increment where to read/write data for every subrequest, and handle the potential situation that the code changes the file after posting an iread/iwrite but before the operation finishes. Furthermore, when initiating an iread/iwrite we need to immidiatly move the position of the handle to the end of the operation, such that subsequent read/write operations use the correct position to start out with, and don't accidentaly interfere with the already ongoing non-blocking operation. Signed-off-by: Edgar Gabriel <[email protected]>
1 parent 8ef9c87 commit 2d4b280

File tree

6 files changed

+81
-4
lines changed

6 files changed

+81
-4
lines changed

ompi/mca/common/ompio/common_ompio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ OMPI_DECLSPEC int mca_common_ompio_decode_datatype (struct ompio_file_t *fh,
350350
struct iovec **iov,
351351
uint32_t *iov_count);
352352

353+
OMPI_DECLSPEC int mca_common_ompio_fview_duplicate (struct ompio_fview_t *outfv, struct ompio_fview_t *infv);
354+
353355
OMPI_DECLSPEC int mca_common_ompio_set_callbacks(mca_common_ompio_generate_current_file_view_fn_t generate_current_file_view,
354356
mca_common_ompio_get_mca_parameter_value_fn_t get_mca_parameter_value);
355357
#endif /* MCA_COMMON_OMPIO_H */

ompi/mca/common/ompio/common_ompio_file_read.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ static void mca_common_ompio_post_next_read_subreq(struct mca_ompio_request_t *r
379379
decoded_iov.iov_base = req->req_tbuf;
380380
decoded_iov.iov_len = (req->req_num_subreqs-1 == index) ?
381381
req->req_max_data - (index* bytes_per_cycle) : req->req_size;
382-
mca_common_ompio_build_io_array (&(req->req_fh->f_fview), index, req->req_num_subreqs,
382+
mca_common_ompio_build_io_array (req->req_fview, index, req->req_num_subreqs,
383383
bytes_per_cycle, decoded_iov.iov_len,
384384
iov_count, &decoded_iov,
385385
&i, &tbw, &spc,
@@ -454,6 +454,7 @@ int mca_common_ompio_file_iread (ompio_file_t *fh,
454454
}
455455

456456
if (need_to_copy) {
457+
OMPI_MPI_OFFSET_TYPE prev_offset;
457458
size_t pipeline_buf_size = OMPIO_MCA_GET(fh, pipeline_buffer_size);
458459

459460
OMPIO_PREPARE_READ_BUF(fh, buf, count, datatype, ompio_req->req_tbuf,
@@ -467,7 +468,26 @@ int mca_common_ompio_file_iread (ompio_file_t *fh,
467468
ompio_req->req_fh = fh;
468469
ompio_req->req_ompi.req_status.MPI_ERROR = MPI_SUCCESS;
469470

471+
ompio_req->req_fview = (struct ompio_fview_t *) malloc(sizeof(struct ompio_fview_t));
472+
if (NULL == ompio_req->req_fview) {
473+
opal_output(1, "common_ompio: error allocating memory\n");
474+
return OMPI_ERR_OUT_OF_RESOURCE;
475+
}
476+
ret = mca_common_ompio_fview_duplicate(ompio_req->req_fview, &fh->f_fview);
477+
if (OMPI_SUCCESS != ret) {
478+
return ret;
479+
}
480+
mca_common_ompio_file_get_position (fh, &prev_offset );
470481
mca_common_ompio_post_next_read_subreq (ompio_req, 0);
482+
483+
/* Move file pointer to the end of the operation.
484+
* Otherwise posting another I/O operation will start of
485+
* from the wrong file position. The request will update
486+
* the position where to write the next chunk of data
487+
* using its internal copy of the file view and file pointer
488+
* position.
489+
*/
490+
mca_common_ompio_set_explicit_offset (fh, prev_offset+max_data);
471491
}
472492
else {
473493
int i = 0;

ompi/mca/common/ompio/common_ompio_file_view.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Copyright (c) 2017-2018 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
1515
* Copyright (c) 2017 IBM Corporation. All rights reserved.
16+
* Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
1617
* $COPYRIGHT$
1718
*
1819
* Additional copyrights may follow
@@ -414,4 +415,32 @@ OMPI_MPI_OFFSET_TYPE get_contiguous_chunk_size (ompio_file_t *fh, int flag)
414415
return global_avg[0];
415416
}
416417

418+
int mca_common_ompio_fview_duplicate (struct ompio_fview_t *outfv, struct ompio_fview_t *infv)
419+
{
420+
uint32_t i;
421+
422+
memset(outfv, 0, sizeof(struct ompio_fview_t));
423+
outfv->f_flags = infv->f_flags;
424+
outfv->f_offset = infv->f_offset;
425+
outfv->f_disp = infv->f_disp;
426+
outfv->f_iov_count = infv->f_iov_count;
417427

428+
outfv->f_decoded_iov = (struct iovec*) malloc (outfv->f_iov_count * sizeof(struct iovec));
429+
if (NULL == outfv->f_decoded_iov) {
430+
opal_output(1, "common_ompio_duplicate_fview: could not allocate memory\n");
431+
return OMPI_ERR_OUT_OF_RESOURCE;
432+
}
433+
for (i=0; i < outfv->f_iov_count; i++) {
434+
outfv->f_decoded_iov[i].iov_base = infv->f_decoded_iov[i].iov_base;
435+
outfv->f_decoded_iov[i].iov_len = infv->f_decoded_iov[i].iov_len ;
436+
}
437+
438+
outfv->f_position_in_file_view = infv->f_position_in_file_view;
439+
outfv->f_total_bytes = infv->f_total_bytes;
440+
outfv->f_index_in_file_view = infv->f_index_in_file_view;
441+
outfv->f_view_extent = infv->f_view_extent;
442+
outfv->f_view_size = infv->f_view_size;
443+
outfv->f_etype_size = infv->f_etype_size;
444+
445+
return OMPI_SUCCESS;
446+
}

ompi/mca/common/ompio/common_ompio_file_write.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Copyright (c) 2008-2019 University of Houston. All rights reserved.
1313
* Copyright (c) 2015-2018 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
15-
* Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
15+
* Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
1616
* $COPYRIGHT$
1717
*
1818
* Additional copyrights may follow
@@ -327,7 +327,7 @@ static void mca_common_ompio_post_next_write_subreq(struct mca_ompio_request_t *
327327
decoded_iov.iov_base = req->req_tbuf;
328328
decoded_iov.iov_len = req->req_size;
329329
opal_convertor_pack (&req->req_convertor, &decoded_iov, &iov_count, &pos);
330-
mca_common_ompio_build_io_array (&(req->req_fh->f_fview), index, req->req_num_subreqs,
330+
mca_common_ompio_build_io_array (req->req_fview, index, req->req_num_subreqs,
331331
bytes_per_cycle, pos,
332332
iov_count, &decoded_iov,
333333
&i, &tbw, &spc,
@@ -398,7 +398,9 @@ int mca_common_ompio_file_iwrite (ompio_file_t *fh,
398398
}
399399

400400
if (need_to_copy) {
401+
OMPI_MPI_OFFSET_TYPE prev_offset;
401402
size_t pipeline_buf_size = OMPIO_MCA_GET(fh, pipeline_buffer_size);
403+
402404
OMPIO_PREPARE_BUF (fh, buf, count, datatype, ompio_req->req_tbuf,
403405
&ompio_req->req_convertor, max_data,
404406
pipeline_buf_size, NULL, iov_count);
@@ -410,7 +412,26 @@ int mca_common_ompio_file_iwrite (ompio_file_t *fh,
410412
ompio_req->req_fh = fh;
411413
ompio_req->req_ompi.req_status.MPI_ERROR = MPI_SUCCESS;
412414

415+
ompio_req->req_fview = (struct ompio_fview_t *) malloc(sizeof(struct ompio_fview_t));
416+
if (NULL == ompio_req->req_fview) {
417+
opal_output(1, "common_ompio: error allocating memory\n");
418+
return OMPI_ERR_OUT_OF_RESOURCE;
419+
}
420+
ret = mca_common_ompio_fview_duplicate(ompio_req->req_fview, &fh->f_fview);
421+
if (OMPI_SUCCESS != ret) {
422+
return ret;
423+
}
424+
mca_common_ompio_file_get_position (fh, &prev_offset );
413425
mca_common_ompio_post_next_write_subreq (ompio_req, 0);
426+
427+
/* Move file pointer to the end of the operation.
428+
* Otherwise posting another I/O operation will start of
429+
* from the wrong file position. The request will update
430+
* the position where to write the next chunk of data
431+
* using its internal copy of the file view and file pointer
432+
* position.
433+
*/
434+
mca_common_ompio_set_explicit_offset (fh, prev_offset+max_data);
414435
}
415436
else {
416437
mca_common_ompio_decode_datatype (fh, datatype, count,

ompi/mca/common/ompio/common_ompio_request.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void mca_common_ompio_request_construct(mca_ompio_request_t* req)
8282
req->req_num_subreqs = 0;
8383
req->req_subreqs_completed = 0;
8484
req->req_fh = NULL;
85+
req->req_fview = NULL;
8586
req->req_post_followup = false;
8687

8788
OBJ_CONSTRUCT(&req->req_item, opal_list_item_t);
@@ -96,7 +97,10 @@ void mca_common_ompio_request_destruct(mca_ompio_request_t* req)
9697
if ( NULL != req->req_data ) {
9798
free (req->req_data);
9899
}
99-
100+
if (NULL != req->req_fview) {
101+
free (req->req_fview->f_decoded_iov);
102+
free (req->req_fview);
103+
}
100104
return;
101105
}
102106

ompi/mca/common/ompio/common_ompio_request.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct mca_ompio_request_t {
6666
int req_num_subreqs;
6767
int req_subreqs_completed;
6868
ompio_file_t *req_fh;
69+
ompio_fview_t *req_fview;
6970
bool req_post_followup;
7071
};
7172
typedef struct mca_ompio_request_t mca_ompio_request_t;

0 commit comments

Comments
 (0)