Skip to content

Commit 329d52a

Browse files
authored
Fix SaveMD performance regression -- ornl-next (mantidproject#40049)
Sister to PR mantidproject#40034
1 parent 632d411 commit 329d52a

File tree

7 files changed

+12
-20
lines changed

7 files changed

+12
-20
lines changed

Framework/DataObjects/src/BoxControllerNeXusIO.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ bool BoxControllerNeXusIO::openFile(const std::string &fileName, const std::stri
154154
CreateEventGroup();
155155
// we are in MDEvent group now (either created or opened)
156156

157-
// read if exist and create if not the group, which is responsible for saving
158-
// DiskBuffer information;
157+
// read if exist and create if not the group, which is responsible for saving DiskBuffer information;
159158
getDiskBufferFileData();
160159

161160
if (m_ReadOnly)

Framework/MDAlgorithms/src/SaveMD.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ namespace {
3232
template <typename MDE, size_t nd>
3333
void prepareUpdate(MDBoxFlatTree &BoxFlatStruct, BoxController *bc, typename MDEventWorkspace<MDE, nd>::sptr ws,
3434
const std::string &filename) {
35-
// remove all boxes from the DiskBuffer. DB will calculate boxes positions
36-
// on HDD.
35+
// remove all boxes from the DiskBuffer. DB will calculate boxes positions on HDD.
3736
bc->getFileIO()->flushCache();
38-
// flatten the box structure; this will remember boxes file positions in the
39-
// box structure
37+
// flatten the box structure; this will remember boxes file positions in the box structure
4038
BoxFlatStruct.initFlatStructure(ws, filename);
4139
}
4240
} // namespace
@@ -74,8 +72,7 @@ void SaveMD::init() {
7472

7573
//----------------------------------------------------------------------------------------------
7674
/** Save the MDEventWorskpace to a file.
77-
* Based on the Intermediate Data Format Detailed Design Document, v.1.R3 found
78-
*in SVN.
75+
* Based on the Intermediate Data Format Detailed Design Document, v.1.R3 found in SVN.
7976
*
8077
* @param ws :: MDEventWorkspace of the given type
8178
*/
@@ -106,18 +103,15 @@ template <typename MDE, size_t nd> void SaveMD::doSaveEvents(typename MDEventWor
106103
}
107104

108105
auto prog = std::make_unique<Progress>(this, 0.0, 0.05, 1);
109-
if (updateFileBackend) // workspace has its own file and ignores any changes
110-
// to the
111-
// algorithm parameters
106+
if (updateFileBackend) // workspace has its own file and ignores any changes to the algorithm parameters
112107
{
113108
if (!ws->isFileBacked())
114109
throw std::runtime_error(" attempt to update non-file backed workspace");
115110
filename = bc->getFileIO()->getFileName();
116111
}
117112

118113
//-----------------------------------------------------------------------------------------------------
119-
// create or open WS group and put there additional information about WS and
120-
// its dimensions
114+
// create or open WS group and put there additional information about WS and its dimensions
121115
auto nDims = static_cast<int>(nd);
122116
bool data_exist;
123117
auto file =
@@ -166,8 +160,7 @@ template <typename MDE, size_t nd> void SaveMD::doSaveEvents(typename MDEventWor
166160
// do not spend time on empty or masked boxes
167161
if (boxe->getDataInMemorySize() == 0 || boxe->getIsMasked())
168162
continue;
169-
// save boxes directly using the boxes file postion, precalculated in
170-
// boxFlatStructure.
163+
// save boxes directly using the boxes file postion, precalculated in boxFlatStructure.
171164
saveableTag->save();
172165
// remove boxes data from memory. This will actually correctly set the
173166
// tag indicatin that data were not loaded.

Framework/MDAlgorithms/src/SaveMD2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void SaveMD2::doSaveHisto(const Mantid::DataObjects::MDHistoWorkspace_sptr &ws)
153153
for (size_t d = 0; d < numDims; d++) {
154154
IMDDimension_const_sptr dim = ws->getDimension(d);
155155
// Size in each dimension (reverse order for RANK)
156-
size[numDims - 1 - d] = int(dim->getNBins());
156+
size[numDims - 1 - d] = dim->getNBins();
157157
}
158158

159159
Nexus::DimVector chunks = size;

Framework/Nexus/inc/MantidNexus/NexusFile_fwd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,4 @@ class File;
148148
} // namespace Mantid::Nexus
149149

150150
constexpr std::size_t NX_MAXRANK(32);
151-
constexpr Mantid::Nexus::dimsize_t NX_UNLIMITED(-1); // 0xffffffffffffffffUL; // AKA max of unsigned long
151+
constexpr Mantid::Nexus::dimsize_t NX_UNLIMITED(-1); // AKA max of unsigned long, equivalent to H5S_UNLIMITED

Framework/Nexus/src/NexusFile.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,6 @@ void File::makeCompData(std::string const &name, NXnumtype const type, DimVector
872872
for (int i = 0; i < rank; i++) {
873873
if (dims[i] <= 0 || dims[i] == NX_UNLIMITED) {
874874
mydim[i] = 1;
875-
chunkdims[i] = 1;
876875
maxdims[i] = H5S_UNLIMITED;
877876
}
878877
}

Framework/Nexus/test/NexusFileReadWriteTest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,14 @@ class NexusFileReadWriteTest : public CxxTest::TestSuite {
268268
// see https://github.com/nexusformat/code/blob/master/test/test_nxunlimited.c
269269
constexpr std::size_t DATA_SIZE(200);
270270
double d[DATA_SIZE];
271-
Mantid::Nexus::DimVector dims{NX_UNLIMITED, DATA_SIZE};
271+
Mantid::Nexus::DimVector dims{NX_UNLIMITED, DATA_SIZE}, chunk{DATA_SIZE, DATA_SIZE};
272272

273273
FileResource resource("test_nxunlimited.nx5");
274274
std::string filename = resource.fullPath();
275275
File fileid = do_prep_files(filename);
276276

277277
// make and open compressed data
278-
TS_ASSERT_THROWS_NOTHING(fileid.makeCompData("data", NXnumtype::FLOAT64, dims, NXcompression::NONE, dims, true));
278+
TS_ASSERT_THROWS_NOTHING(fileid.makeCompData("data", NXnumtype::FLOAT64, dims, NXcompression::NONE, chunk, true));
279279

280280
Mantid::Nexus::DimVector slab_start{0, 0}, slab_size{1, DATA_SIZE};
281281
for (Mantid::Nexus::dimsize_t i = 0; i < 2; i++) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- fixed a performance regression in :ref:`SaveMD <algm-SaveMD>` that led to dramatically increased save times in release 6.13.1.1.

0 commit comments

Comments
 (0)