Skip to content

Commit dedbba5

Browse files
committed
io/ompio: fix for CID 1645290
move the lock protection to include setting the flag indicating that a split collective is already ongoing. Unify the handling for write_all_begin, write_at_all_begin, read_all_begin, read_at_all_begin (even if coverty only complained about one of them). Signed-off-by: Edgar Gabriel <[email protected]>
1 parent b8d45a2 commit dedbba5

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

ompi/mca/io/ompio/io_ompio_file_read.c

+26-9
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,22 @@ int mca_io_ompio_file_read_all_begin (ompi_file_t *fh,
362362

363363
data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
364364
fp = &data->ompio_fh;
365-
if ( true == fp->f_split_coll_in_use ) {
366-
printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
367-
return MPI_ERR_OTHER;
365+
if (true == fp->f_split_coll_in_use) {
366+
printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
367+
return MPI_ERR_OTHER;
368+
}
369+
370+
OPAL_THREAD_LOCK(&fh->f_lock);
371+
if (true == fp->f_split_coll_in_use) {
372+
printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
373+
OPAL_THREAD_UNLOCK(&fh->f_lock);
374+
return MPI_ERR_OTHER;
368375
}
369-
/* No need for locking fh->f_lock, that is done in file_iread_all */
370-
ret = mca_io_ompio_file_iread_all ( fh, buf, count, datatype, &fp->f_split_coll_req );
371376
fp->f_split_coll_in_use = true;
377+
OPAL_THREAD_UNLOCK(&fh->f_lock);
378+
379+
/* No need for locking fh->f_lock for the operation itself, that is done in io_ompio_file_iread_all */
380+
ret = mca_io_ompio_file_iread_all ( fh, buf, count, datatype, &fp->f_split_coll_req );
372381

373382
return ret;
374383
}
@@ -402,14 +411,22 @@ int mca_io_ompio_file_read_at_all_begin (ompi_file_t *fh,
402411
data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
403412
fp = &data->ompio_fh;
404413

405-
if ( true == fp->f_split_coll_in_use ) {
406-
printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
407-
return MPI_ERR_REQUEST;
414+
if (true == fp->f_split_coll_in_use) {
415+
printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
416+
return MPI_ERR_REQUEST;
408417
}
418+
409419
OPAL_THREAD_LOCK(&fh->f_lock);
420+
if (true == fp->f_split_coll_in_use) {
421+
printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
422+
OPAL_THREAD_UNLOCK(&fh->f_lock);
423+
return MPI_ERR_REQUEST;
424+
}
425+
426+
fp->f_split_coll_in_use = true;
410427
ret = mca_common_ompio_file_iread_at_all ( fp, offset, buf, count, datatype, &fp->f_split_coll_req );
411428
OPAL_THREAD_UNLOCK(&fh->f_lock);
412-
fp->f_split_coll_in_use = true;
429+
413430
return ret;
414431
}
415432

ompi/mca/io/ompio/io_ompio_file_write.c

+23-8
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,21 @@ int mca_io_ompio_file_write_all_begin (ompi_file_t *fh,
371371
data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
372372
fp = &data->ompio_fh;
373373
if ( true == fp->f_split_coll_in_use ) {
374-
printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
375-
return MPI_ERR_OTHER;
374+
printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
375+
return MPI_ERR_OTHER;
376+
}
377+
378+
OPAL_THREAD_LOCK(&fh->f_lock);
379+
if (true == fp->f_split_coll_in_use) {
380+
printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
381+
OPAL_THREAD_UNLOCK(&fh->f_lock);
382+
return MPI_ERR_REQUEST;
376383
}
377-
/* No need for locking fh->f_lock, that is done in file_iwrite_all */
378-
ret = mca_io_ompio_file_iwrite_all ( fh, buf, count, datatype, &fp->f_split_coll_req );
379384
fp->f_split_coll_in_use = true;
385+
OPAL_THREAD_UNLOCK(&fh->f_lock);
386+
387+
/* No need for locking fh->f_lock the operation itself, that is done in io_ompio_file_iwrite_all */
388+
ret = mca_io_ompio_file_iwrite_all ( fh, buf, count, datatype, &fp->f_split_coll_req );
380389

381390
return ret;
382391
}
@@ -412,14 +421,20 @@ int mca_io_ompio_file_write_at_all_begin (ompi_file_t *fh,
412421
data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
413422
fp = &data->ompio_fh;
414423

415-
if ( true == fp->f_split_coll_in_use ) {
416-
printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
417-
return MPI_ERR_REQUEST;
424+
if (true == fp->f_split_coll_in_use) {
425+
printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
426+
return MPI_ERR_REQUEST;
418427
}
428+
419429
OPAL_THREAD_LOCK(&fh->f_lock);
430+
if (true == fp->f_split_coll_in_use) {
431+
printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
432+
OPAL_THREAD_UNLOCK(&fh->f_lock);
433+
return MPI_ERR_REQUEST;
434+
}
435+
fp->f_split_coll_in_use = true;
420436
ret = mca_common_ompio_file_iwrite_at_all ( fp, offset, buf, count, datatype, &fp->f_split_coll_req );
421437
OPAL_THREAD_UNLOCK(&fh->f_lock);
422-
fp->f_split_coll_in_use = true;
423438

424439
return ret;
425440
}

0 commit comments

Comments
 (0)