Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HDF5 write WINDOWS when running in parallel #130

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/TimeSeries.C
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,17 @@ void TimeSeries::writeWindows( string suffix )
// int ret = createWriteAttr( grp, "WINDOWS", H5T_NATIVE_DOUBLE, data_space, windows );
// if( ret < 0 )
{
int ret = openWriteAttr(grp, "WINDOWS", H5T_NATIVE_DOUBLE, windows);
if( ret < 0 )
std::cout << "TimeSeries::writeWindows, Error could not create/open data space" << std::endl;
if( H5Lexists(grp, "WINDOWS", H5P_DEFAULT) ) {
int ret = openWriteAttr(grp, "WINDOWS", H5T_NATIVE_DOUBLE, windows);
if( ret < 0 )
std::cout << "TimeSeries::writeWindows, Error could not create/open data space" << std::endl;
}
else {
hsize_t nelements=4;
hid_t data_space = H5Screate_simple(1, &nelements, NULL);
int ret = createWriteAttr( grp, "WINDOWS", H5T_NATIVE_DOUBLE, data_space, windows );
H5Sclose(data_space);
}
}
H5Gclose(grp);
}
Expand Down
14 changes: 10 additions & 4 deletions src/moptmain.C
Original file line number Diff line number Diff line change
Expand Up @@ -2192,9 +2192,12 @@ int main(int argc, char **argv)
nlcg( simulation, nspar, nmpars, xs, nmpard, xm, GlobalSources, GlobalTimeSeries,
GlobalObservations, myRank, mopt );

for( int e=0 ; e < GlobalTimeSeries.size(); e++ )
for( int m=0 ; m < GlobalTimeSeries[e].size() ; m++ )
GlobalTimeSeries[e][m]->writeWindows();
for( int e=0 ; e < GlobalTimeSeries.size(); e++ )
for( int m=0 ; m < GlobalTimeSeries[e].size() ; m++ ) {
// This barrier is needed as each process needs to open and write to the HDF5 file independently, and one at a time
MPI_Barrier(simulation.m_1d_communicator);
GlobalTimeSeries[e][m]->writeWindows();
}

sw4_profile->time_stamp("Done optimizer");
sw4_profile->flush();
Expand Down Expand Up @@ -2318,8 +2321,11 @@ int main(int argc, char **argv)
simulation.solveTT(GlobalSources[e][0], GlobalObservations[e], coarse, nmpars, mopt->m_mp,
mopt->get_wave_mode(), e, simulation.getRank());

for( int s=0 ; s < GlobalObservations[e].size() ; s++)
for( int s=0 ; s < GlobalObservations[e].size() ; s++) {
// This barrier is needed as each process needs to open and write to the HDF5 file independently, and one at a time
MPI_Barrier(simulation.m_1d_communicator);
GlobalObservations[e][s]->writeWindows();
}
}
}
}
Expand Down