Dynamic Load Balance 3.7.0
backend_utils.h
Go to the documentation of this file.
1/*********************************************************************************/
2/* Copyright 2009-2025 Barcelona Supercomputing Center */
3/* */
4/* This file is part of the DLB library. */
5/* */
6/* DLB is free software: you can redistribute it and/or modify */
7/* it under the terms of the GNU Lesser General Public License as published by */
8/* the Free Software Foundation, either version 3 of the License, or */
9/* (at your option) any later version. */
10/* */
11/* DLB is distributed in the hope that it will be useful, */
12/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14/* GNU Lesser General Public License for more details. */
15/* */
16/* You should have received a copy of the GNU Lesser General Public License */
17/* along with DLB. If not, see <https://www.gnu.org/licenses/>. */
18/*********************************************************************************/
19
20#ifndef PLUGIN_UTILS_H
21#define PLUGIN_UTILS_H
22
23#include <stdbool.h>
24#include <stdint.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <time.h>
28
29
30static inline uint64_t get_timestamp(void) {
31 struct timespec t;
32 clock_gettime(CLOCK_MONOTONIC_RAW, &t);
33 return (uint64_t)t.tv_sec * 1000000000LL + (uint64_t)t.tv_nsec;
34}
35
36static inline bool plugin_gpu_use_low_level_api(void) {
37
38 const char *env = getenv("DLB_PLUGIN_GPU_USE_LOW_LEVEL_API");
39 if (env && (*env == '1' || *env == 'y' || *env == 'Y')) {
40 return true;
41 }
42
43 return false;
44}
45
46static inline int plugin_is_verbose(void) {
47 static int initialized = 0;
48 static int verbose = 0;
49
50 if (!initialized) {
51 const char *env = getenv("DLB_PLUGIN_VERBOSE");
52 if (env && (*env == '1' || *env == 'y' || *env == 'Y')) {
53 verbose = 1;
54 }
55 initialized = 1;
56 }
57 return verbose;
58}
59
60#define PLUGIN_PRINT(fmt, ...) \
61 do { if (plugin_is_verbose()) fprintf(stderr, "[DLB PLUGIN] " fmt, ##__VA_ARGS__); } while (0)
62
63#define PLUGIN_ERROR(fmt, ...) \
64 do { fprintf(stderr, "[DLB PLUGIN ERROR] " fmt, ##__VA_ARGS__); } while (0)
65
66#define PLUGIN_WARNING(fmt, ...) \
67 do { fprintf(stderr, "[DLB PLUGIN WARNING] " fmt, ##__VA_ARGS__); } while (0)
68
69
70#endif /* PLUGIN_UTILS_H */
71
#define verbose(flag,...)
Definition: debug.h:75