PLASMA  2.4.5
PLASMA - Parallel Linear Algebra for Scalable Multi-core Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
auxiliary.c
Go to the documentation of this file.
1 
16 #include "common.h"
17 #include "auxiliary.h"
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 
22 /***************************************************************************/
36 void plasma_warning(const char *func_name, char* msg_text)
37 {
39 
40  plasma = plasma_context_self();
41  if (plasma == NULL)
42  plasma_fatal_error("plasma_warning", "PLASMA not initialized");
43  if (plasma->warnings_enabled)
44  fprintf(stderr, "PLASMA WARNING: %s(): %s\n", func_name, msg_text);
45 }
46 
47 /***************************************************************************/
61 void plasma_error(const char *func_name, char* msg_text)
62 {
64 
65  plasma = plasma_context_self();
66  if (plasma == NULL)
67  plasma_fatal_error("plasma_error", "PLASMA not initialized");
68  if (plasma->errors_enabled)
69  fprintf(stderr, "PLASMA ERROR: %s(): %s\n", func_name, msg_text);
70 
71 }
72 
73 /***************************************************************************/
86 void plasma_fatal_error(const char *func_name, char* msg_text)
87 {
88  fprintf(stderr, "PLASMA FATAL ERROR: %s(): %s\n", func_name, msg_text);
89  exit(0);
90 }
91 
92 /***************************************************************************/
95 int plasma_element_size(int type)
96 {
97  switch(type) {
98  case PlasmaByte: return 1;
99  case PlasmaInteger: return sizeof(int);
100  case PlasmaRealFloat: return sizeof(float);
101  case PlasmaRealDouble: return sizeof(double);
102  case PlasmaComplexFloat: return 2*sizeof(float);
103  case PlasmaComplexDouble: return 2*sizeof(double);
104  default: plasma_fatal_error("plasma_element_size", "undefined type");
106 
107  }
108 }
109 
110 /***************************************************************************/
113 void plasma_memcpy(void *dst, void *src, PLASMA_size size, int type)
114 {
115  memcpy(dst, src, size*plasma_element_size(type));
116 }
117 
118 /***************************************************************************/
121 void plasma_memzero(void *memptr, PLASMA_size size, int type)
122 {
123  memset(memptr, 0, size*plasma_element_size(type));
124 }
125 
126 /***************************************************************************/
129 void plasma_memset_int(int *mem, int size, int value)
130 {
131  int i;
132 
133  for (i = 0; i < size; i++)
134  mem[i] = value;
135 }
136 
137 /***************************************************************************/
141 {
142  int rank;
143  pthread_t thread_id;
144 
145  thread_id = pthread_self();
146  for (rank = 0; rank < plasma->world_size; rank++)
147  if (pthread_equal(plasma->thread_id[rank], thread_id))
148  return rank;
149  return PLASMA_ERR_NOT_FOUND;
150 }
151 
152 /***************************************************************************/
155 int plasma_tune(PLASMA_enum func, int M, int N, int NRHS)
156 {
158 
159  plasma = plasma_context_self();
160  if (plasma == NULL) {
161  plasma_fatal_error("plasma_tune", "PLASMA not initialized");
163  }
164 
165  if (!plasma->autotuning_enabled)
166  return PLASMA_SUCCESS;
167 
168  switch (func) {
169  case PLASMA_FUNC_SGEMM:
170  case PLASMA_FUNC_DGEMM:
171  case PLASMA_FUNC_CGEMM:
172  case PLASMA_FUNC_ZGEMM:
173  case PLASMA_FUNC_CHERK:
174  case PLASMA_FUNC_ZHERK:
175  case PLASMA_FUNC_SSYRK:
176  case PLASMA_FUNC_DSYRK:
177  case PLASMA_FUNC_CSYRK:
178  case PLASMA_FUNC_ZSYRK:
179  case PLASMA_FUNC_CHEMM:
180  case PLASMA_FUNC_ZHEMM:
181  case PLASMA_FUNC_SSYMM:
182  case PLASMA_FUNC_DSYMM:
183  case PLASMA_FUNC_CSYMM:
184  case PLASMA_FUNC_ZSYMM:
185  plasma->nb = 120;
186  plasma->ib = 120; // not used in GEMM
187  break;
188  case PLASMA_FUNC_SPOSV:
189  case PLASMA_FUNC_DPOSV:
190  case PLASMA_FUNC_CPOSV:
191  case PLASMA_FUNC_ZPOSV:
192  case PLASMA_FUNC_ZCPOSV:
193  case PLASMA_FUNC_DSPOSV:
194  plasma->nb = 120;
195  plasma->ib = 120; // not used in Cholesky
196  break;
197  case PLASMA_FUNC_SGELS:
198  case PLASMA_FUNC_DGELS:
199  case PLASMA_FUNC_CGELS:
200  case PLASMA_FUNC_ZGELS:
201  case PLASMA_FUNC_ZCGELS:
202  case PLASMA_FUNC_DSGELS:
203  plasma->nb = 144;
204  plasma->ib = 48;
205  break;
206  case PLASMA_FUNC_SGESV:
207  case PLASMA_FUNC_DGESV:
208  case PLASMA_FUNC_CGESV:
209  case PLASMA_FUNC_ZGESV:
210  case PLASMA_FUNC_ZCGESV:
211  case PLASMA_FUNC_DSGESV:
212  plasma->nb = 200;
213  plasma->ib = 40;
214  break;
215  case PLASMA_FUNC_SGEEV:
216  case PLASMA_FUNC_DGEEV:
217  case PLASMA_FUNC_CGEEV:
218  case PLASMA_FUNC_ZGEEV:
219  case PLASMA_FUNC_SGEHRD:
220  case PLASMA_FUNC_DGEHRD:
221  case PLASMA_FUNC_CGEHRD:
222  case PLASMA_FUNC_ZGEHRD:
223  plasma->nb = 120;
224  plasma->ib = 20;
225  break;
226  case PLASMA_FUNC_ZHEEV:
227  case PLASMA_FUNC_CHEEV:
228  case PLASMA_FUNC_DSYEV:
229  case PLASMA_FUNC_SSYEV:
230  case PLASMA_FUNC_ZHETRD:
231  case PLASMA_FUNC_CHETRD:
232  case PLASMA_FUNC_DSYTRD:
233  case PLASMA_FUNC_SSYTRD:
234  case PLASMA_FUNC_ZHEGV:
235  case PLASMA_FUNC_CHEGV:
236  case PLASMA_FUNC_DSYGV:
237  case PLASMA_FUNC_SSYGV:
238  case PLASMA_FUNC_ZHEGST:
239  case PLASMA_FUNC_CHEGST:
240  case PLASMA_FUNC_DSYGST:
241  case PLASMA_FUNC_SSYGST:
242  plasma->nb = 120;
243  plasma->ib = 20;
244  break;
245  case PLASMA_FUNC_ZGESVD:
246  case PLASMA_FUNC_CGESVD:
247  case PLASMA_FUNC_DGESVD:
248  case PLASMA_FUNC_SGESVD:
249  case PLASMA_FUNC_ZGEBRD:
250  case PLASMA_FUNC_CGEBRD:
251  case PLASMA_FUNC_DGEBRD:
252  case PLASMA_FUNC_SGEBRD:
253  plasma->nb = 120;
254  plasma->ib = 20;
255  break;
256  default:
257  plasma_fatal_error("plasma_tune", "illegal parameter value");
259  }
260  /* Calculate A, B tile size and round up to cache line size */
261  /* round up for the smallest type (float) - will hold for all */
262  plasma->nbnbsize = plasma->nb * plasma->nb; // * sizeof(float);
263 // plasma->nbnbsize = roundup(plasma->nbnbsize, CACHE_LINE_SIZE);
264 // plasma->nbnbsize /= sizeof(float);
265  /* Calculate T, L tile size and round up to cache line size */
266  /* round up for the smallest type (float) - will hold for all */
267  plasma->ibnbsize = plasma->ib * plasma->nb; // * sizeof(float);
268 // plasma->ibnbsize = roundup(plasma->ibnbsize, CACHE_LINE_SIZE);
269 // plasma->ibnbsize /= sizeof(float);
270  return PLASMA_SUCCESS;
271 }
272 
273 /***************************************************************************/
296 int PLASMA_Version(int *ver_major, int *ver_minor, int *ver_micro)
297 {
298  if (! ver_major && ! ver_minor && ! ver_micro)
300 
301  if (ver_major)
302  *ver_major = PLASMA_VERSION_MAJOR;
303 
304  if (ver_minor)
305  *ver_minor = PLASMA_VERSION_MINOR;
306 
307  if (ver_micro)
308  *ver_micro = PLASMA_VERSION_MICRO;
309 
310  return PLASMA_SUCCESS;
311 }