source: src/JobMarket/Operations/Controllers/CheckResultsOperation.cpp@ 404d2b

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_JobMarket Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 404d2b was 404d2b, checked in by Frederik Heber <heber@…>, 8 years ago

Squashed 'ThirdParty/JobMarket/' content from commit e194722

git-subtree-dir: ThirdParty/JobMarket
git-subtree-split: e19472277e62c493f6c10f1483fe21e64c1039e9

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Project: JobMarket
3 * Description: asynchronous Server/Controller/Client-approach to parallel computing, based on boost::asio
4 * Copyright (C) 2011-2012 Frederik Heber. All rights reserved.
5 *
6 */
7
8/*
9 * CheckResultsOperation.cpp
10 *
11 * Created on: Dec 11, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20// boost asio needs specific operator new
21#include <boost/asio.hpp>
22
23#include "CodePatterns/MemDebug.hpp"
24
25#include "JobMarket/Operations/Controllers/CheckResultsOperation.hpp"
26
27#include <boost/bind.hpp>
28#include <iostream>
29#include "JobMarket/Connection.hpp" // Must come before boost/serialization headers.
30#include <boost/serialization/set.hpp>
31#include <boost/serialization/vector.hpp>
32#include "CodePatterns/Info.hpp"
33#include "CodePatterns/Log.hpp"
34#include "JobMarket/ControllerChoices.hpp"
35
36// static entities
37const std::set<JobId_t> CheckResultsOperation::emptyids;
38
39/** Handle connect operation to send number of done jobs.
40 *
41 * \param e error code if something went wrong
42 * \param endpoint_iterator endpoint of the connection
43 */
44void CheckResultsOperation::handle_connect(const boost::system::error_code& e,
45 boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
46{
47 DEBUG_FUNCTION_ENTRYEXIT
48 if (!e)
49 {
50 // Successfully established connection. Give choice.
51 enum ControllerChoices choice = CheckState;
52 connection_.async_write(choice,
53 boost::bind(&CheckResultsOperation::handle_SendJobIds, this,
54 boost::asio::placeholders::error));
55 } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {
56 // Try the next endpoint.
57 connection_.socket().close();
58 boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
59 connection_.socket().async_connect(endpoint,
60 boost::bind(&CheckResultsOperation::handle_connect, this,
61 boost::asio::placeholders::error, ++endpoint_iterator));
62 } else {
63 // An error occurred. Log it and return. Since we are not starting a new
64 // operation the io_service will run out of work to do and the client will
65 // exit.
66 ELOG(1, e.message());
67 AsyncOperation::handle_FinishOperation(e);
68 }
69}
70
71/** Callback function when doneJobs have been received.
72 *
73 * \param e error code if something went wrong
74 */
75void CheckResultsOperation::handle_SendJobIds(const boost::system::error_code& e)
76{
77 DEBUG_FUNCTION_ENTRYEXIT
78 if (!e)
79 {
80 // The connection::async_write() function will automatically
81 // decode the data that is written to the underlying socket.
82 LOG(1, "INFO: Sending vector of desired " << jobids.size() << " jobids ...");
83 connection_.async_write(jobids,
84 boost::bind(&CheckResultsOperation::handle_ReceiveJobInfo, this,
85 boost::asio::placeholders::error));
86 }
87 else
88 {
89 // An error occurred.
90 ELOG(1, e.message());
91 AsyncOperation::handle_FinishOperation(e);
92 }
93}
94
95/** Callback function when doneJobs have been received.
96 *
97 * \param e error code if something went wrong
98 */
99void CheckResultsOperation::handle_ReceiveJobInfo(const boost::system::error_code& e)
100{
101 DEBUG_FUNCTION_ENTRYEXIT
102 if (!e)
103 {
104 // The connection::async_read() function will automatically
105 // decode the data that is written to the underlying socket.
106 LOG(1, "INFO: Obtaining number of present and done jobs ...");
107 connection_.async_read(jobInfo,
108 boost::bind(&CheckResultsOperation::handle_FinishOperation, this,
109 boost::asio::placeholders::error));
110 }
111 else
112 {
113 // An error occurred.
114 ELOG(1, e.message());
115 AsyncOperation::handle_FinishOperation(e);
116 }
117}
118
119/** Getter for jobInfo.
120 *
121 * \sa checkResults()
122 * \param number of present jobs
123 */
124size_t CheckResultsOperation::getPresentJobs() const
125{
126 ASSERT( jobInfo.size() == (size_t)2,
127 "CheckResultsOperation::getPresentJobs() - jobInfo does not contain present and done jobs.");
128 return jobInfo[0];
129}
130
131/** Getter for jobInfo.
132 *
133 * \sa checkResults()
134 * \param number of done jobs
135 */
136size_t CheckResultsOperation::getDoneJobs() const
137{
138 ASSERT( jobInfo.size() == (size_t)2,
139 "CheckResultsOperation::getPresentJobs() - jobInfo does not contain present and done jobs.");
140 return jobInfo[1];
141}
142
Note: See TracBrowser for help on using the repository browser.