votca 2024.2-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
26#include "xtp_libint2.h"
27
28// Local VOTCA includes
30
31using boost::format;
32
33namespace votca {
34namespace xtp {
35
36template <typename JobContainer>
38 libint2::initialize();
39 // INITIALIZE PROGRESS OBSERVER
40 std::string progFile = jobfile_;
41 std::unique_ptr<JobOperator> master = std::unique_ptr<JobOperator>(
42 new JobOperator(-1, top, *this, openmp_threads_));
43 master->getLogger().setReportLevel(Log::current_level);
44 master->getLogger().setMultithreading(true);
45 master->getLogger().setPreface(Log::info, "\nMST INF");
46 master->getLogger().setPreface(Log::error, "\nMST ERR");
47 master->getLogger().setPreface(Log::warning, "\nMST WAR");
48 master->getLogger().setPreface(Log::debug, "\nMST DBG");
49 progObs_->InitFromProgFile(progFile, *(master.get()));
50
51 // CREATE + EXECUTE THREADS (XJOB HANDLERS)
52 std::vector<std::unique_ptr<JobOperator>> jobOps;
53
54 for (Index id = 0; id < nThreads_; id++) {
55 jobOps.push_back(std::unique_ptr<JobOperator>(
56 new JobOperator(id, top, *this, openmp_threads_)));
57 }
58
59 for (Index id = 0; id < nThreads_; ++id) {
60 CustomizeLogger(*jobOps[id]);
61 }
62
63 if (!maverick_) {
64 std::cout << std::endl; // REQUIRED FOR PROGRESS BAR IN OBSERVER
65 }
66
67 for (Index id = 0; id < nThreads_; id++) {
68 jobOps[id]->Start();
69 }
70
71 for (Index id = 0; id < nThreads_; id++) {
72 jobOps[id]->WaitDone();
73 }
74
75 if (!maverick_) {
76 for (Index id = 0; id < nThreads_; id++) {
77 std::cout << std::endl << (jobOps[id]->getLogger()) << std::flush;
78 }
79 }
80
81 jobOps.clear();
82
83 // SYNC REMAINING COMPLETE JOBS
84 progObs_->SyncWithProgFile(*(master.get()));
85 libint2::finalize();
86 return true;
87}
88
89template <typename JobContainer>
92 while (true) {
93 Job *job = master_.progObs_->RequestNextJob(*this);
94
95 if (job == nullptr) {
96 break;
97 } else {
98 Result res = this->master_.EvalJob(top_, *job, *this);
99 this->master_.progObs_->ReportJobDone(*job, res, *this);
100 }
101 }
102}
103
104template <typename JobContainer>
106 const tools::Property &options) {
107 std::cout << "\n... ... Initialized with " << nThreads_ << " threads.\n";
108
109 maverick_ = (nThreads_ == 1) ? true : false;
110
111 std::cout << "\n... ... Using " << openmp_threads_ << " openmp threads for "
112 << nThreads_ << "x" << openmp_threads_ << "="
113 << nThreads_ * openmp_threads_ << " total threads." << std::flush;
114 jobfile_ = options.get(".job_file").as<std::string>();
115 mapfile_ = options.get(".map_file").as<std::string>();
116}
117
118template <typename JobContainer>
120
121 // CONFIGURE LOGGER
122 Logger &log = thread.getLogger();
125
127 (format("\nT%1$02d INF ...") % thread.getId()).str());
129 (format("\nT%1$02d ERR ...") % thread.getId()).str());
131 (format("\nT%1$02d WAR ...") % thread.getId()).str());
133 (format("\nT%1$02d DBG ...") % thread.getId()).str());
134}
135
136// REGISTER PARALLEL CALCULATORS
138
139} // namespace xtp
140} // 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
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