votca 2024.2-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
25
26using namespace votca;
27
28class XtpParallel final : public xtp::StateApplication {
29 public:
30 XtpParallel() = default;
31 ~XtpParallel() = default;
32 std::string ProgramName() final { return "xtp_parallel"; }
33
34 void HelpText(std::ostream& out) final {
35 out << "Runs job-based heavy-duty calculators\n";
36 }
37
38 protected:
39 void CreateCalculator(const std::string& name);
40 void ConfigCalculator();
41 bool savetoStateFile() const final { return import_; }
42
43 bool EvaluateFrame(votca::xtp::Topology& top) final;
44 std::string CalculatorType() const { return "Calculator"; }
45 void CheckOptions() final;
46 std::vector<std::string> CalculatorNames() const {
48 }
49
50 void AddCommandLineOpt() final;
51
52 private:
53 bool generate_input_ = false;
54 bool run_ = false;
55 bool import_ = false;
56 xtp::ProgObserver<std::vector<xtp::Job>> progObs_;
57 std::unique_ptr<xtp::JobCalculator> calc_ = nullptr;
58};
59
61 namespace propt = boost::program_options;
62 AddProgramOptions()("ompthreads,x", propt::value<Index>()->default_value(1),
63 " number of openmp threads to create in each thread");
64 AddProgramOptions()("restart,r",
65 propt::value<std::string>()->default_value(""),
66 " restart pattern: 'host(pc1:234) stat(FAILED)'");
67 AddProgramOptions()("cache,q", propt::value<Index>()->default_value(8),
68 " assigns jobs in blocks of this size");
69 AddProgramOptions()("jobs,j",
70 propt::value<std::string>()->default_value("run"),
71 " task(s) to perform: write, run, read");
72 AddProgramOptions()("maxjobs,m", propt::value<Index>()->default_value(-1),
73 " maximum number of jobs to process (-1 = inf)");
74}
75
77 std::string jobstr = OptionsMap()["jobs"].as<std::string>();
78 generate_input_ = (jobstr == "write");
79 run_ = (jobstr == "run");
80 import_ = (jobstr == "read");
81}
82
83void XtpParallel::CreateCalculator(const std::string& name) {
85}
86
88 std::cout << "... " << calc_->Identify() << std::endl;
89
91 calc_->setnThreads(OptionsMap()["nthreads"].as<Index>());
92 calc_->setOpenMPThreads(OptionsMap()["ompthreads"].as<Index>());
95 std::cout << std::endl;
96}
97
99 std::cout << "... " << calc_->Identify() << " " << std::flush;
100 if (generate_input_) {
101 calc_->WriteJobFile(top);
102 } else if (run_) {
103 calc_->EvaluateFrame(top);
104 } else if (import_) {
105 calc_->ReadJobFile(top);
106 }
107 std::cout << std::endl;
108 return true;
109}
110
111int main(int argc, char** argv) {
112
113 XtpParallel xtprun;
114 return xtprun.Exec(argc, argv);
115}
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
void setnThreads(Index nThreads)
Sets number of threads to use.
Definition calculator.h:83
virtual std::unique_ptr< T > Create(const key_t &key, args_t &&...arguments)
std::vector< key_t > getKeys() const
virtual void WriteJobFile(const Topology &top)=0
bool EvaluateFrame(const Topology &top)
std::string Identify() const override=0
Calculator name.
void setProgObserver(ProgObserver< std::vector< Job > > *obs)
void Initialize(const tools::Property &opt) final
Initializes a calculator from an XML file with options.
virtual void ReadJobFile(Topology &top)=0
void setOpenMPThreads(Index ompthreads)
void InitCmdLineOpts(const boost::program_options::variables_map &optsMap)
Container for segments and box and atoms.
Definition topology.h:41
votca::tools::Property options_
STL namespace.
base class for all analysis tools
Definition basebead.h:33
int main(int argc, char **argv)