-
Notifications
You must be signed in to change notification settings - Fork 3
/
runtime.C
181 lines (135 loc) · 4.55 KB
/
runtime.C
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/******************************************************************************
*
* This file is part of meryl-utility, a collection of miscellaneous code
* used by Meryl, Canu and others.
*
* This software is based on:
* 'Canu' v2.0 (https://github.com/marbl/canu)
* which is based on:
* 'Celera Assembler' r4587 (http://wgs-assembler.sourceforge.net)
* the 'kmer package' r1994 (http://kmer.sourceforge.net)
*
* Except as indicated otherwise, this is a 'United States Government Work',
* and is released in the public domain.
*
* File 'README.licenses' in the root directory of this distribution
* contains full conditions and disclaimers.
*/
#include "types.H"
#include "files.H"
#include "system.H"
#include "version.H"
#ifdef X86_GCC_LINUX
#include <fpu_control.h>
#endif
#ifdef _GLIBCXX_PARALLEL
#include <parallel/algorithm>
#include <parallel/settings.h>
#endif
// We take argc and argv, so, maybe, eventually, we'll want to parse
// something out of there. We return argc in case what we parse we
// want to remove.
//
int
AS_configure(int argc, char **argv) {
#ifdef X86_GCC_LINUX
// Set the x86 FPU control word to force double precision rounding
// rather than `extended' precision rounding. This causes base
// calls and quality values on x86 GCC-Linux (tested on RedHat
// Linux) machines to be identical to those on IEEE conforming UNIX
// machines.
//
fpu_control_t fpu_cw = ( _FPU_DEFAULT & ~_FPU_EXTENDED ) | _FPU_DOUBLE;
_FPU_SETCW( fpu_cw );
#endif
#ifdef _GLIBCXX_PARALLEL_SETTINGS_H
__gnu_parallel::_Settings s = __gnu_parallel::_Settings::get();
// The sizes that GNU decides to enable parallelization for are
// ludicrously small. A benchmark (Dec 2019, gcc6) showed that a
// sort-heavy code was a whopping 10% faster (wall clock 61 vs 69 seconds)
// but used 10x the CPU time (707 vs 69 seconds).
//
// Further, the sort is no longer in-place. This matters, significantly,
// for our overlap sorting, since we fill memory with as many overlaps as
// possible, and if we don't sort in-place, we run out of memory.
//
// So, if the silly user has enabled parallelization, turn it off for
// sorting by setting the minimal size to something large.
//
s.sort_minimal_n = UINT64_MAX;
__gnu_parallel::_Settings::set(s);
#endif
// Default to one thread. This is mostly to disable the parallel sort,
// which seems to have a few bugs left in it. e.g., a crash when using 48
// threads, but not when using 47, 49 or 64 threads.
omp_set_num_threads(1);
// Install a signal handler to catch seg faults and errors.
AS_UTL_installCrashCatcher(argv[0]);
// Set the start time.
getProcessTime();
//
// Et cetera.
//
for (int32 i=0; i<argc; i++) {
if (strcmp(argv[i], "--version") == 0) {
fputs(MERYL_UTILITY_VERSION, stderr);
exit(0);
}
}
//
// Logging.
//
#if 0
char *p = getenv("CANU_DIRECTORY");
if (p == NULL)
return(argc);
char D[FILENAME_MAX] = {0};
char N[FILENAME_MAX] = {0};
char H[1024] = {0}; // HOST_NAME_MAX? Undefined.
// Make a directory for logs. If an error, just return now, there's nothing we can log.
snprintf(D, FILENAME_MAX, "%s/canu-logs", p);
errno = 0;
mkdir(D, S_IRWXU | S_IRWXG | S_IRWXO);
if ((errno != 0) && (errno != EEXIST))
return(argc);
// Our hostname is part of our unique filename.
gethostname(H, 1024);
// Our executable name is part of our unique filename too.
char *E = argv[0] + strlen(argv[0]) - 1;
while ((E != argv[0]) && (*E != '/'))
E--;
if (*E == '/')
E++;
// Construct a name for this log, and open it. If we can't open it, just skip the log.
snprintf(N, FILENAME_MAX, "%s/" F_U64 "_%s_" F_U64 "_%s",
D,
(uint64)time(NULL),
H,
(uint64)getpid(),
E);
errno = 0;
FILE *F = fopen(N, "w");
if ((errno != 0) || (F == NULL))
return(argc);
fprintf(F, "Canu v%s.%s (+%s commits) r%s %s.\n",
CANU_VERSION_MAJOR,
CANU_VERSION_MINOR,
CANU_VERSION_COMMITS,
CANU_VERSION_REVISION,
CANU_VERSION_HASH);
fprintf(F, "\n");
fprintf(F, "Current Working Directory:\n");
fprintf(F, "%s\n", getcwd(N, FILENAME_MAX));
fprintf(F, "\n");
fprintf(F, "Command:\n");
fprintf(F, "%s", argv[0]);
for (int32 i=1; i<argc; i++)
if (argv[i][0] == '-')
fprintf(F, " \\\n %s", argv[i]);
else
fprintf(F, " %s", argv[i]);
fprintf(F, "\n");
AS_UTL_closeFile(F, N, true);
#endif
return(argc);
}