@@ -469,12 +469,17 @@ int PIOc_inq_unlimdims_impl(int ncid, int *nunlimdimsp, int *unlimdimidsp)
469469#endif
470470
471471 /* A failure to inquire is not fatal */
472- mpierr = MPI_Allreduce (MPI_IN_PLACE, &ierr, 1 , MPI_INT, MPI_BOR, ios->my_comm );
472+ if (file->iotype != PIO_IOTYPE_PNETCDF) {
473+ /* Skip MPI communication for checking error code, because PnetCDF
474+ * always keeps metadata consistent among all ranks.
475+ */
476+ mpierr = MPI_Allreduce (MPI_IN_PLACE, &ierr, 1 , MPI_INT, MPI_BOR, ios->my_comm );
473477
474- if (mpierr != MPI_SUCCESS){
475- spio_ltimer_stop (ios->io_fstats ->tot_timer_name );
476- spio_ltimer_stop (file->io_fstats ->tot_timer_name );
477- return check_mpi (NULL , file, mpierr, __FILE__, __LINE__);
478+ if (mpierr != MPI_SUCCESS){
479+ spio_ltimer_stop (ios->io_fstats ->tot_timer_name );
480+ spio_ltimer_stop (file->io_fstats ->tot_timer_name );
481+ return check_mpi (NULL , file, mpierr, __FILE__, __LINE__);
482+ }
478483 }
479484
480485 if (ierr != PIO_NOERR){
@@ -484,6 +489,12 @@ int PIOc_inq_unlimdims_impl(int ncid, int *nunlimdimsp, int *unlimdimidsp)
484489 return ierr;
485490 }
486491
492+ /* Skip MPI communications below, because PnetCDF always keeps metadata
493+ * consistent among all ranks.
494+ */
495+ if (file->iotype == PIO_IOTYPE_PNETCDF)
496+ goto fn_exit;
497+
487498 /* Broadcast results to all tasks. Ignore NULL parameters. */
488499 if ((mpierr = MPI_Bcast (&tmp_nunlimdims, 1 , MPI_INT, ios->ioroot , ios->my_comm )))
489500 {
@@ -508,6 +519,7 @@ int PIOc_inq_unlimdims_impl(int ncid, int *nunlimdimsp, int *unlimdimidsp)
508519 return check_mpi (NULL , file, mpierr, __FILE__, __LINE__);
509520 }
510521
522+ fn_exit:
511523 spio_ltimer_stop (ios->io_fstats ->tot_timer_name );
512524 spio_ltimer_stop (file->io_fstats ->tot_timer_name );
513525 return PIO_NOERR;
0 commit comments