AQUAgpusph 4.1.2
Loading...
Searching...
No Matches
Tool.h
Go to the documentation of this file.
1/*
2 * This file is part of AQUAgpusph, a free CFD program based on SPH.
3 * Copyright (C) 2012 Jose Luis Cercos Pita <jl.cercos@upm.es>
4 *
5 * AQUAgpusph is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * AQUAgpusph is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with AQUAgpusph. If not, see <http://www.gnu.org/licenses/>.
17 */
18
25#ifndef TOOL_H_INCLUDED
26#define TOOL_H_INCLUDED
27
28#include <sphPrerequisites.h>
29#include <Variable.h>
30#include <math.h>
31#include <vector>
32
33namespace Aqua {
34namespace CalcServer {
35
45class Tool
46{
47 public:
52 Tool(const std::string tool_name, bool once = false);
53
56 virtual ~Tool();
57
61 void name(const std::string tool_name) { _name = tool_name; };
62
66 const std::string name() { return _name; }
67
70 virtual void setup();
71
83 virtual void execute();
84
92 virtual Tool* next_tool() { return _next_tool; }
93
97 size_t allocatedMemory() const { return _allocated_memory; }
98
102 unsigned int used_times() const { return _n_iters; }
103
109 float elapsedTime(bool averaged = true) const
110 {
111 if (!averaged)
112 return _elapsed_time;
113 return _average_elapsed_time;
114 }
115
120 {
121 return _squared_elapsed_time - pow(_average_elapsed_time, 2);
122 }
123
127 float elapsedTimeDeviation() const { return sqrt(elapsedTimeVariance()); }
128
139 virtual const int scope_modifier() { return 0; }
140
141 protected:
145 int id_in_pipeline();
146
151 void next_tool(Tool* tool) { _next_tool = tool; }
152
156 void allocatedMemory(size_t mem_size) { _allocated_memory = mem_size; }
157
162 virtual cl_event _execute(const std::vector<cl_event> events)
163 {
164 return NULL;
165 }
166
170 void addElapsedTime(float elapsed_time);
171
179 void setDependencies(std::vector<std::string> var_names);
180
188 void setDependencies(std::vector<InputOutput::Variable*> vars);
189
194 const std::vector<InputOutput::Variable*> getDependencies();
195
212 static std::vector<cl_kernel> compile(const std::string source,
213 const std::vector<std::string> names,
214 const std::string flags = "");
215
232 static cl_kernel compile_kernel(const std::string source,
233 const std::string kernel_name,
234 const std::string flags = "");
235
236 private:
243 const std::vector<cl_event> getEvents();
244
246 std::string _name;
247
249 bool _once;
250
252 Tool* _next_tool;
253
255 size_t _allocated_memory;
256
258 unsigned int _n_iters;
259
261 float _elapsed_time;
262
264 float _average_elapsed_time;
265
267 float _squared_elapsed_time;
268
270 std::vector<InputOutput::Variable*> _vars;
271
273 std::vector<cl_event> _events;
274};
275
276}
277} // namespace
278
279#endif // TOOL_H_INCLUDED
Virtual variables environment to allow the user define/manipulate the variables used in the simulatio...
Tools base class. The way that AQUAgpusph compute each problem is set through a set of tools that are...
Definition: Tool.h:46
int id_in_pipeline()
Definition: Tool.cpp:155
virtual void execute()
Execute the tool measuring the elapsed time.
Definition: Tool.cpp:65
virtual Tool * next_tool()
Definition: Tool.h:92
float elapsedTimeDeviation() const
Definition: Tool.h:127
size_t allocatedMemory() const
Definition: Tool.h:97
void allocatedMemory(size_t mem_size)
Definition: Tool.h:156
float elapsedTime(bool averaged=true) const
Definition: Tool.h:109
void name(const std::string tool_name)
Definition: Tool.h:61
void setDependencies(std::vector< std::string > var_names)
Set the depedencies of the tool.
Definition: Tool.cpp:181
static std::vector< cl_kernel > compile(const std::string source, const std::vector< std::string > names, const std::string flags="")
Compile an OpenCL source code and generate the corresponding kernel.
Definition: Tool.cpp:212
void addElapsedTime(float elapsed_time)
Add new data to the average and squared elapsed times.
Definition: Tool.cpp:165
virtual cl_event _execute(const std::vector< cl_event > events)
Definition: Tool.h:162
void next_tool(Tool *tool)
Definition: Tool.h:151
float elapsedTimeVariance() const
Definition: Tool.h:119
const std::string name()
Definition: Tool.h:66
const std::vector< InputOutput::Variable * > getDependencies()
Get the depedencies of the tool.
Definition: Tool.cpp:206
static cl_kernel compile_kernel(const std::string source, const std::string kernel_name, const std::string flags="")
Compile an OpenCL source code and generate the corresponding kernel.
Definition: Tool.cpp:297
virtual const int scope_modifier()
Definition: Tool.h:139
unsigned int used_times() const
Definition: Tool.h:102
virtual ~Tool()
Definition: Tool.cpp:47
virtual void setup()
Definition: Tool.cpp:50
Main AQUAgpusph namespace.
Definition: ArgumentsManager.cpp:45
Set of definitions and macros related with the implementation.