Changeset 12d15a for src/Fragmentation


Ignore:
Timestamp:
May 4, 2012, 2:19:06 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
b0b64c
Parents:
57876b
git-author:
Frederik Heber <heber@…> (10/23/11 21:24:18)
git-committer:
Frederik Heber <heber@…> (05/04/12 14:19:06)
Message:

FragmentQueue now allows for removal of jobs.

Location:
src/Fragmentation/Automation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Automation/FragmentQueue.cpp

    r57876b r12d15a  
    2525
    2626FragmentResult FragmentQueue::NoResult(-1);
    27 FragmentResult FragmentQueue::ResultDelivered(-2);
     27FragmentResult FragmentQueue::NoResultQueued(-2);
     28FragmentResult FragmentQueue::ResultDelivered(-3);
    2829
    2930/** Constructor for class FragmentQueue.
     
    3940{}
    4041
     42/** Checks whether there are jobs in the queue at all.
     43 * \return true - jobs present, false - queue is empty
     44 */
     45bool FragmentQueue::isJobPresent() const
     46{
     47  return !jobs.empty();
     48}
     49
    4150/** Pushes a FragmentJob into the internal queue for delivery to server.
    4251 *
     
    5160  ASSERT(!results.count(job.getId()),
    5261      "FragmentQueue::pushJob() - job id "+toString(job.getId())+" has already been used.");
     62  results.insert( std::make_pair(job.getId(), NoResult));
    5363  jobs.push_back(job);
    54   results.insert( std::make_pair(job.getId(), NoResult));
     64}
     65
     66/** Pops top-most FragmentJob from internal queue.
     67 *
     68 * From here on, we expect a result in FragmentQueue::results.
     69 *
     70 * \return job topmost job from queue
     71 */
     72FragmentJob FragmentQueue::popJob()
     73{
     74  ASSERT(jobs.size(),
     75      "FragmentQueue::popJob() - there are no jobs on the queue.");
     76  FragmentJob job = jobs.front();
     77  ResultMap::iterator iter = results.find(job.getId());
     78  ASSERT(iter != results.end(),
     79      "FragmentQueue::popJob() - for job "+toString(job.getId())+" no result place has been stored.");
     80  iter->second = NoResultQueued;
     81  jobs.pop_front();
     82  return job;
    5583}
    5684
     
    6593  return ((iter != results.end())
    6694      && (iter->second != NoResult)
     95      && (iter->second != NoResultQueued)
    6796      && (iter->second != ResultDelivered));
    6897}
     
    81110      "FragmentQueue::pushResult() - job "+toString(jobid)+" is not known to us.");
    82111  ASSERT(iter->second != NoResult,
    83       "FragmentQueue::pushResult() - job "+toString(jobid)+"'s result has not arrived yet.");
     112      "FragmentQueue::pushResult() - job "+toString(jobid)+" has not been request for calculation yet.");
     113  ASSERT(iter->second != NoResultQueued,
     114      "FragmentQueue::pushResult() - job "+toString(jobid)+"'s calculation is underway but not result has arrived yet.");
    84115  ASSERT(iter->second != ResultDelivered,
    85116      "FragmentQueue::pushResult() - job "+toString(jobid)+"'s result has already been delivered.");
     
    104135  ASSERT(iter != results.end(),
    105136      "FragmentQueue::pushResult() - job "+toString(result.getId())+" is not known to us.");
    106   ASSERT(iter->second == NoResult,
     137  ASSERT(iter->second == NoResultQueued,
    107138      "FragmentQueue::pushResult() - is not waiting for the result of job "+toString(result.getId())+".");
    108139  /// and overwrite NoResult in found entry
  • src/Fragmentation/Automation/FragmentQueue.hpp

    r57876b r12d15a  
    3636  // entering jobs into queue
    3737  void pushJob(FragmentJob &job);
     38  FragmentJob popJob();
     39  bool isJobPresent() const;
    3840
    3941  // querying for results
     
    4244  void pushResult(FragmentResult &result);
    4345
    44 
    4546private:
     47  //!> result that takes place in ResultQueue after job has arrived before it has been popped.
     48  static FragmentResult NoResult;
    4649  //!> result that takes place in ResultQueue until real result has arrived.
    47   static FragmentResult NoResult;
     50  static FragmentResult NoResultQueued;
    4851  //!> result that takes place in ResultQueue after real result has been delivered.
    4952  static FragmentResult ResultDelivered;
  • src/Fragmentation/Automation/unittests/FragmentQueueUnitTest.cpp

    r57876b r12d15a  
    6666  testJob.outputfile = std::string("do something");
    6767
     68  CPPUNIT_ASSERT_EQUAL(false, queue->isJobPresent() );
     69
    6870#ifndef NDEBUG
    6971  CPPUNIT_ASSERT_NO_THROW( queue->pushJob(testJob) );
     
    7375
    7476  CPPUNIT_ASSERT_EQUAL((size_t)1, queue->jobs.size());
     77  CPPUNIT_ASSERT_EQUAL(true, queue->isJobPresent() );
     78  CPPUNIT_ASSERT_EQUAL((size_t)1, queue->results.size());
     79  FragmentQueue::ResultMap::const_iterator iter = queue->results.find((JobId_t)1);
     80  CPPUNIT_ASSERT( iter != queue->results.end() );
     81  CPPUNIT_ASSERT( FragmentQueue::NoResult == iter->second );
    7582
    7683  // push same id again
     
    8188
    8289  CPPUNIT_ASSERT_EQUAL((size_t)1, queue->jobs.size());
     90  CPPUNIT_ASSERT_EQUAL((size_t)1, queue->results.size());
     91
     92  FragmentJob poppedJob;
     93#ifndef NDEBUG
     94  CPPUNIT_ASSERT_NO_THROW( poppedJob = queue->popJob() );
     95#else
     96  poppedJob = queue->popJob();
     97#endif
     98  CPPUNIT_ASSERT( poppedJob == testJob );
     99
     100  CPPUNIT_ASSERT_EQUAL((size_t)0, queue->jobs.size());
     101  CPPUNIT_ASSERT_EQUAL(false, queue->isJobPresent() );
     102  CPPUNIT_ASSERT_EQUAL((size_t)1, queue->results.size());
     103  iter = queue->results.find((JobId_t)1);
     104  CPPUNIT_ASSERT( iter != queue->results.end() );
     105  CPPUNIT_ASSERT( FragmentQueue::NoResultQueued == iter->second );
     106
     107#ifndef NDEBUG
     108  std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
     109  CPPUNIT_ASSERT_THROW( queue->popJob(), Assert::AssertionFailure );
     110#endif
    83111}
    84112
     
    91119  testJob.setId(1);
    92120  testJob.outputfile = std::string("do something");
     121#ifndef NDEBUG
     122  CPPUNIT_ASSERT_NO_THROW( queue->pushJob(testJob) );
     123#else
    93124  queue->pushJob(testJob);
     125#endif
     126#ifndef NDEBUG
     127  CPPUNIT_ASSERT_NO_THROW( queue->popJob() );
     128#else
     129  queue->popJob();
     130#endif
     131
    94132
    95133  // prepare a result
Note: See TracChangeset for help on using the changeset viewer.