votca 2026-dev
Loading...
Searching...
No Matches
xtp_parallel.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2023 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 */
19
20// Local VOTCA includes
26
27using namespace votca;
28
29class XtpParallel final : public xtp::StateApplication {
30 public:
31 XtpParallel() = default;
32 ~XtpParallel() = default;
33 std::string ProgramName() final { return "xtp_parallel"; }
34
35 void HelpText(std::ostream& out) final {
36 out << "Runs job-based heavy-duty calculators\n";
37 }
38
39 protected:
40 void CreateCalculator(const std::string& name);
41 void ConfigCalculator();
42 bool savetoStateFile() const final { return import_; }
43
44 bool EvaluateFrame(votca::xtp::Topology& top) final;
45 std::string CalculatorType() const { return "Calculator"; }
46 void CheckOptions() final;
47 std::vector<std::string> CalculatorNames() const {
49 }
50
51 void AddCommandLineOpt() final;
52
53 private:
54 bool generate_input_ = false;
55 bool run_ = false;
56 bool import_ = false;
57 xtp::ProgObserver<std::vector<xtp::Job>> progObs_;
58 std::unique_ptr<xtp::JobCalculator> calc_ = nullptr;
59};
60
62 namespace propt = boost::program_options;
63 AddProgramOptions()("ompthreads,x", propt::value<Index>()->default_value(1),
64 " number of openmp threads to create in each thread");
65 AddProgramOptions()("restart,r",
66 propt::value<std::string>()->default_value(""),
67 " restart pattern: 'host(pc1:234) stat(FAILED)'");
68 AddProgramOptions()("cache,q", propt::value<Index>()->default_value(8),
69 " assigns jobs in blocks of this size");
70 AddProgramOptions()("jobs,j",
71 propt::value<std::string>()->default_value("run"),
72 " task(s) to perform: write, run, read");
73 AddProgramOptions()("maxjobs,m", propt::value<Index>()->default_value(-1),
74 " maximum number of jobs to process (-1 = inf)");
75}
76
78 std::string jobstr = OptionsMap()["jobs"].as<std::string>();
79 generate_input_ = (jobstr == "write");
80 run_ = (jobstr == "run");
81 import_ = (jobstr == "read");
82}
83
84void XtpParallel::CreateCalculator(const std::string& name) {
86}
87
89 std::cout << "... " << calc_->Identify() << std::endl;
90
91 progObs_.InitCmdLineOpts(OptionsMap());
92 calc_->setnThreads(OptionsMap()["nthreads"].as<Index>());
93 // nthreads jobs run concurrently and share the memory budget
94 xtp::MemoryBudget::SetConcurrentJobs(OptionsMap()["nthreads"].as<Index>());
95 calc_->setOpenMPThreads(OptionsMap()["ompthreads"].as<Index>());
96 calc_->setProgObserver(&progObs_);
97 calc_->Initialize(options_);
98 std::cout << std::endl;
99}
100
102 std::cout << "... " << calc_->Identify() << " " << std::flush;
103 if (generate_input_) {
104 calc_->WriteJobFile(top);
105 } else if (run_) {
106 calc_->EvaluateFrame(top);
107 } else if (import_) {
108 calc_->ReadJobFile(top);
109 }
110 std::cout << std::endl;
111 return true;
112}
113
114int main(int argc, char** argv) {
115
116 XtpParallel xtprun;
117 return xtprun.Exec(argc, argv);
118}
xtp::ProgObserver< std::vector< xtp::Job > > progObs_
void AddCommandLineOpt() final
bool EvaluateFrame(votca::xtp::Topology &top) final
std::vector< std::string > CalculatorNames() const
~XtpParallel()=default
std::string ProgramName() final
program name
XtpParallel()=default
std::string CalculatorType() const
std::unique_ptr< xtp::JobCalculator > calc_
void CheckOptions() final
void CreateCalculator(const std::string &name)
void HelpText(std::ostream &out) final
help text of application without version information
bool savetoStateFile() const final
bool generate_input_
void ConfigCalculator()
int Exec(int argc, char **argv)
executes the program
boost::program_options::variables_map & OptionsMap()
get available program options & descriptions
boost::program_options::options_description_easy_init AddProgramOptions(const std::string &group="")
add option for command line
virtual std::unique_ptr< T > Create(const key_t &key, args_t &&...arguments)
std::vector< key_t > getKeys() const
static void SetConcurrentJobs(Index concurrent_jobs)
Container for segments and box and atoms.
Definition topology.h:41
votca::tools::Property options_
STL namespace.
Charge transport classes.
Definition ERIs.h:28
Provides a means for comparing floating point numbers.
Definition basebead.h:33
int main(int argc, char **argv)