Commit 2d2dfc7e authored by Jan Oliver Oelerich's avatar Jan Oliver Oelerich

Fixes #6, where the temporary results file was not written at all when the...

Fixes #6, where the temporary results file was not written at all when the master process doesn't participate in the calculation.
parent 7d776fe2
Pipeline #42822890 passed with stages
in 3 minutes and 17 seconds
......@@ -929,6 +929,24 @@ string getTempFileName() {
return output::fmt("%s/%s_%d.bin", p.tmpDir(), p.uuid(), mpi_rank);
}
void IO::generateTemporaryResultFile() {
auto &mpi_env = mpi::Environment::getInstance();
int mpi_rank = mpi_env.rank();
auto tmpfile = std::ofstream(getTempFileName(), std::ios::binary | std::ios::app);
if(tmpfile.fail()) {
output::error("Couldn't open temporary binary %s file for writing.\n", getTempFileName());
}
tmpfile.write(reinterpret_cast<const char *>(&mpi_rank), sizeof(mpi_rank));
tmpfile.close();
}
void IO::removeTemporaryResultFile() {
remove(getTempFileName().c_str());
}
void IO::writeTemporaryResult(unsigned int idefocus, unsigned int iconf, ScanPoint &point,
shared_ptr<memory::buffer::number_buffer<float>> &ibuf,
shared_ptr<memory::buffer::number_buffer<float>> &cbuf) {
......@@ -938,7 +956,7 @@ void IO::writeTemporaryResult(unsigned int idefocus, unsigned int iconf, ScanPoi
auto tmpfile = std::ofstream(getTempFileName(), std::ios::binary | std::ios::app);
// the format is as follows:
// int rank
// int rank ( written in generateTemporaryResultFile)
// for each pixel:
// unsigned int idefocus
// unsigned int iconf
......@@ -951,8 +969,7 @@ void IO::writeTemporaryResult(unsigned int idefocus, unsigned int iconf, ScanPoi
}
if(tmpfile.tellp() == 0) {
// empty file, write rank
tmpfile.write(reinterpret_cast<const char *>(&mpi_rank), sizeof(mpi_rank));
output::error("File %s shouldn't be empty! Has writeTemporaryResult() been called?\n", getTempFileName());
}
tmpfile.write(reinterpret_cast<const char *>(&idefocus), sizeof(idefocus));
......@@ -1044,9 +1061,6 @@ void IO::copyFromTemporaryFile(const shared_ptr<GridManager> &gridman,
nc_close(f_id);
// remove the file, as all the data is now transferred.
remove(getTempFileName().c_str());
}
......
......@@ -114,6 +114,16 @@ namespace stemsalabim {
const std::shared_ptr<GridManager> &gridman, const ScanPoint &point,
std::shared_ptr<memory::buffer::number_buffer<float>> &cbuf, int g_id, int v_id);
/*!
* Generates the temporary result file and writes the header.
*/
static void generateTemporaryResultFile();
/*!
* Removes the temporary result file.
*/
static void removeTemporaryResultFile();
/*!
* Write temporary results to a binary file (custom format). This is done in MPI mode.
* @param idefocus current defocus index
......
......@@ -277,6 +277,8 @@ void Simulation::run() {
output::fmt("Finished calculation of transmission functions in %s.\n",
output::humantime(algorithms::getTimeSince(t1))));
_io->generateTemporaryResultFile();
if(mpi_env.isMaster()) {
multisliceMaster(st);
} else {
......@@ -294,7 +296,7 @@ void Simulation::run() {
if(rank == mpi_env.rank()) {
auto start = high_resolution_clock::now();
_io->copyFromTemporaryFile(_gridman, _adf_intensity_buffer, _cbed_intensity_buffer);
_io->removeTemporaryResultFile();
printLine(st,
output::fmt("Finished copying pixels for %s.\n",
output::humantime(algorithms::getTimeSince(start))));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment