votca 2024-dev
Loading...
Searching...
No Matches
parallelxjobcalc.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
21
22// Third party includes
23#include <boost/algorithm/string.hpp>
24#include <boost/format.hpp>
25#include <libint2/initialize.h>
26
27// Local VOTCA includes
29
30using boost::format;
31
32namespace votca {
33namespace xtp {
34
35template <typename JobContainer>
37 libint2::initialize();
38 // INITIALIZE PROGRESS OBSERVER
39 std::string progFile = jobfile_;
40 std::unique_ptr<JobOperator> master = std::unique_ptr<JobOperator>(
41 new JobOperator(-1, top, *this, openmp_threads_));
42 master->getLogger().setReportLevel(Log::current_level);
43 master->getLogger().setMultithreading(true);
44 master->getLogger().setPreface(Log::info, "\nMST INF");
45 master->getLogger().setPreface(Log::error, "\nMST ERR");
46 master->getLogger().setPreface(Log::warning, "\nMST WAR");
47 master->getLogger().setPreface(Log::debug, "\nMST DBG");
48 progObs_->InitFromProgFile(progFile, *(master.get()));
49
50 // CREATE + EXECUTE THREADS (XJOB HANDLERS)
51 std::vector<std::unique_ptr<JobOperator>> jobOps;
52
53 for (Index id = 0; id < nThreads_; id++) {
54 jobOps.push_back(std::unique_ptr<JobOperator>(
55 new JobOperator(id, top, *this, openmp_threads_)));
56 }
57
58 for (Index id = 0; id < nThreads_; ++id) {
59 CustomizeLogger(*jobOps[id]);
60 }
61
62 if (!maverick_) {
63 std::cout << std::endl; // REQUIRED FOR PROGRESS BAR IN OBSERVER
64 }
65
66 for (Index id = 0; id < nThreads_; id++) {
67 jobOps[id]->Start();
68 }
69
70 for (Index id = 0; id < nThreads_; id++) {
71 jobOps[id]->WaitDone();
72 }
73
74 if (!maverick_) {
75 for (Index id = 0; id < nThreads_; id++) {
76 std::cout << std::endl << (jobOps[id]->getLogger()) << std::flush;
77 }
78 }
79
80 jobOps.clear();
81
82 // SYNC REMAINING COMPLETE JOBS
83 progObs_->SyncWithProgFile(*(master.get()));
84 libint2::finalize();
85 return true;
86}
87
88template <typename JobContainer>
91 while (true) {
92 Job *job = master_.progObs_->RequestNextJob(*this);
93
94 if (job == nullptr) {
95 break;
96 } else {
97 Result res = this->master_.EvalJob(top_, *job, *this);
98 this->master_.progObs_->ReportJobDone(*job, res, *this);
99 }
100 }
101}
102
103template <typename JobContainer>
105 const tools::Property &options) {
106 std::cout << "\n... ... Initialized with " << nThreads_ << " threads.\n";
107
108 maverick_ = (nThreads_ == 1) ? true : false;
109
110 std::cout << "\n... ... Using " << openmp_threads_ << " openmp threads for "
111 << nThreads_ << "x" << openmp_threads_ << "="
112 << nThreads_ * openmp_threads_ << " total threads." << std::flush;
113 jobfile_ = options.get(".job_file").as<std::string>();
114 mapfile_ = options.get(".map_file").as<std::string>();
115}
116
117template <typename JobContainer>
119
120 // CONFIGURE LOGGER
121 Logger &log = thread.getLogger();
124
126 (format("\nT%1$02d INF ...") % thread.getId()).str());
128 (format("\nT%1$02d ERR ...") % thread.getId()).str());
130 (format("\nT%1$02d WAR ...") % thread.getId()).str());
132 (format("\nT%1$02d DBG ...") % thread.getId()).str());
133}
134
135// REGISTER PARALLEL CALCULATORS
137
138} // namespace xtp
139} // namespace votca
class to manage program options with xml serialization functionality
Definition property.h:55
Property & get(const std::string &key)
get existing property
Definition property.cc:79
T as() const
return value as type
Definition property.h:283
Logger is used for thread-safe output of messages.
Definition logger.h:164
void setPreface(Log::Level level, const std::string &preface)
Definition logger.h:194
void setReportLevel(Log::Level ReportLevel)
Definition logger.h:185
void setMultithreading(bool maverick)
Definition logger.h:186
ParallelXJobCalc< JobContainer > & master_
void Run() override
Run() executes the actual code.
typename JobContainer::value_type Job
void ParseCommonOptions(const tools::Property &options)
typename Job::JobResult Result
virtual void CustomizeLogger(QMThread &thread)
bool Evaluate(const Topology &top) final
Index getId() const
Definition qmthread.h:51
Logger & getLogger()
Definition qmthread.h:55
Container for segments and box and atoms.
Definition topology.h:41
void setMaxThreads(Index)
Definition eigen.h:158
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
static Level current_level
Definition globals.h:30