@@ -139,6 +139,7 @@ if (rank == 0) { printf("\nxxxx %s at %d: ---- %s\n",__func__,__LINE__,fd->filen
139139 err = ncmpii_error_posix2nc ("open" );
140140 goto err_out ;
141141 }
142+ fd -> is_open = 1 ;
142143
143144err_out :
144145 MPI_Bcast (stripin_info , 4 , MPI_INT , 0 , fd -> comm );
@@ -154,6 +155,7 @@ if (rank == 0) { printf("\nxxxx %s at %d: ---- %s\n",__func__,__LINE__,fd->filen
154155 __func__ ,__LINE__ , rank , fd -> filename , strerror (errno ));
155156 return ncmpii_error_posix2nc ("ioctl" );
156157 }
158+ fd -> is_open = 1 ;
157159 }
158160
159161 /* construct cb_nodes rank list */
@@ -196,6 +198,7 @@ if (rank == 0) { printf("\nxxxx %s at %d: ---- %s\n",__func__,__LINE__,fd->filen
196198 err = ncmpii_error_posix2nc ("open" );
197199 goto err_out ;
198200 }
201+ fd -> is_open = 1 ;
199202
200203 /* Only root obtains the striping information and bcast to all other
201204 * processes.
@@ -233,7 +236,7 @@ int PNCIO_File_open(MPI_Comm comm,
233236 * called to check the file system type.
234237 */
235238 char value [MPI_MAX_INFO_VAL + 1 ], int_str [16 ];
236- int i , err , min_err ;
239+ int i , err , min_err , status = NC_NOERR ;
237240
238241 fd -> comm = comm ;
239242 fd -> filename = filename ; /* without file system type name prefix */
@@ -256,9 +259,13 @@ int PNCIO_File_open(MPI_Comm comm,
256259 else
257260 MPI_Info_dup (info , & fd -> info );
258261
259- err = PNCIO_File_SetInfo (fd , fd -> info );
260- if (err != NC_NOERR )
261- return err ;
262+ status = PNCIO_File_SetInfo (fd , fd -> info );
263+ if (status != NC_NOERR && status != NC_EMULTIDEFINE_HINTS ) {
264+ /* Inconsistent I/O hints is not a fatal error.
265+ * In PNCIO_File_SetInfo(), root's hints overwrite local's.
266+ */
267+ goto err_out ;
268+ }
262269
263270#if defined(PNETCDF_PROFILING ) && (PNETCDF_PROFILING == 1 )
264271 for (i = 0 ; i < NMEASURES ; i ++ ) {
@@ -269,6 +276,10 @@ int PNCIO_File_open(MPI_Comm comm,
269276
270277 assert (fd -> file_system != PNCIO_FSTYPE_MPIIO );
271278
279+ /* TODO: When hint romio_no_indep_rw hint is set to true, only aggregators open
280+ * the file.
281+ * Note because fd->is_agg is set at the end of create/open call.
282+ */
272283 if (fd -> file_system == PNCIO_LUSTRE ) {
273284 if (amode & MPI_MODE_CREATE )
274285 err = PNCIO_Lustre_create (fd , amode );
@@ -281,11 +292,10 @@ int PNCIO_File_open(MPI_Comm comm,
281292 else
282293 err = GEN_open (fd );
283294 }
284- if (err != NC_NOERR ) goto err_out ;
285-
286- /* TODO: when hint no_indep_rw hint is set to true, only aggregators open
287- * the file */
288- fd -> is_open = 1 ;
295+ if (err != NC_NOERR ) { /* fatal error */
296+ status = err ;
297+ goto err_out ;
298+ }
289299
290300 /* set file striping hints */
291301 snprintf (int_str , 16 , "%d" , fd -> hints -> striping_unit );
@@ -323,22 +333,24 @@ int PNCIO_File_open(MPI_Comm comm,
323333 /* collective buffer is used only by I/O aggregators only */
324334 if (fd -> is_agg ) {
325335 fd -> io_buf = NCI_Calloc (1 , fd -> hints -> cb_buffer_size );
326- if (fd -> io_buf == NULL )
327- return NC_ENOMEM ;
336+ if (fd -> io_buf == NULL ) /* fatal error */
337+ status = NC_ENOMEM ;
328338 }
329339
330340err_out :
331- MPI_Allreduce (& err , & min_err , 1 , MPI_INT , MPI_MIN , comm );
341+ MPI_Allreduce (& status , & min_err , 1 , MPI_INT , MPI_MIN , comm );
332342 /* All NC errors are < 0 */
333- if (min_err < 0 ) {
334- if (err == 0 ) /* close file if opened successfully */
343+
344+ if (min_err != NC_NOERR ) {
345+ if (status == NC_NOERR && fd -> is_open )
346+ /* close file if opened successfully */
335347 close (fd -> fd_sys );
336348 NCI_Free (fd -> hints );
337349 if (fd -> info != MPI_INFO_NULL )
338350 MPI_Info_free (& (fd -> info ));
339351 if (fd -> io_buf != NULL )
340352 NCI_Free (fd -> io_buf );
341353 }
342- return err ;
354+ return status ;
343355}
344356
0 commit comments