Skip to content

Commit

Permalink
Refs #4024, hopeful nexus fix
Browse files Browse the repository at this point in the history
removed MakeFileBacked option from SaveMD as it was causing the problem.
  • Loading branch information
Janik Zikovsky committed Nov 16, 2011
1 parent f5ae305 commit f1e4f54
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 189 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace MDEvents
bool getInMemory() const
{ return m_inMemory; }

/** Set whether the box data (from disk) is loaded in memory (for SaveMD with MakeFileBacked).
/** Set whether the box data (from disk) is loaded in memory
* DON'T CALL THIS DIRECTLY UNLESS YOU KNOW WHAT YOU ARE DOING!
* @param inMem :: true if it is in memory */
void setInMemory(const bool inMem)
Expand Down
13 changes: 11 additions & 2 deletions Code/Mantid/Framework/MDEvents/src/LoadSQW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,20 @@ namespace Mantid
if ((m_nDataPoints * sizeof(MDEvent<4>) * 2 / 1024) < stat.availMem())
g_log.notice() << "You have enough memory available to load the " << m_nDataPoints << " points into memory; this would be faster than using a file back-end." << std::endl;

IAlgorithm_sptr saver = this->createSubAlgorithm("SaveMD" ,0.01, 0.05, true);
IAlgorithm_sptr saver = this->createSubAlgorithm("SaveMD" ,0.01, 0.04, true);
saver->setProperty("InputWorkspace", ws);
saver->setPropertyValue("Filename", m_outputFile);
saver->setProperty("MakeFileBacked", true);
saver->executeAsSubAlg();

// Re-load into a file-backed workspace
IAlgorithm_sptr loader = this->createSubAlgorithm("LoadMD" ,0.04, 0.05, true);
loader->setPropertyValue("Filename", m_outputFile);
loader->setProperty("FileBackEnd", true);
loader->setPropertyValue("OutputWorkspace", this->getPropertyValue("OutputWorkspace"));
loader->executeAsSubAlg();
ws = loader->getProperty("OutputWorkspace");
MDEventWorkspace<MDEvent<4>,4>::sptr ws4 = boost::dynamic_pointer_cast< MDEventWorkspace<MDEvent<4>,4> >(ws);
pWs = ws4.get();
m_prog->resetNumSteps(100, 0.05, 0.75);
}
else
Expand Down
274 changes: 146 additions & 128 deletions Code/Mantid/Framework/MDEvents/src/MergeMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,130 +232,139 @@ namespace MDEvents
}



//----------------------------------------------------------------------------------------------
/** Create the output workspace using the input as a guide
*
* @param ws :: first workspace from the inputs
* @return the MDEventWorkspace sptr.
*/
template<typename MDE, size_t nd>
typename MDEventWorkspace<MDE, nd>::sptr MergeMD::createOutputWS(typename MDEventWorkspace<MDE, nd>::sptr ws)
{
// Use the copy constructor to get the same dimensions etc.
typename MDEventWorkspace<MDE, nd>::sptr outWS(new MDEventWorkspace<MDE, nd>(*ws));
this->outIWS = outWS;

std::string outputFile = getProperty("OutputFilename");

// Fix the box controller settings in the output workspace so that it splits normally
BoxController_sptr bc = outWS->getBoxController();
// TODO: Specify these split parameters some smarter way?
bc->setMaxDepth(20);
bc->setSplitInto(4);
bc->setSplitThreshold(10000);

// Perform the initial box splitting.
IMDBox<MDE,nd> * box = outWS->getBox();
for (size_t d=0; d<nd; d++)
box->setExtents(d, outWS->getDimension(d)->getMinimum(), outWS->getDimension(d)->getMaximum());
box->setBoxController(bc);
outWS->splitBox();

// Save the empty WS and turn it into a file-backed MDEventWorkspace
if (!outputFile.empty())
{
IAlgorithm_sptr saver = this->createSubAlgorithm("SaveMD" ,0.01, 0.05);
saver->setProperty("InputWorkspace", outIWS);
saver->setPropertyValue("Filename", outputFile);
saver->setProperty("MakeFileBacked", true);
saver->executeAsSubAlg();
}

// Complete the file-back-end creation.
DiskMRU & mru = bc->getDiskMRU(); UNUSED_ARG(mru);
g_log.notice() << "Setting cache to 0 MB read, 400 MB write, 2000 MB small objects." << std::endl;
bc->setCacheParameters(sizeof(MDE), 0, 400000000/sizeof(MDE), 2000000000/sizeof(MDE));
g_log.notice() << "Threshold for small boxes: " << bc->getDiskMRU().getSmallThreshold() << " events." << std::endl;


return outWS;
}


//----------------------------------------------------------------------------------------------
/** Perform the merging, with generalized output workspace
*
* @param ws :: first MDEventWorkspace in the list to merge
*/
template<typename MDE, size_t nd>
void MergeMD::doExec(typename MDEventWorkspace<MDE, nd>::sptr ws)
{
// First, load all the box data
this->loadBoxData<MDE,nd>();

// Now create the output workspace
typename MDEventWorkspace<MDE, nd>::sptr outWS = this->createOutputWS<MDE,nd>(ws);

// Progress report based on events processed.
this->prog = new Progress(this, 0.1, 0.9, size_t(totalEvents));
this->prog->setNotifyStep(0.1);

// For tracking progress
uint64_t totalEventsInTasks = 0;
this->totalLoaded = 0;

// Prepare thread pool
CPUTimer overallTime;
ThreadSchedulerFIFO * ts = new ThreadSchedulerFIFO();
ThreadPool tp(ts);

for (size_t ib=0; ib<numBoxes; ib++)
{
// Add a task for each box that actually has some events
if (this->eventsPerBox[ib] > 0)
{
totalEventsInTasks += eventsPerBox[ib];
MergeMDLoadTask<MDE,nd> * task = new MergeMDLoadTask<MDE,nd>(this, ib, outWS);
ts->push(task);
}

// You've added enough tasks that will fill up some memory.
if (totalEventsInTasks > 10000000)
{
// Run all the tasks
tp.joinAll();

// Occasionally release free memory (has an effect on Linux only).
MemoryManager::Instance().releaseFreeMemory();

// Now do all the splitting tasks
g_log.information() << "Splitting boxes since we have added " << totalEventsInTasks << " events." << std::endl;
outWS->splitAllIfNeeded(ts);
if (ts->size() > 0)
prog->doReport("Splitting Boxes");
tp.joinAll();

totalEventsInTasks = 0;
}
} // for each box

// Run any final tasks
tp.joinAll();

// Final splitting
g_log.debug() << "Final splitting of boxes. " << totalEventsInTasks << " events." << std::endl;
outWS->splitAllIfNeeded(ts);
tp.joinAll();
g_log.information() << overallTime << " to do all the adding." << std::endl;

// Finish things up
this->finalizeOutput<MDE,nd>(outWS);
}




//
// //----------------------------------------------------------------------------------------------
// /** Create the output workspace using the input as a guide
// *
// * @param ws :: first workspace from the inputs
// * @return the MDEventWorkspace sptr.
// */
// template<typename MDE, size_t nd>
// typename MDEventWorkspace<MDE, nd>::sptr MergeMD::createOutputWS(typename MDEventWorkspace<MDE, nd>::sptr ws)
// {
// // Use the copy constructor to get the same dimensions etc.
// typename MDEventWorkspace<MDE, nd>::sptr outWS(new MDEventWorkspace<MDE, nd>(*ws));
// this->outIWS = outWS;
//
// std::string outputFile = getProperty("OutputFilename");
//
// // Fix the box controller settings in the output workspace so that it splits normally
// BoxController_sptr bc = outWS->getBoxController();
// // TODO: Specify these split parameters some smarter way?
// bc->setMaxDepth(20);
// bc->setSplitInto(4);
// bc->setSplitThreshold(10000);
//
// // Perform the initial box splitting.
// IMDBox<MDE,nd> * box = outWS->getBox();
// for (size_t d=0; d<nd; d++)
// box->setExtents(d, outWS->getDimension(d)->getMinimum(), outWS->getDimension(d)->getMaximum());
// box->setBoxController(bc);
// outWS->splitBox();
//
// // Save the empty WS and turn it into a file-backed MDEventWorkspace
// if (!outputFile.empty())
// {
// IAlgorithm_sptr saver = this->createSubAlgorithm("SaveMD" ,0.01, 0.05);
// saver->setProperty("InputWorkspace", outIWS);
// saver->setPropertyValue("Filename", outputFile);
// saver->executeAsSubAlg();
//
// // Re-load into a file-backed workspace
// IAlgorithm_sptr loader = this->createSubAlgorithm("LoadMD" ,0.04, 0.05, true);
// loader->setPropertyValue("Filename", outputFile);
// loader->setProperty("FileBackEnd", true);
// loader->setPropertyValue("OutputWorkspace", this->getPropertyValue("OutputWorkspace"));
// loader->executeAsSubAlg();
// outIWS = loader->getProperty("OutputWorkspace");
// outWS = boost::dynamic_pointer_cast<MDEventWorkspace<MDE, nd> >(outIWS);
// bc = outWS->getBoxController();
// }
//
// // Complete the file-back-end creation.
// DiskMRU & mru = bc->getDiskMRU(); UNUSED_ARG(mru);
// g_log.notice() << "Setting cache to 0 MB read, 400 MB write, 2000 MB small objects." << std::endl;
// bc->setCacheParameters(sizeof(MDE), 0, 400000000/sizeof(MDE), 2000000000/sizeof(MDE));
// g_log.notice() << "Threshold for small boxes: " << bc->getDiskMRU().getSmallThreshold() << " events." << std::endl;
//
//
// return outWS;
// }
//
//
// //----------------------------------------------------------------------------------------------
// /** Perform the merging, with generalized output workspace
// *
// * @param ws :: first MDEventWorkspace in the list to merge
// */
// template<typename MDE, size_t nd>
// void MergeMD::doExec(typename MDEventWorkspace<MDE, nd>::sptr ws)
// {
// // First, load all the box data
// this->loadBoxData<MDE,nd>();
//
// // Now create the output workspace
// typename MDEventWorkspace<MDE, nd>::sptr outWS = this->createOutputWS<MDE,nd>(ws);
//
// // Progress report based on events processed.
// this->prog = new Progress(this, 0.1, 0.9, size_t(totalEvents));
// this->prog->setNotifyStep(0.1);
//
// // For tracking progress
// uint64_t totalEventsInTasks = 0;
// this->totalLoaded = 0;
//
// // Prepare thread pool
// CPUTimer overallTime;
// ThreadSchedulerFIFO * ts = new ThreadSchedulerFIFO();
// ThreadPool tp(ts);
//
// for (size_t ib=0; ib<numBoxes; ib++)
// {
// // Add a task for each box that actually has some events
// if (this->eventsPerBox[ib] > 0)
// {
// totalEventsInTasks += eventsPerBox[ib];
// MergeMDLoadTask<MDE,nd> * task = new MergeMDLoadTask<MDE,nd>(this, ib, outWS);
// ts->push(task);
// }
//
// // You've added enough tasks that will fill up some memory.
// if (totalEventsInTasks > 10000000)
// {
// // Run all the tasks
// tp.joinAll();
//
// // Occasionally release free memory (has an effect on Linux only).
// MemoryManager::Instance().releaseFreeMemory();
//
// // Now do all the splitting tasks
// g_log.information() << "Splitting boxes since we have added " << totalEventsInTasks << " events." << std::endl;
// outWS->splitAllIfNeeded(ts);
// if (ts->size() > 0)
// prog->doReport("Splitting Boxes");
// tp.joinAll();
//
// totalEventsInTasks = 0;
// }
// } // for each box
//
// // Run any final tasks
// tp.joinAll();
//
// // Final splitting
// g_log.debug() << "Final splitting of boxes. " << totalEventsInTasks << " events." << std::endl;
// outWS->splitAllIfNeeded(ts);
// tp.joinAll();
// g_log.information() << overallTime << " to do all the adding." << std::endl;
//
// // Finish things up
// this->finalizeOutput<MDE,nd>(outWS);
// }
//
//
//
//



Expand All @@ -376,21 +385,30 @@ namespace MDEvents
{
this->clonedFirst = true;
std::string outputFile = getProperty("OutputFilename");
typename MDEventWorkspace<MDE, nd>::sptr outWS = ws;

// Convert the output workspace to file-backed
if (!outputFile.empty())
{
IAlgorithm_sptr saver = this->createSubAlgorithm("SaveMD" ,0.05, 0.10, true);
saver->setProperty("InputWorkspace", boost::dynamic_pointer_cast<IMDEventWorkspace>(ws) );
saver->setPropertyValue("Filename", outputFile);
saver->setProperty("MakeFileBacked", true);
saver->executeAsSubAlg();

// Re-load into a file-backed workspace
IAlgorithm_sptr loader = this->createSubAlgorithm("LoadMD" ,0.04, 0.05, true);
loader->setPropertyValue("Filename", outputFile);
loader->setProperty("FileBackEnd", true);
loader->setPropertyValue("OutputWorkspace", this->getPropertyValue("OutputWorkspace"));
loader->executeAsSubAlg();
IMDEventWorkspace_sptr outIWS = loader->getProperty("OutputWorkspace");
outWS = boost::dynamic_pointer_cast<MDEventWorkspace<MDE, nd> >(outIWS);
}
// For the output
outIWS = boost::dynamic_pointer_cast<IMDEventWorkspace>(ws);
outIWS = boost::dynamic_pointer_cast<IMDEventWorkspace>(outWS);

// Fix the box controller settings in the output workspace so that it splits normally
BoxController_sptr bc = ws->getBoxController();
BoxController_sptr bc = outWS->getBoxController();
// Fix the max depth to something bigger.
bc->setMaxDepth(20);
bc->setSplitThreshold(5000);
Expand All @@ -400,7 +418,7 @@ namespace MDEvents
g_log.notice() << "Setting cache to 2000 MB read, 400 MB write, 0 MB small objects." << std::endl;
bc->setCacheParameters(sizeof(MDE), 2000000000/sizeof(MDE), 400000000/sizeof(MDE), 0/sizeof(MDE));

return ws;
return outWS;
}


Expand Down

0 comments on commit f1e4f54

Please sign in to comment.