QUDA v0.4.0
A library for QCD on GPUs
quda/include/util_quda.h
Go to the documentation of this file.
00001 #ifndef _UTIL_QUDA_H
00002 #define _UTIL_QUDA_H
00003 
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 
00007 #ifdef QMP_COMMS
00008 
00009 #include <qmp.h>
00010 
00011 #define printfQuda(...) do {         \
00012  if (QMP_get_node_number() == 0) {      \
00013     printf(__VA_ARGS__);             \
00014     fflush(stdout);                  \
00015   }                                  \
00016 } while (0)
00017 
00018 #define errorQuda(...) do {                 \
00019   printf("QUDA error: " __VA_ARGS__);   \
00020   printf(" (node %d, " __FILE__ ":%d in %s())\n",   \
00021          QMP_get_node_number(), __LINE__, __FUNCTION__);                        \
00022   QMP_abort(1);                             \
00023 } while (0)
00024 
00025 #elif defined(MPI_COMMS)
00026 
00027 #include <comm_quda.h>
00028 
00029 #define printfQuda(...) do {                    \
00030     if (comm_rank() == 0) {                     \
00031       printf(__VA_ARGS__);                      \
00032       fflush(stdout);                           \
00033     }                                           \
00034   } while (0)
00035 
00036 extern char hostname[];
00037 #define errorQuda(...) do {                 \
00038   printf("QUDA error: " __VA_ARGS__);   \
00039   printf(" (node %d, " __FILE__ ":%d in %s(), hostname=%s)\n",   \
00040          comm_rank(), __LINE__, __FUNCTION__, hostname);               \
00041   comm_exit(1);                                          \
00042 } while (0)
00043 
00044 #else
00045 
00046 #define printfQuda(...) do {                            \
00047     printf(__VA_ARGS__);                                \
00048     fflush(stdout); } while (0)                         
00049 
00050 
00051 #define errorQuda(...) do {                  \
00052   printf("QUDA error: " __VA_ARGS__);   \
00053   printf(" (" __FILE__ ":%d in %s())\n", __LINE__, __FUNCTION__);       \
00054   exit(1);                                   \
00055 } while (0)
00056 
00057 #endif // USE_QMP
00058 
00059 #define warningQuda(...) do {                \
00060   printfQuda("QUDA warning: " __VA_ARGS__);  \
00061   printfQuda("\n");                          \
00062 } while (0)
00063 
00064 #ifdef HOST_DEBUG
00065 
00066 #define checkCudaError() do {                           \
00067     cudaThreadSynchronize();                            \
00068   cudaError_t error = cudaGetLastError();               \
00069   if (error != cudaSuccess)                             \
00070     errorQuda("(CUDA) %s", cudaGetErrorString(error));  \
00071 } while (0)
00072 
00073 #else
00074 
00075 #define checkCudaError() do {                           \
00076   cudaError_t error = cudaGetLastError();               \
00077   if (error != cudaSuccess)                             \
00078     errorQuda("(CUDA) %s", cudaGetErrorString(error));  \
00079 } while (0)
00080 
00081 #endif
00082 
00083 #ifdef __cplusplus
00084 extern "C" {
00085 #endif
00086   
00087   void stopwatchStart();
00088   double stopwatchReadSeconds();
00089 
00090 #ifdef __cplusplus
00091 }
00092 #endif
00093 
00094 #endif // _UTIL_QUDA_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines