votca 2024.2-dev
Loading...
Searching...
No Matches
csgapplication.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2021 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18#ifndef VOTCA_CSG_CSGAPPLICATION_H
19#define VOTCA_CSG_CSGAPPLICATION_H
20
21// VOTCA includes
22#include <memory>
24#include <votca/tools/mutex.h>
25#include <votca/tools/thread.h>
26
27// Local VOTCA includes
28#include "cgobserver.h"
29#include "topology.h"
30#include "topologymap.h"
31#include "trajectoryreader.h"
32
33namespace votca {
34namespace csg {
35
37 public:
38 CsgApplication() = default;
39 ~CsgApplication() override = default;
40
41 void Initialize() override;
42 bool EvaluateOptions() override;
43
44 void Run(void) override;
45
46 void ShowHelpText(std::ostream &out) override;
47
49
50 virtual bool DoMapping(void) { return false; }
52
53 virtual bool DoMappingDefault(void) { return true; }
55
56 virtual bool DoTrajectory(void) { return false; }
57
58 /* \brief overload and return true to enable threaded calculations */
59 virtual bool DoThreaded(void) { return false; }
60
61 /* \brief overload and return false to disable synchronized (while threaded)
62 * calculations */
63 virtual bool SynchronizeThreads(void) {
64 if (DoThreaded()) {
65 return true;
66 } else {
67 return false;
68 }
69 }
70
72 virtual bool NeedsTopology(void) { return true; }
73
75
76 virtual bool EvaluateTopology(Topology *, Topology * = nullptr) {
77 return true;
78 }
79
80 void AddObserver(CGObserver *observer);
81
83 virtual void BeginEvaluate(Topology *top, Topology *top_ref = nullptr);
85 virtual void EndEvaluate();
86 // \brief called for each frame which is mapped
87 virtual void EvalConfiguration(Topology *top, Topology *top_ref = nullptr);
88
89 // thread related stuff follows
90
105 class Worker : public tools::Thread {
106 public:
107 Worker() = default;
108
110 virtual void EvalConfiguration(Topology *top,
111 Topology *top_ref = nullptr) = 0;
112
114 Index getId() { return id_; }
115
116 protected:
119 std::unique_ptr<TopologyMap> map_;
120 Index id_ = -1;
121
122 void Run(void) override;
123
124 void setApplication(CsgApplication *app) { app_ = app; }
125
126 void setId(Index id) { id_ = id; }
127
128 friend class CsgApplication;
129 };
130
138 bool ProcessData(Worker *worker);
139
145 virtual std::unique_ptr<Worker> ForkWorker(void);
146
151 virtual void MergeWorker(Worker *worker);
152
153 protected:
154 std::list<CGObserver *> observers_;
156 std::vector<std::unique_ptr<Worker>> myWorkers_;
162
164 std::vector<std::unique_ptr<tools::Mutex>> threadsMutexesIn_;
166 std::vector<std::unique_ptr<tools::Mutex>> threadsMutexesOut_;
167 std::unique_ptr<TrajectoryReader> traj_reader_;
168};
169
171 observers_.push_back(observer);
172}
173
174} // namespace csg
175} // namespace votca
176
177#endif // VOTCA_CSG_CSGAPPLICATION_H
Observer class for analysis hook.
Definition cgobserver.h:36
Worker, derived from Thread, does the work.
virtual void EvalConfiguration(Topology *top, Topology *top_ref=nullptr)=0
overload with the actual computation
std::unique_ptr< TopologyMap > map_
Index getId()
returns worker id
void Run(void) override
Run() executes the actual code.
void setApplication(CsgApplication *app)
virtual bool DoMapping(void)
overload and return true to enable mapping command line options
virtual bool EvaluateTopology(Topology *, Topology *=nullptr)
called after topology was loaded
std::vector< std::unique_ptr< tools::Mutex > > threadsMutexesIn_
stores Mutexes used to impose order for input
void ShowHelpText(std::ostream &out) override
bool EvaluateOptions() override
Process command line options.
virtual bool SynchronizeThreads(void)
virtual void EndEvaluate()
called after the last frame
~CsgApplication() override=default
void Initialize() override
Initialize application data.
void AddObserver(CGObserver *observer)
std::list< CGObserver * > observers_
virtual void MergeWorker(Worker *worker)
virtual void BeginEvaluate(Topology *top, Topology *top_ref=nullptr)
called before the first frame
virtual bool DoMappingDefault(void)
if DoMapping is true, will by default require mapping or not
virtual bool DoTrajectory(void)
overload and return true to enable trajectory command line options
bool ProcessData(Worker *worker)
Gets frames from TrajectoryReader in an ordered way and, if successful, calls Worker::EvalConfigurati...
virtual bool NeedsTopology(void)
if topology is always needed
virtual std::unique_ptr< Worker > ForkWorker(void)
virtual void EvalConfiguration(Topology *top, Topology *top_ref=nullptr)
std::vector< std::unique_ptr< tools::Mutex > > threadsMutexesOut_
stores Mutexes used to impose order for output
std::vector< std::unique_ptr< Worker > > myWorkers_
std::unique_ptr< TrajectoryReader > traj_reader_
void Run(void) override
Main body of application.
virtual bool DoThreaded(void)
topology of the whole system
Definition topology.h:81
Framework for threaded execution.
Definition thread.h:35
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26