ISAAC
Overview :: Library Doc :: Server Doc :: JSON Commands

In Situ Animation of Accelerated Computations

isaac_macros.hpp
Go to the documentation of this file.
1 /* This file is part of ISAAC.
2  *
3  * ISAAC is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * ISAAC is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with ISAAC. If not, see <www.gnu.org/licenses/>. */
15 
16 #pragma once
17 
18 #include "isaac_types.hpp"
19 
20 #define ISAAC_CUDA_CHECK(call) \
21 { \
22  const cudaError_t error = call; \
23  if (error != cudaSuccess) \
24  { \
25  fprintf(stderr, "Error: %s:%d, ", __FILE__, __LINE__); \
26  fprintf(stderr, "code: %d, reason: %s\n", error, \
27  cudaGetErrorString(error)); \
28  } \
29 }
30 
31 #define ISAAC_FOR_EACH_DIM_4(start,end) \
32  start.x end \
33  start.y end \
34  start.z end \
35  start.w end
36 
37 #define ISAAC_FOR_EACH_DIM_3(start,end) \
38  start.x end \
39  start.y end \
40  start.z end
41 
42 #define ISAAC_FOR_EACH_DIM_2(start,end) \
43  start.x end \
44  start.y end
45 
46 #define ISAAC_FOR_EACH_DIM_1(start,end) \
47  start.x end
48 
49 #define ISAAC_FOR_EACH_DIM(dim,start,end) \
50  BOOST_PP_CAT( ISAAC_FOR_EACH_DIM_, dim) (start,end)
51 
52 #define ISAAC_FOR_EACH_DIM_TWICE_4(start,middle,end) \
53  start.x middle.x end \
54  start.y middle.y end \
55  start.z middle.z end \
56  start.w middle.w end
57 
58 #define ISAAC_FOR_EACH_DIM_TWICE_3(start,middle,end) \
59  start.x middle.x end \
60  start.y middle.y end \
61  start.z middle.z end
62 
63 #define ISAAC_FOR_EACH_DIM_TWICE_2(start,middle,end) \
64  start.x middle.x end \
65  start.y middle.y end
66 
67 #define ISAAC_FOR_EACH_DIM_TWICE_1(start,middle,end) \
68  start.x middle.x end
69 
70 #define ISAAC_FOR_EACH_DIM_TWICE(dim,start,middle,end) \
71  BOOST_PP_CAT( ISAAC_FOR_EACH_DIM_TWICE_, dim) (start,middle,end)
72 
73 #define ISAAC_SWITCH_IF_SMALLER(left,right) \
74  if (left < right) \
75  { \
76  auto temp = left; \
77  left = right; \
78  right = temp; \
79  }
80 
81 #define ISAAC_SET_COLOR( dest, color ) \
82  { \
83  isaac_uint4 result; \
84  result.x = ISAAC_MIN( isaac_uint( ISAAC_MIN( isaac_float(1), color.x ) * 255.0f ), 255u); \
85  result.y = ISAAC_MIN( isaac_uint( ISAAC_MIN( isaac_float(1), color.y ) * 255.0f ), 255u); \
86  result.z = ISAAC_MIN( isaac_uint( ISAAC_MIN( isaac_float(1), color.z ) * 255.0f ), 255u); \
87  result.w = ISAAC_MIN( isaac_uint( ISAAC_MIN( isaac_float(1), color.w ) * 255.0f ), 255u); \
88  dest = (result.w << 24) | (result.z << 16) | (result.y << 8) | (result.x << 0); \
89  }
90 
91 #define ISAAC_START_TIME_MEASUREMENT( unique_name, time_function ) \
92  uint64_t BOOST_PP_CAT( __tm_start_, unique_name ) = time_function;
93 #define ISAAC_STOP_TIME_MEASUREMENT( result, operand, unique_name, time_function ) \
94  result operand time_function - BOOST_PP_CAT( __tm_start_, unique_name );
95 
96 #define ISAAC_SET_IDENTITY(size,matrix) \
97  for (isaac_int x = 0; x < size; x++) \
98  for (isaac_int y = 0; y < size; y++) \
99  (matrix)[x+y*size] = (x==y)?1.0f:0.0f;
100 
101 #define ISAAC_JSON_ADD_MATRIX(array,matrix,count) \
102  for (isaac_int i = 0; i < count; i++) \
103  json_array_append_new( array, json_real( (matrix)[i] ) );
104 
105 #ifdef ISAAC_THREADING
106  #define ISAAC_WAIT_VISUALIZATION \
107  if (visualizationThread) \
108  { \
109  pthread_join(visualizationThread,NULL); \
110  visualizationThread = 0; \
111  }
112 #else
113  #define ISAAC_WAIT_VISUALIZATION {}
114 #endif
115 
116 #define ISAAC_HANDLE_EPIPE(add,n,sockfd,readThread) \
117  if (add < 0) \
118  { \
119  pthread_join(readThread,NULL); \
120  readThread = 0; \
121  sockfd = 0; \
122  return n; \
123  }