QUDA  v0.5.0
A library for QCD on GPUs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
util_quda.h
Go to the documentation of this file.
1 #ifndef _UTIL_QUDA_H
2 #define _UTIL_QUDA_H
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <enum_quda.h>
7 #include <comm_quda.h>
8 
9 
11 char *getOutputPrefix();
12 FILE *getOutputFile();
13 
14 void setVerbosity(const QudaVerbosity verbosity);
15 void setOutputPrefix(const char *prefix);
16 void setOutputFile(FILE *outfile);
17 
18 void pushVerbosity(QudaVerbosity verbosity);
19 void popVerbosity();
20 
21 char *getPrintBuffer();
22 
23 // Note that __func__ is part of C++11 and has long been supported by GCC.
24 
25 #ifdef MULTI_GPU
26 
27 #define printfQuda(...) do { \
28  sprintf(getPrintBuffer(), __VA_ARGS__); \
29  if (comm_rank() == 0) { \
30  fprintf(getOutputFile(), "%s", getOutputPrefix()); \
31  fprintf(getOutputFile(), "%s", getPrintBuffer()); \
32  fflush(getOutputFile()); \
33  } \
34 } while (0)
35 
36 #define errorQuda(...) do { \
37  fprintf(getOutputFile(), "%sERROR: ", getOutputPrefix()); \
38  fprintf(getOutputFile(), __VA_ARGS__); \
39  fprintf(getOutputFile(), " (rank %d, host %s, " __FILE__ ":%d in %s())\n", \
40  comm_rank(), comm_hostname(), __LINE__, __func__); \
41  fflush(getOutputFile()); \
42  comm_abort(1); \
43 } while (0)
44 
45 #define warningQuda(...) do { \
46  sprintf(getPrintBuffer(), __VA_ARGS__); \
47  if (comm_rank() == 0) { \
48  fprintf(getOutputFile(), "%sWARNING: ", getOutputPrefix()); \
49  fprintf(getOutputFile(), "%s", getPrintBuffer()); \
50  fprintf(getOutputFile(), "\n"); \
51  fflush(getOutputFile()); \
52  } \
53 } while (0)
54 
55 #else
56 
57 #define printfQuda(...) do { \
58  fprintf(getOutputFile(), "%s", getOutputPrefix()); \
59  fprintf(getOutputFile(), __VA_ARGS__); \
60  fflush(getOutputFile()); \
61 } while (0)
62 
63 #define errorQuda(...) do { \
64  fprintf(getOutputFile(), "%sERROR: ", getOutputPrefix()); \
65  fprintf(getOutputFile(), __VA_ARGS__); \
66  fprintf(getOutputFile(), " (" __FILE__ ":%d in %s())\n", \
67  __LINE__, __func__); \
68  exit(1); \
69 } while (0)
70 
71 #define warningQuda(...) do { \
72  fprintf(getOutputFile(), "%sWARNING: ", getOutputPrefix()); \
73  fprintf(getOutputFile(), __VA_ARGS__); \
74  fprintf(getOutputFile(), "\n"); \
75  fflush(getOutputFile()); \
76 } while (0)
77 
78 #endif // MULTI_GPU
79 
80 
81 #define checkCudaErrorNoSync() do { \
82  cudaError_t error = cudaGetLastError(); \
83  if (error != cudaSuccess) \
84  errorQuda("(CUDA) %s", cudaGetErrorString(error)); \
85 } while (0)
86 
87 
88 #ifdef HOST_DEBUG
89 
90 #define checkCudaError() do { \
91  cudaDeviceSynchronize(); \
92  checkCudaErrorNoSync(); \
93 } while (0)
94 
95 #else
96 
97 #define checkCudaError() checkCudaErrorNoSync()
98 
99 #endif // HOST_DEBUG
100 
101 
102 #endif // _UTIL_QUDA_H