source: ThirdParty/JobMarket/src/JobMarket/server_main.cpp@ 363f28

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 Candidate_v1.7.0 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 363f28 was 363f28, checked in by Frederik Heber <heber@…>, 9 years ago

Merge commit '404d2be35f6544290132fcbe8f79a4ff9c6584ad' as 'ThirdParty/JobMarket'

  • Property mode set to 100644
File size: 3.2 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 * \file server_main.cpp
10 *
11 * This file strongly follows the Serialization example from the boost::asio
12 * library (see server.cpp)
13 *
14 * Created on: Oct 21, 2011
15 * Author: heber
16 */
17
18// include config.h
19#ifdef HAVE_CONFIG_H
20#include <config.h>
21#endif
22
23// boost asio needs specific operator new
24#include <boost/asio.hpp>
25// program_options must have some strange static stuff, causes double free or
26// corruption if included after MemDebug
27#include <boost/program_options.hpp>
28
29#include "CodePatterns/MemDebug.hpp"
30
31#include <cstdlib>
32#include <iostream>
33#include <vector>
34
35#include "CodePatterns/Info.hpp"
36#include "CodePatterns/Log.hpp"
37#include "JobMarket/atexit.hpp"
38#include "JobMarket/FragmentScheduler.hpp"
39#include "JobMarket/Jobs/SystemCommandJob.hpp"
40#include "JobMarket/ServerOptions.hpp"
41#include "JobMarket/SignalHandler.hpp"
42
43int server_main(int argc, char* argv[])
44{
45 // from this moment on, we need to be sure to deinitialize in the correct order
46 // this is handled by the cleanup function
47 atexit(cleanUp);
48
49 ServerOptions ServerOpts;
50
51 // Declare the supported options.
52 boost::program_options::options_description desc("Allowed options");
53 desc.add_options()
54 ("help,h", "produce help message")
55 ("verbosity,v", boost::program_options::value<size_t>(), "set verbosity level")
56 ("signal", boost::program_options::value< std::vector<size_t> >(), "set signal to catch (can be given multiple times)")
57 ("workerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting workers")
58 ("controllerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting controller")
59 ("timeout", boost::program_options::value< size_t >(), "timeout in seconds for alive status of workers")
60 ;
61
62 boost::program_options::variables_map vm;
63 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
64 boost::program_options::notify(vm);
65
66 int status = 0;
67 status = ServerOpts.parseHelp(vm, desc);
68 if (status) return status;
69 status = ServerOpts.parseVerbosity(vm);
70 if (status) return status;
71 status = ServerOpts.parseWorkerPort(vm);
72 if (status) return status;
73 status = ServerOpts.parseControllerPort(vm);
74 if (status) return status;
75 status = ServerOpts.parseTimeout(vm);
76 if (status) return status;
77 status = ServerOpts.parseSignals(vm);
78 if (status) return status;
79
80 size_t Exitflag = 0;
81 try
82 {
83 boost::asio::io_service io_service;
84 FragmentScheduler Server(io_service, ServerOpts.workerport, ServerOpts.controllerport, ServerOpts.timeout);
85
86 // catch ctrl-c and shutdown worker properly
87 boost::function<void (int)> shutdownfunction = boost::bind(&FragmentScheduler::shutdown, boost::ref(Server), _1);
88 SignalHandler signalhandler(shutdownfunction, ServerOpts.signals);
89
90 {
91 Info info("io_service");
92 io_service.run();
93 }
94 Exitflag = Server.getExitflag();
95 }
96 catch (std::exception& e)
97 {
98 std::cerr << e.what() << std::endl;
99 }
100
101 return Exitflag;
102}
Note: See TracBrowser for help on using the repository browser.