source: src/Fragmentation/Automation/FragmentQueue.cpp@ 6f2bc7

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
Last change on this file since 6f2bc7 was bf56f6, checked in by Frederik Heber <heber@…>, 13 years ago

Added getPresentJobs() to FragmentQueue.

  • Property mode set to 100644
File size: 6.0 KB
RevLine 
[b5ebb5]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2011 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * FragmentQueue.cpp
10 *
11 * Created on: Oct 19, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "FragmentQueue.hpp"
23
24#include "CodePatterns/Assert.hpp"
25
[35f587]26FragmentResult::ptr FragmentQueue::NoResult( new FragmentResult(-1) );
27FragmentResult::ptr FragmentQueue::NoResultQueued( new FragmentResult(-2) );
28FragmentResult::ptr FragmentQueue::ResultDelivered( new FragmentResult(-3) );
[b5ebb5]29
30/** Constructor for class FragmentQueue.
31 *
32 */
33FragmentQueue::FragmentQueue()
34{}
35
36/** Destructor for class FragmentQueue.
37 *
38 */
39FragmentQueue::~FragmentQueue()
[78ad7d]40{
41 jobs.clear();
42 results.clear();
43}
[b5ebb5]44
[12d15a]45/** Checks whether there are jobs in the queue at all.
46 * \return true - jobs present, false - queue is empty
47 */
48bool FragmentQueue::isJobPresent() const
49{
50 return !jobs.empty();
51}
52
[b5ebb5]53/** Pushes a FragmentJob into the internal queue for delivery to server.
54 *
55 * \note we throw assertion when jobid has already been used.
56 *
57 * \param job job to enter into queue
58 */
[78ad7d]59void FragmentQueue::pushJob(FragmentJob::ptr job)
[b5ebb5]60{
[78ad7d]61 ASSERT(job->getId() != JobId::IllegalJob,
[9875cc]62 "FragmentQueue::pushJob() - job to push has IllegalJob id.");
[78ad7d]63 ASSERT(!results.count(job->getId()),
64 "FragmentQueue::pushJob() - job id "+toString(job->getId())+" has already been used.");
65 results.insert( std::make_pair(job->getId(), NoResult));
[12d15a]66 jobs.push_back(job);
67}
68
[9875cc]69/** Pushes a bunch of FragmentJob's into the internal queue for delivery to server.
70 *
71 * \note we throw assertion when jobid has already been used.
72 *
73 * \sa pushJob()
74 *
75 * \param _jobs jobs to enter into queue
76 */
[78ad7d]77void FragmentQueue::pushJobs(std::vector<FragmentJob::ptr> &_jobs)
[9875cc]78{
[78ad7d]79 for (std::vector<FragmentJob::ptr>::iterator iter = _jobs.begin();
[9875cc]80 iter != _jobs.end(); ++iter)
81 pushJob(*iter);
82}
83
[12d15a]84/** Pops top-most FragmentJob from internal queue.
85 *
86 * From here on, we expect a result in FragmentQueue::results.
87 *
88 * \return job topmost job from queue
89 */
[78ad7d]90FragmentJob::ptr FragmentQueue::popJob()
[12d15a]91{
92 ASSERT(jobs.size(),
93 "FragmentQueue::popJob() - there are no jobs on the queue.");
[78ad7d]94 FragmentJob::ptr job = jobs.front();
95 ResultMap::iterator iter = results.find(job->getId());
[12d15a]96 ASSERT(iter != results.end(),
[78ad7d]97 "FragmentQueue::popJob() - for job "+toString(job->getId())+" no result place has been stored.");
[12d15a]98 iter->second = NoResultQueued;
99 jobs.pop_front();
100 return job;
[b5ebb5]101}
102
[b9c486]103/** Internal function to check whether result is not one of static entities.
104 *
105 * @param result result to check against
106 * @return true - result is a present, valid result, false - result is one of the statics
107 */
[35f587]108bool FragmentQueue::isPresentResult(const FragmentResult::ptr result) const
[b9c486]109{
[35f587]110 return (*result != *NoResult)
111 && (*result != *NoResultQueued)
112 && (*result != *ResultDelivered);
[b9c486]113}
114
[b5ebb5]115/** Queries whether a job has already been finished and the result is present.
116 *
117 * \param jobid id of job to query
118 * \return true - result is present, false - result is not present
119 */
120bool FragmentQueue::isResultPresent(JobId_t jobid) const
121{
122 ResultMap::const_iterator iter = results.find(jobid);
123 return ((iter != results.end())
[b9c486]124 && isPresentResult(iter->second));
[b5ebb5]125}
126
[8ee5ac]127/** Counts the number of jobs for which we have a calculated result present.
128 *
129 * \return number of calculated results
130 */
131size_t FragmentQueue::getDoneJobs() const
132{
133 size_t doneJobs = 0;
134 for (ResultMap::const_iterator iter = results.begin();
135 iter != results.end(); ++iter)
[35f587]136 if (isPresentResult(iter->second))
[8ee5ac]137 ++doneJobs;
[bf56f6]138 return doneJobs;
139}
140
141/** Counts the number of jobs for which still have to be calculated.
142 *
143 * \return number of jobs to be calculated
144 */
145size_t FragmentQueue::getPresentJobs() const
146{
147 const size_t presentJobs = jobs.size();
148 return presentJobs;
[8ee5ac]149}
150
[b5ebb5]151/** Delivers result for a finished job.
152 *
153 * \note we throw assertion if not present
154 *
155 * \param jobid id of job
156 * \return result for job of given \a jobid
157 */
[35f587]158FragmentResult::ptr FragmentQueue::getResult(JobId_t jobid)
[b5ebb5]159{
160 ResultMap::iterator iter = results.find(jobid);
161 ASSERT(iter != results.end(),
162 "FragmentQueue::pushResult() - job "+toString(jobid)+" is not known to us.");
[35f587]163 ASSERT(*iter->second != *NoResult,
[12d15a]164 "FragmentQueue::pushResult() - job "+toString(jobid)+" has not been request for calculation yet.");
[35f587]165 ASSERT(*iter->second != *NoResultQueued,
[12d15a]166 "FragmentQueue::pushResult() - job "+toString(jobid)+"'s calculation is underway but not result has arrived yet.");
[35f587]167 ASSERT(*iter->second != *ResultDelivered,
[b5ebb5]168 "FragmentQueue::pushResult() - job "+toString(jobid)+"'s result has already been delivered.");
169 /// store result
[35f587]170 FragmentResult::ptr _result = iter->second;
[b5ebb5]171 /// mark as delivered in map
172 iter->second = ResultDelivered;
173 /// and return result
[b9c486]174 return _result;
175}
176
[35f587]177std::vector<FragmentResult::ptr> FragmentQueue::getAllResults()
[b9c486]178{
[35f587]179 std::vector<FragmentResult::ptr> returnresults;
[b9c486]180 for (ResultMap::iterator iter = results.begin();
181 iter != results.end(); ++iter) {
182 if (isPresentResult(iter->second)) {
183 returnresults.push_back(getResult(iter->first));
184 iter = results.begin();
185 }
186 }
187
188 return returnresults;
[b5ebb5]189}
190
191/** Pushes a result for a finished job.
192 *
193 * \note we throw assertion if job already has result or is not known.
194 *
195 * \param result result of job to store
196 */
[35f587]197void FragmentQueue::pushResult(FragmentResult::ptr &_result)
[b5ebb5]198{
199 /// check for presence
[35f587]200 ResultMap::iterator iter = results.find(_result->getId());
[b5ebb5]201 ASSERT(iter != results.end(),
[35f587]202 "FragmentQueue::pushResult() - job "+toString(_result->getId())+" is not known to us.");
203 ASSERT(*iter->second == *NoResultQueued,
204 "FragmentQueue::pushResult() - is not waiting for the result of job "+toString(_result->getId())+".");
[b5ebb5]205 /// and overwrite NoResult in found entry
[b9c486]206 iter->second = _result;
[b5ebb5]207}
[b9c486]208
Note: See TracBrowser for help on using the repository browser.