This repository has been archived by the owner on Jul 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
/
wbInit.cpp
86 lines (68 loc) · 1.67 KB
/
wbInit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "wb.h"
#define MB (1 << 20)
#ifndef WB_DEFAULT_HEAP_SIZE
#define WB_DEFAULT_HEAP_SIZE (1024 * MB)
#endif /* WB_DEFAULT_HEAP_SIZE */
static bool _initializedQ = wbFalse;
#ifndef WB_USE_WINDOWS
//__attribute__((__constructor__))
#endif /* WB_USE_WINDOWS */
void wb_init(int *
#ifdef WB_USE_MPI
argc
#endif /* WB_USE_MPI */
,
char ***
#ifdef WB_USE_MPI
argv
#endif /* WB_USE_MPI */
) {
if (_initializedQ == wbTrue) {
return;
}
#ifdef WB_USE_MPI
wbMPI_Init(argc, argv);
#endif /* WB_USE_MPI */
_envSessionId();
#ifdef WB_USE_CUDA
CUresult err = cuInit(0);
/* Select a random GPU */
#ifdef WB_USE_MPI
if (rankCount() > 1) {
int deviceCount;
cudaGetDeviceCount(&deviceCount);
srand(time(NULL));
cudaSetDevice(wbMPI_getRank() % deviceCount);
} else {
int deviceCount;
cudaGetDeviceCount(&deviceCount);
srand(time(NULL));
cudaSetDevice(rand() % deviceCount);
}
#else
{
int deviceCount;
cudaGetDeviceCount(&deviceCount);
srand(time(NULL));
cudaSetDevice(rand() % deviceCount);
}
#endif /* WB_USE_MPI */
cudaDeviceSetLimit(cudaLimitPrintfFifoSize, 1 * MB);
cudaDeviceSetLimit(cudaLimitMallocHeapSize, WB_DEFAULT_HEAP_SIZE);
cudaDeviceSynchronize();
#endif /* WB_USE_CUDA */
#ifdef WB_USE_WINDOWS
QueryPerformanceFrequency((LARGE_INTEGER *)&_hrtime_frequency);
#endif /* _MSC_VER */
_hrtime();
_timer = wbTimer_new();
_logger = wbLogger_new();
_initializedQ = wbTrue;
wbFile_init();
solutionJSON = nullptr;
#ifdef WB_USE_MPI
atexit(wbMPI_Exit);
#else /* WB_USE_MPI */
atexit(wb_atExit);
#endif /* WB_USE_MPI */
}