CHAMELEON 1.4.0
Loading...
Searching...
No Matches
auxiliary.c
Go to the documentation of this file.
1
31#include "control/common.h"
32#include "control/auxiliary.h"
33
34#include <stdio.h>
35#include <stdlib.h>
36#include <limits.h>
37
38int _chameleon_silent = 0;
39
40__attribute__((unused)) __attribute__((constructor)) static void
41__chameleon_lib_init()
42{
43 _chameleon_silent = chameleon_getenv_get_value_int( "CHAMELEON_SILENT", _chameleon_silent );
44}
45
46void
47__chameleon_log_debug( const char *fmt, ... )
48{
49 va_list ap;
50
51 if ( _chameleon_silent ) {
52 return;
53 }
54
55 va_start( ap, fmt );
56 vfprintf( stderr, fmt, ap );
57 va_end(ap);
58}
59
74void chameleon_warning(const char *func_name, const char *msg_text)
75{
76 CHAM_context_t *chamctxt;
77
78 chamctxt = chameleon_context_self();
79 if (chamctxt == NULL) {
80 chameleon_fatal_error("chameleon_warning", "CHAMELEON not initialized");
81 }
82 if (chamctxt->warnings_enabled) {
83 fprintf(stderr, "CHAMELEON WARNING: %s(): %s\n", func_name, msg_text);
84 }
85}
86
101void chameleon_error(const char *func_name, const char *msg_text)
102{
103 fprintf( stderr, "CHAMELEON ERROR: %s(): %s\n", func_name, msg_text );
104}
105
119void chameleon_fatal_error(const char *func_name, const char *msg_text)
120{
121 fprintf(stderr, "CHAMELEON FATAL ERROR: %s(): %s\n", func_name, msg_text);
122 exit(0);
123}
124
128int chameleon_rank(CHAM_context_t *chamctxt)
129{
130 return RUNTIME_thread_rank( chamctxt );
131}
132
136int chameleon_tune(cham_tasktype_t func, int M, int N, int NRHS)
137{
138 CHAM_context_t *chamctxt;
139 chamctxt = chameleon_context_self();
140 if ( chamctxt && chamctxt->autotuning_enabled == CHAMELEON_TRUE ) {
141 chameleon_warning( "chameleon_tune", "Autotunning not available for now" );
142 }
143 (void)func;
144 (void)M;
145 (void)N;
146 (void)NRHS;
147 return CHAMELEON_SUCCESS;
148}
149
172int CHAMELEON_Version(int *ver_major, int *ver_minor, int *ver_micro)
173{
174 if (! ver_major && ! ver_minor && ! ver_micro)
175 return CHAMELEON_ERR_ILLEGAL_VALUE;
176
177 if (ver_major)
178 *ver_major = CHAMELEON_VERSION_MAJOR;
179
180 if (ver_minor)
181 *ver_minor = CHAMELEON_VERSION_MINOR;
182
183 if (ver_micro)
184 *ver_micro = CHAMELEON_VERSION_MICRO;
185
186 return CHAMELEON_SUCCESS;
187}
188
212ssize_t CHAMELEON_Element_Size( cham_flttype_t type )
213{
214 switch( cham_get_flttype(type) ) {
215 case ChamByte: return (ssize_t)1;
216 case ChamInteger16: return sizeof(int16_t);
217 case ChamInteger32: return sizeof(int32_t);
218 case ChamInteger64: return sizeof(int64_t);
219 case ChamRealHalf: return (ssize_t)2;
220 case ChamRealFloat: return sizeof(float);
221 case ChamRealDouble: return sizeof(double);
222 case ChamComplexHalf: return (ssize_t)4;
223 case ChamComplexFloat: return sizeof(float) * 2;
224 case ChamComplexDouble: return sizeof(double) * 2;
225 default: chameleon_fatal_error("CHAMELEON_Element_Size", "undefined type");
226 return CHAMELEON_ERR_ILLEGAL_VALUE;
227
228 }
229}
230
234void update_progress(int currentValue, int maximumValue) {
235 div_t res ;
236 static int progress = -1; /* varie de 0 a 100 au cours du calcul concerne */
237
238 if (maximumValue == 0) {
239 res.quot = 100;
240 }
241 else {
242 if (currentValue < (INT_MAX / 100) ) {
243 res = div(currentValue*100, maximumValue);
244 }
245 else {
246 /* Compute the quotient */
247 res.quot = (int)( ((double)currentValue * 100.) / (double)maximumValue );
248 }
249 }
250
251 // Print the percentage
252 if (res.quot > progress) {
253 fprintf(stderr, "%3d%%\b\b\b\b", res.quot);
254 }
255 progress = res.quot;
256
257 if (currentValue >= maximumValue) {
258 progress = -1;
259 }
260}
261
262// A function to display the progress indicator.
263// By default it is update_progress()
264// The user can change it with CHAMELEON_Set_update_progress_callback()
265void (*update_progress_callback)(int, int) = update_progress;
266
267int CHAMELEON_Set_update_progress_callback(void (*p)(int, int)) {
268 update_progress_callback = p;
269 return CHAMELEON_SUCCESS;
270}
271
int chameleon_tune(cham_tasktype_t func, int M, int N, int NRHS)
Definition auxiliary.c:136
void chameleon_error(const char *func_name, const char *msg_text)
Definition auxiliary.c:101
void update_progress(int currentValue, int maximumValue)
Definition auxiliary.c:234
int chameleon_rank(CHAM_context_t *chamctxt)
Definition auxiliary.c:128
void chameleon_warning(const char *func_name, const char *msg_text)
Definition auxiliary.c:74
void chameleon_fatal_error(const char *func_name, const char *msg_text)
Definition auxiliary.c:119
CHAM_context_t * chameleon_context_self()
Definition context.c:169
ssize_t CHAMELEON_Element_Size(cham_flttype_t type)
Definition auxiliary.c:212
int CHAMELEON_Version(int *ver_major, int *ver_minor, int *ver_micro)
Definition auxiliary.c:172