View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

reader.h
Go to the documentation of this file.
1#ifndef VISTLE_READER_H
2#define VISTLE_READER_H
3
4#include "module.h"
5#include <set>
6#include <future>
7
8namespace vistle {
9
22class V_MODULEEXPORT Reader: public Module {
23 friend class Token;
24
25public:
26 class V_MODULEEXPORT Token {
27 friend class vistle::Reader;
28 friend V_MODULEEXPORT std::ostream &operator<<(std::ostream &os, const Token &tok);
29
30 public:
32 Token(Reader *reader, std::shared_ptr<Token> previous);
33 Reader *reader() const;
34 const Meta &meta() const;
35 bool wait(const std::string &port = std::string());
36 bool addObject(const std::string &port, Object::ptr obj);
37 bool addObject(Port *port, Object::ptr obj);
38 void applyMeta(vistle::Object::ptr obj) const;
39 unsigned long id() const;
40
41 private:
42 bool result();
43 bool waitDone();
44 bool waitPortReady(const std::string &port);
45 void setPortReady(const std::string &port, bool ready);
46
47 Reader *m_reader = nullptr;
48 Meta m_meta;
49 std::mutex m_mutex;
50 bool m_finished = false;
51 bool m_result = false;
52 std::shared_ptr<Token> m_previous;
53 std::shared_future<bool> m_future;
54 unsigned long m_id = 0;
55
56 struct PortState {
57 PortState(): future(promise.get_future().share()) {}
58 bool valid = false;
59 std::promise<bool> promise;
60 std::shared_future<bool> future;
61 bool ready = false;
62 };
63 std::map<std::string, std::shared_ptr<PortState>> m_ports;
64 };
65
67
72 Reader(const std::string &name, const int moduleID, mpi::communicator comm);
73 ~Reader() override;
75
80 virtual bool examine(const Parameter *param = nullptr);
81
83
86 virtual bool read(Token &token, int timestep = -1, int block = -1) = 0;
88 virtual bool prepareRead();
90 virtual bool finishRead();
91
93 int timeIncrement() const;
95 virtual int rankForTimestepAndPartition(int t, int p) const;
96
98 int numPartitions() const;
99
100protected:
101protected:
107 };
108
110 void setParallelizationMode(ParallelizationMode mode);
112 void setHandlePartitions(bool enable);
114 void setAllowTimestepDistribution(bool allow);
115
117 void observeParameter(const Parameter *param);
119 void setTimesteps(int number);
121 void setPartitions(int number);
122
123 bool changeParameters(std::set<const Parameter *> params) override;
124 bool changeParameter(const Parameter *param) override;
125 void prepareQuit() override;
126
127 bool checkConvexity() const;
128
129 IntParameter *m_first = nullptr;
130 IntParameter *m_last = nullptr;
131 IntParameter *m_increment = nullptr;
132 IntParameter *m_distributeTime = nullptr;
133 IntParameter *m_firstRank = nullptr;
134 IntParameter *m_checkConvexity = nullptr;
135
136private:
137 bool prepare() override;
138 bool compute() override;
139
140 ParallelizationMode m_parallel = Serial;
141 std::mutex m_mutex; // protect ports and message queues
142 std::deque<std::shared_ptr<Token>> m_tokens;
143 size_t waitForReaders(size_t maxRunning, bool &result);
144
145 std::set<const Parameter *> m_observedParameters;
146
147 int m_numTimesteps = 0;
148 int m_numPartitions = 0;
149 bool m_readyForRead = true;
150
151 bool m_handlePartitions = true;
152 bool m_allowTimestepDistribution = false;
153
154 unsigned long m_tokenCount = 0;
155
156 /*
157 * # files (api)
158 * file selection (ui)
159 * # data ports/fields (api)
160 * field -> port mapping (ui)
161 * bool: directory/file (api)
162 * timestep control (ui)
163 * distribution over ranks (ui)
164 * ? bool: can reorder (api)
165 * ? extensions? (api)
166 * ? bool: field name from file (api)
167 * ? bool: create ghostcells (ui)
168 */
169};
170
171V_MODULEEXPORT std::ostream &operator<<(std::ostream &os, const Reader::Token &tok);
172} // namespace vistle
173#endif
Definition: objectmeta.h:16
Definition: module.h:116
const int m_id
Definition: module.h:260
int id() const
Definition: module.cpp:330
bool addObject(Port *port, vistle::Object::ptr object)
Definition: module.cpp:775
std::shared_ptr< Object > ptr
Definition: object.h:67
Definition: parameter.h:26
Definition: port.h:29
Definition: reader.h:26
base class for Vistle read modules
Definition: reader.h:22
friend class Token
Definition: reader.h:23
ParallelizationMode
Definition: reader.h:102
@ Serial
only one operation at a time, all blocks of a timestep first, then other timesteps
Definition: reader.h:103
@ ParallelizeBlocks
up to 'concurrency' operations at a time, all operations for one timestep have finished before operat...
Definition: reader.h:106
@ ParallelizeTimesteps
up to 'concurrency' operations at a time, but the same block from different timesteps may be schedule...
Definition: reader.h:104
@ ParallelizeTimeAndBlocks
up to 'concurrency' operations at a time
Definition: reader.h:105
virtual bool read(Token &token, int timestep=-1, int block=-1)=0
called for every unit of work to be read
std::string share(const std::string &prefix)
Definition: directory.cpp:74
Definition: allobjects.cpp:30
std::ostream & operator<<(std::ostream &out, const Meta &meta)
Definition: objectmeta.cpp:45