#include "cuda.h" #include <wb.h> #include <wbCUDA.h> #define MB (1 << 20) #ifndef WB_DEFAULT_HEAP_SIZE const size_t WB_DEFAULT_HEAP_SIZE = (256 * MB); #endif /* WB_DEFAULT_HEAP_SIZE */ static bool _initializedQ = wbFalse; #ifndef _MSC_VER __attribute__((__constructor__)) #endif /* _MSC_VER */ void wb_init(void) { if (_initializedQ == wbTrue) { return; } #ifdef WB_USE_CUDA cuInit(0); /* Select a random GPU */ { int deviceCount; cudaGetDeviceCount(&deviceCount); srand(time(NULL)); cudaSetDevice(rand() % deviceCount); } cudaDeviceSetLimit(cudaLimitPrintfFifoSize, 1*MB); cudaDeviceSetLimit(cudaLimitMallocHeapSize, WB_DEFAULT_HEAP_SIZE); cudaDeviceSynchronize(); #endif /* WB_USE_CUDA */ #ifdef WB_USE_CUSTOM_MALLOC wbMemoryManager_new(WB_DEFAULT_HEAP_SIZE); #endif /* WB_USE_CUSTOM_MALLOC */ #ifdef _MSC_VER QueryPerformanceFrequency((LARGE_INTEGER *)&_hrtime_frequency); #endif /* _MSC_VER */ _hrtime(); _timer = wbTimer_new(); _logger = wbLogger_new(); _initializedQ = wbTrue; wbFile_init(); #ifdef WB_USE_SANDBOX wbSandbox_new(); #endif /* WB_USE_SANDBOX */ solutionJSON = NULL; atexit(wb_atExit); }
static inline wbLogEntry_t wbLogEntry_new() { wbLogEntry_t elem; elem = wbNew(struct st_wbLogEntry_t); wbLogEntry_setMessage(elem, NULL); wbLogEntry_setTime(elem, _hrtime()); #ifndef NDEBUG wbLogEntry_setLevel(elem, wbLogLevel_TRACE); #else wbLogEntry_setLevel(elem, wbLogLevel_OFF); #endif wbLogEntry_setNext(elem, NULL); wbLogEntry_setLine(elem, -1); wbLogEntry_setFile(elem, NULL); wbLogEntry_setFunction(elem, NULL); return elem; }
static inline wbLogEntry_t wbLogEntry_new() { wbLogEntry_t elem; elem = wbNew(struct st_wbLogEntry_t); wbLogEntry_setId(elem, uuid()); wbLogEntry_setSessionId(elem, sessionId()); wbLogEntry_setMessage(elem, NULL); wbLogEntry_setMPIRank(elem, wbMPI_getRank()); wbLogEntry_setTime(elem, _hrtime()); wbLogEntry_setLevel(elem, wbLogLevel_TRACE); wbLogEntry_setNext(elem, NULL); wbLogEntry_setLine(elem, -1); wbLogEntry_setFile(elem, NULL); wbLogEntry_setFunction(elem, NULL); return elem; }
#include <wb.h> #include <wbCUDA.h> #ifndef WB_DEFAULT_HEAP_SIZE #define WB_DEFAULT_HEAP_SIZE (1024*1024*120) #endif /* WB_DEFAULT_HEAP_SIZE */ static bool _initializedQ = wbFalse; #ifndef _MSC_VER __attribute__ ((__constructor__)) #endif /* _MSC_VER */ void wb_init(void) { if (_initializedQ == wbTrue) { return ; } #ifdef WB_USE_CUDA cuInit(0); /* Select a random GPU */ { int deviceCount; cudaGetDeviceCount(&deviceCount); srand(time(NULL)); cudaSetDevice(rand() % deviceCount); } #endif /* WB_USE_CUDA */ _hrtime(); #ifdef _MSC_VER QueryPerformanceFrequency((LARGE_INTEGER*) &_hrtime_frequency); #endif _timer = wbTimer_new(); _logger = wbLogger_new(); _initializedQ = wbTrue; wbFile_init(); solutionJSON = NULL; atexit(wb_atExit); }