AQUAgpusph 4.1.2
Loading...
Searching...
No Matches
sphPrerequisites.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
23#ifndef SPHPREREQUISITES_H_INCLUDED
24#define SPHPREREQUISITES_H_INCLUDED
25
29#define XSTR(x) STR(x)
39#define STR(x) #x
40
41#include <string>
42
43// CMake configuration file
44#include <config.h>
45
46#if __APPLE__
47#include <OpenCL/cl.h>
48#else
49#include <CL/cl.h>
50#endif
51
52// Assume the 3D version if 2D has not been set
53#if !defined(HAVE_2D) && !defined(HAVE_3D)
60#define HAVE_3D
61#endif
62
63#ifndef vec2
67#define vec2 cl_float2
68#endif
69#ifndef vec3
73#define vec3 cl_float3
74#endif
75#ifndef vec4
79#define vec4 cl_float4
80#endif
81
82#ifndef ivec2
86#define ivec2 cl_int2
87#endif
88#ifndef ivec3
92#define ivec3 cl_int3
93#endif
94#ifndef ivec4
98#define ivec4 cl_int4
99#endif
100
101#ifndef uivec2
105#define uivec2 cl_uint2
106#endif
107#ifndef uivec3
111#define uivec3 cl_uint3
112#endif
113#ifndef uivec4
117#define uivec4 cl_uint4
118#endif
119
120#ifdef HAVE_3D
121#ifndef vec
130#define vec vec4
131#endif
132#ifndef ivec
141#define ivec ivec4
142#endif
143#ifndef uivec
152#define uivec uivec4
153#endif
154#ifndef matrix
163#define matrix cl_float16
164#endif
165#else
166#ifndef vec
167#define vec vec2
168#endif
169#ifndef ivec
170#define ivec ivec2
171#endif
172#ifndef uivec
173#define uivec uivec2
174#endif
175#ifndef matrix
176#define matrix cl_float4
177#endif
178#endif
179
180#ifndef __CL_MIN_LOCALSIZE__
190#define __CL_MIN_LOCALSIZE__ 64
191#endif
192#ifndef __CL_MAX_LOCALSIZE__
202#define __CL_MAX_LOCALSIZE__ 1024
203#endif
204
205#ifndef __ERROR_SHOW_TIME__
206#ifndef HAVE_NCURSES
212#define __ERROR_SHOW_TIME__ 0u
213#else
219#define __ERROR_SHOW_TIME__ 3u
220#endif
221#endif
222
224static std::string methodAndClassName_str;
225
238inline const std::string
239methodAndClassName(const std::string& pretty_function)
240{
241 std::string all_name, method_name, class_name;
242 size_t begin, end;
243
244 // Filter the name removing the preceding and trailing types data
245 end = pretty_function.find("(");
246 begin = pretty_function.substr(0, end).rfind(" ") + 1;
247 end -= begin;
248 all_name = pretty_function.substr(begin, end);
249
250 // Get the method name
251 begin = all_name.rfind("::");
252 if (begin == std::string::npos) {
253 // There are no class name
254 methodAndClassName_str = all_name;
256 }
257 method_name = all_name.substr(begin + 2, std::string::npos);
258 end = begin;
259 begin = all_name.substr(0, end).rfind("::");
260 if (begin == std::string::npos)
261 begin = 0;
262 else
263 begin += 2;
264 end -= begin;
265 class_name = all_name.substr(begin, end);
266 methodAndClassName_str = class_name + "::" + method_name;
268}
269
275#define __METHOD_CLASS_NAME__ methodAndClassName(__PRETTY_FUNCTION__)
276
287class mat
288{
289 public:
295 {
296#ifdef HAVE_3D
297 row[0].x = 0.f;
298 row[0].y = 0.f;
299 row[0].z = 0.f;
300 row[0].w = 0.f;
301 row[1].x = 0.f;
302 row[1].y = 0.f;
303 row[1].z = 0.f;
304 row[1].w = 0.f;
305 row[2].x = 0.f;
306 row[2].y = 0.f;
307 row[2].z = 0.f;
308 row[2].w = 0.f;
309 row[3].x = 0.f;
310 row[3].y = 0.f;
311 row[3].z = 0.f;
312 row[3].w = 0.f;
313#else
314 row[0].x = 0.f;
315 row[0].y = 0.f;
316 row[1].x = 0.f;
317 row[1].y = 0.f;
318#endif
319 }
320
325 vec const& operator[](unsigned index) const { return row[index]; }
330 vec& operator[](unsigned index) { return row[index]; }
331
336 vec operator*(const vec& V)
337 {
338 unsigned int i, j;
339 vec R;
340#ifdef HAVE_3D
341 R.x = row[0].x * V.x + row[0].y * V.y + row[0].z * V.z + row[0].w * V.w;
342 R.y = row[1].x * V.x + row[1].y * V.y + row[1].z * V.z + row[1].w * V.w;
343 R.z = row[2].x * V.x + row[2].y * V.y + row[2].z * V.z + row[2].w * V.w;
344 R.w = row[3].x * V.x + row[3].y * V.y + row[3].z * V.z + row[3].w * V.w;
345#else
346 R.x = row[0].x * V.x + row[0].y * V.y;
347 R.y = row[1].x * V.x + row[1].y * V.y;
348#endif
349 return R;
350 }
351
356 mat& operator=(const mat& M)
357 {
358 if (this == &M) { // Same object, simply return it
359 return *this;
360 }
361#ifdef HAVE_3D
362 row[0].x = M[0].x;
363 row[0].y = M[0].y;
364 row[0].z = M[0].z;
365 row[0].w = M[0].w;
366 row[1].x = M[1].x;
367 row[1].y = M[1].y;
368 row[1].z = M[1].z;
369 row[1].w = M[1].w;
370 row[2].x = M[2].x;
371 row[2].y = M[2].y;
372 row[2].z = M[2].z;
373 row[2].w = M[2].w;
374 row[3].x = M[3].x;
375 row[3].y = M[3].y;
376 row[3].z = M[3].z;
377 row[3].w = M[3].w;
378#else
379 row[0].x = M[0].x;
380 row[0].y = M[0].y;
381 row[1].x = M[1].x;
382 row[1].y = M[1].y;
383#endif
384 return *this;
385 }
386
387 private:
389#ifdef HAVE_3D
390 vec row[4];
391#else
392 vec row[2];
393#endif
394};
395
396#endif // SPHPREREQUISITES_H_INCLUDED
Matrix of real components.
Definition: sphPrerequisites.h:288
mat & operator=(const mat &M)
Definition: sphPrerequisites.h:356
vec & operator[](unsigned index)
Definition: sphPrerequisites.h:330
mat()
Constructor.
Definition: sphPrerequisites.h:294
vec const & operator[](unsigned index) const
Subscript operator to return a matrix row.
Definition: sphPrerequisites.h:325
vec operator*(const vec &V)
Definition: sphPrerequisites.h:336
const std::string methodAndClassName(const std::string &pretty_function)
Function to extract the class and function from <strong class= macro.
Definition: sphPrerequisites.h:239
static std::string methodAndClassName_str
Helper string for methodAndClassName function.
Definition: sphPrerequisites.h:224
#define vec
Vector of real components.
Definition: sphPrerequisites.h:130