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