source: src/Fragmentation/Automation/FragmentQueue.cpp@ 8ee5ac

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 8ee5ac was 8ee5ac, checked in by Frederik Heber <heber@…>, 13 years ago

Added function getDoneJobs() to FragmentQueue.

  • this allows to check on the state of calculations.
  • Property mode set to 100644
File size: 5.0 KB
Line 
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
26FragmentResult FragmentQueue::NoResult(-1);
27FragmentResult FragmentQueue::NoResultQueued(-2);
28FragmentResult FragmentQueue::ResultDelivered(-3);
29
30/** Constructor for class FragmentQueue.
31 *
32 */
33FragmentQueue::FragmentQueue()
34{}
35
36/** Destructor for class FragmentQueue.
37 *
38 */
39FragmentQueue::~FragmentQueue()
40{}
41
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
50/** Pushes a FragmentJob into the internal queue for delivery to server.
51 *
52 * \note we throw assertion when jobid has already been used.
53 *
54 * \param job job to enter into queue
55 */
56void FragmentQueue::pushJob(FragmentJob &job)
57{
58 ASSERT(job.getId() != JobId::IllegalJob,
59 "FragmentQueue::pushJob() - job to push has IllegalJob id.");
60 ASSERT(!results.count(job.getId()),
61 "FragmentQueue::pushJob() - job id "+toString(job.getId())+" has already been used.");
62 results.insert( std::make_pair(job.getId(), NoResult));
63 jobs.push_back(job);
64}
65
66/** Pushes a bunch of FragmentJob's into the internal queue for delivery to server.
67 *
68 * \note we throw assertion when jobid has already been used.
69 *
70 * \sa pushJob()
71 *
72 * \param _jobs jobs to enter into queue
73 */
74void FragmentQueue::pushJobs(std::vector<FragmentJob> &_jobs)
75{
76 for (std::vector<FragmentJob>::iterator iter = _jobs.begin();
77 iter != _jobs.end(); ++iter)
78 pushJob(*iter);
79}
80
81/** Pops top-most FragmentJob from internal queue.
82 *
83 * From here on, we expect a result in FragmentQueue::results.
84 *
85 * \return job topmost job from queue
86 */
87FragmentJob FragmentQueue::popJob()
88{
89 ASSERT(jobs.size(),
90 "FragmentQueue::popJob() - there are no jobs on the queue.");
91 FragmentJob job = jobs.front();
92 ResultMap::iterator iter = results.find(job.getId());
93 ASSERT(iter != results.end(),
94 "FragmentQueue::popJob() - for job "+toString(job.getId())+" no result place has been stored.");
95 iter->second = NoResultQueued;
96 jobs.pop_front();
97 return job;
98}
99
100/** Queries whether a job has already been finished and the result is present.
101 *
102 * \param jobid id of job to query
103 * \return true - result is present, false - result is not present
104 */
105bool FragmentQueue::isResultPresent(JobId_t jobid) const
106{
107 ResultMap::const_iterator iter = results.find(jobid);
108 return ((iter != results.end())
109 && (iter->second != NoResult)
110 && (iter->second != NoResultQueued)
111 && (iter->second != ResultDelivered));
112}
113
114/** Counts the number of jobs for which we have a calculated result present.
115 *
116 * \return number of calculated results
117 */
118size_t FragmentQueue::getDoneJobs() const
119{
120 size_t doneJobs = 0;
121 for (ResultMap::const_iterator iter = results.begin();
122 iter != results.end(); ++iter)
123 if ((iter->second != NoResult)
124 && (iter->second != NoResultQueued)
125 && (iter->second != ResultDelivered))
126 ++doneJobs;
127 return doneJobs;
128}
129
130/** Delivers result for a finished job.
131 *
132 * \note we throw assertion if not present
133 *
134 * \param jobid id of job
135 * \return result for job of given \a jobid
136 */
137FragmentResult FragmentQueue::getResult(JobId_t jobid)
138{
139 ResultMap::iterator iter = results.find(jobid);
140 ASSERT(iter != results.end(),
141 "FragmentQueue::pushResult() - job "+toString(jobid)+" is not known to us.");
142 ASSERT(iter->second != NoResult,
143 "FragmentQueue::pushResult() - job "+toString(jobid)+" has not been request for calculation yet.");
144 ASSERT(iter->second != NoResultQueued,
145 "FragmentQueue::pushResult() - job "+toString(jobid)+"'s calculation is underway but not result has arrived yet.");
146 ASSERT(iter->second != ResultDelivered,
147 "FragmentQueue::pushResult() - job "+toString(jobid)+"'s result has already been delivered.");
148 /// store result
149 FragmentResult result = iter->second;
150 /// mark as delivered in map
151 iter->second = ResultDelivered;
152 /// and return result
153 return result;
154}
155
156/** Pushes a result for a finished job.
157 *
158 * \note we throw assertion if job already has result or is not known.
159 *
160 * \param result result of job to store
161 */
162void FragmentQueue::pushResult(FragmentResult &result)
163{
164 /// check for presence
165 ResultMap::iterator iter = results.find(result.getId());
166 ASSERT(iter != results.end(),
167 "FragmentQueue::pushResult() - job "+toString(result.getId())+" is not known to us.");
168 ASSERT(iter->second == NoResultQueued,
169 "FragmentQueue::pushResult() - is not waiting for the result of job "+toString(result.getId())+".");
170 /// and overwrite NoResult in found entry
171 iter->second = result;
172}
Note: See TracBrowser for help on using the repository browser.