Skip to content

Commit 46e31dc

Browse files
khou2020wkliao
authored andcommitted
Only rank 0 count attribute write size:
Attribute write is collective. However, only one process will actually write the attribute. In HDF5 and ADIOS2 driver, when counting application write size, attirbute write should only be count on one process. We count attribute write size at rank 0. Attribute read size is still counted on all processes.
1 parent 8e3812c commit 46e31dc

4 files changed

+27
-7
lines changed

src/drivers/e3sm_io_driver_adios2.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,15 @@ e3sm_io_driver_adios2::~e3sm_io_driver_adios2 () {
9090

9191
int e3sm_io_driver_adios2::create (std::string path, MPI_Comm comm, MPI_Info info, int *fid) {
9292
int nerrs = 0;
93+
int err;
9394
adios2_error aerr;
9495
adios2_file *fp;
9596
char ng[32];
9697

9798
fp = new adios2_file ();
9899
fp->path = std::string (path);
100+
err = MPI_Comm_rank (comm, &(fp->rank));
101+
CHECK_MPIERR
99102

100103
fp->adp = adios2_init (comm, "");
101104
CHECK_APTR (fp->adp)
@@ -134,12 +137,15 @@ err_out:;
134137

135138
int e3sm_io_driver_adios2::open (std::string path, MPI_Comm comm, MPI_Info info, int *fid) {
136139
int nerrs = 0;
140+
int err;
137141
adios2_error aerr;
138142
adios2_file *fp;
139143
adios2_step_status stat;
140144

141145
fp = new adios2_file ();
142146
fp->path = std::string (path);
147+
err = MPI_Comm_rank (comm, &(fp->rank));
148+
CHECK_MPIERR
143149

144150
fp->adp = adios2_init (comm, "");
145151
CHECK_APTR (fp->adp)
@@ -176,8 +182,8 @@ int e3sm_io_driver_adios2::close (int fid) {
176182
adios2_bool result;
177183

178184
if (fp->ep) {
179-
//aerr = adios2_end_step (fp->ep);
180-
//CHECK_AERR
185+
// aerr = adios2_end_step (fp->ep);
186+
// CHECK_AERR
181187

182188
aerr = adios2_close (fp->ep);
183189
CHECK_AERR
@@ -532,8 +538,10 @@ int e3sm_io_driver_adios2::put_att (
532538
CHECK_APTR (aid)
533539
}
534540

535-
esize = adios2_type_size (atype);
536-
fp->putsize += size * esize;
541+
if (fp->rank == 0) {
542+
esize = adios2_type_size (atype);
543+
fp->putsize += size * esize;
544+
}
537545

538546
err_out:;
539547
return nerrs;

src/drivers/e3sm_io_driver_adios2.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class e3sm_io_driver_adios2 : public e3sm_io_driver {
5656
adios2_operator *op;
5757
MPI_Offset putsize = 0;
5858
MPI_Offset getsize = 0;
59+
int rank;
5960
} adios2_file;
6061
std::vector<adios2_file *> files;
6162
double tsel, twrite, tread, text;

src/drivers/e3sm_io_driver_hdf5.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ e3sm_io_driver_hdf5::~e3sm_io_driver_hdf5 () {
130130

131131
int e3sm_io_driver_hdf5::create (std::string path, MPI_Comm comm, MPI_Info info, int *fid) {
132132
int nerrs = 0;
133+
int err;
133134
herr_t herr;
134135
hid_t faplid;
135136
hdf5_file *fp;
@@ -138,6 +139,9 @@ int e3sm_io_driver_hdf5::create (std::string path, MPI_Comm comm, MPI_Info info,
138139

139140
fp = new hdf5_file (*this);
140141

142+
err = MPI_Comm_rank (comm, &(fp->rank));
143+
CHECK_MPIERR
144+
141145
faplid = H5Pcreate (H5P_FILE_ACCESS);
142146
CHECK_HID (faplid)
143147
herr = H5Pset_fapl_mpio (faplid, comm, info);
@@ -166,6 +170,7 @@ err_out:;
166170

167171
int e3sm_io_driver_hdf5::open (std::string path, MPI_Comm comm, MPI_Info info, int *fid) {
168172
int nerrs = 0;
173+
int err;
169174
herr_t herr;
170175
hid_t faplid;
171176
hdf5_file *fp;
@@ -174,6 +179,9 @@ int e3sm_io_driver_hdf5::open (std::string path, MPI_Comm comm, MPI_Info info, i
174179

175180
fp = new hdf5_file (*this);
176181

182+
err = MPI_Comm_rank (comm, &(fp->rank));
183+
CHECK_MPIERR
184+
177185
faplid = H5Pcreate (H5P_FILE_ACCESS);
178186
CHECK_HID (faplid)
179187
herr = H5Pset_fapl_mpio (faplid, comm, info);
@@ -528,9 +536,11 @@ int e3sm_io_driver_hdf5::put_att (
528536

529537
E3SM_IO_TIMER_STOP (E3SM_IO_TIMER_HDF5)
530538

531-
err = MPI_Type_size (type, &esize);
532-
CHECK_MPIERR
533-
fp->putsize += asize * esize;
539+
if (fp->rank == 0) {
540+
err = MPI_Type_size (type, &esize);
541+
CHECK_MPIERR
542+
fp->putsize += asize * esize;
543+
}
534544

535545
err_out:;
536546
if (asid >= 0) H5Sclose (asid);

src/drivers/e3sm_io_driver_hdf5.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class e3sm_io_driver_hdf5 : public e3sm_io_driver {
3434
MPI_Offset recsize = 0;
3535
MPI_Offset putsize = 0;
3636
MPI_Offset getsize = 0;
37+
int rank;
3738

3839
#ifndef HDF5_HAVE_DWRITE_MULTI
3940
typedef struct H5D_rw_multi_t {

0 commit comments

Comments
 (0)