Skip to content

Commit 47dbe91

Browse files
committed
Check file system type at rank 0 only and then bcast result
1 parent 362665d commit 47dbe91

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

src/drivers/ncmpio/ncmpio_create.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ ncmpio_create(MPI_Comm comm,
9090
* nc_num_aggrs_per_node: number of processes per node to be the INA
9191
* aggregators.
9292
*
93-
* ncp->fstype will be set in ncmpio_hint_extract().
93+
* ncp->fstype will be initialized in ncmpio_hint_extract(), and set in
94+
* PNCIO_FileSysType().
9495
*/
9596
ncmpio_hint_extract(ncp, user_info);
9697

97-
if (ncp->fstype == PNCIO_FSTYPE_CHECK)
98+
if (ncp->fstype == PNCIO_FSTYPE_CHECK && rank == 0)
9899
/* Check file system type. If the given file does not exist, check its
99100
* folder. Currently PnetCDF's PNCIO drivers support Lustre
100101
* (PNCIO_LUSTRE) and Unix File System (PNCIO_UFS).
@@ -159,13 +160,20 @@ if (rank == 0) printf("%s at %d fstype=%s\n", __func__,__LINE__,(ncp->fstype ==
159160
* NC_NOCLOBBER mode is set in ncmpi_create.
160161
*/
161162
#ifdef HAVE_ACCESS
162-
if (nprocs > 1)
163-
TRACE_COMM(MPI_Bcast)(&file_exist, 1, MPI_INT, 0, comm);
163+
if (nprocs > 1) {
164+
int msg[2] = {file_exist, ncp->fstype};
165+
TRACE_COMM(MPI_Bcast)(msg, 2, MPI_INT, 0, comm);
166+
file_exist = msg[0];
167+
ncp->fstype = msg[1];
168+
}
164169
if (file_exist) {
165170
NCI_Free(ncp);
166171
DEBUG_RETURN_ERROR(NC_EEXIST)
167172
}
168173
#else
174+
if (nprocs > 1)
175+
TRACE_COMM(MPI_Bcast)(&ncp->fstype, 1, MPI_INT, 0, comm);
176+
169177
/* Add MPI_MODE_EXCL mode for MPI_File_open, so it can error out, if
170178
* the file exists.
171179
*/
@@ -183,8 +191,10 @@ if (rank == 0) printf("%s at %d fstype=%s\n", __func__,__LINE__,(ncp->fstype ==
183191
if (rank == 0 && file_exist) {
184192
if (!use_trunc) { /* delete the file */
185193
#ifdef HAVE_UNLINK
186-
/* unlink() is likely faster then truncate(), but may be still
187-
* expensive
194+
/* unlink() is likely faster then truncate(). However, unlink()
195+
* can be expensive when the file size is large. For example,
196+
* it taook 1.1061 seconds to delete a file of size 27.72 GiB
197+
* on Perlmutter at NERSC.
188198
*/
189199
err = unlink(filename);
190200
if (err < 0 && errno != ENOENT)
@@ -283,12 +293,11 @@ if (rank == 0) printf("%s at %d fstype=%s\n", __func__,__LINE__,(ncp->fstype ==
283293
* when the file to be clobbered is a symbolic link.
284294
*/
285295
if (nprocs > 1) {
286-
int msg[2];
287-
msg[0] = err;
288-
msg[1] = mpiomode;
289-
TRACE_COMM(MPI_Bcast)(&msg, 2, MPI_INT, 0, comm);
290-
err = msg[0];
291-
mpiomode = msg[1];
296+
int msg[3] = {err, mpiomode, ncp->fstype};
297+
TRACE_COMM(MPI_Bcast)(&msg, 3, MPI_INT, 0, comm);
298+
err = msg[0];
299+
mpiomode = msg[1];
300+
ncp->fstype = msg[2];
292301
}
293302
if (err != NC_NOERR) return err;
294303
}

src/drivers/ncmpio/ncmpio_open.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,21 @@ ncmpio_open(MPI_Comm comm,
8181
* nc_num_aggrs_per_node: number of processes per node to be INA
8282
* aggregators.
8383
*
84-
* ncp->fstype will be set in ncmpio_hint_extract().
84+
* ncp->fstype will be initialized in ncmpio_hint_extract() and set in
85+
* PNCIO_FileSysType().
8586
*/
8687
ncmpio_hint_extract(ncp, user_info);
8788

88-
if (ncp->fstype == PNCIO_FSTYPE_CHECK)
89-
/* Check file system type. If the given file does not exist, check its
90-
* folder. Currently PnetCDF's PNCIO drivers support Lustre
91-
* (PNCIO_LUSTRE) and Unix File System (PNCIO_UFS).
92-
*/
93-
ncp->fstype = PNCIO_FileSysType(path);
89+
if (ncp->fstype == PNCIO_FSTYPE_CHECK) {
90+
if (rank == 0)
91+
/* Check file system type. If the given file does not exist, check
92+
* its parent folder. Currently PnetCDF's PNCIO drivers support
93+
* Lustre (PNCIO_LUSTRE) and Unix File System (PNCIO_UFS).
94+
*/
95+
ncp->fstype = PNCIO_FileSysType(path);
96+
97+
MPI_Bcast(&ncp->fstype, 1, MPI_INT, 0, ncp->comm);
98+
}
9499

95100
#ifdef WKL_DEBUG
96101
if (rank == 0) printf("%s at %d fstype=%s\n", __func__,__LINE__,(ncp->fstype == PNCIO_FSTYPE_MPIIO)? "PNCIO_FSTYPE_MPIIO" : (ncp->fstype == PNCIO_LUSTRE) ? "PNCIO_LUSTRE" : "PNCIO_UFS");

0 commit comments

Comments
 (0)