File: AS_global.C

package info (click to toggle)
canu 1.7.1+dfsg-1~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 7,680 kB
  • sloc: cpp: 66,708; perl: 13,682; ansic: 4,020; makefile: 627; sh: 472; python: 39
file content (199 lines) | stat: -rw-r--r-- 5,340 bytes parent folder | download
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

/******************************************************************************
 *
 *  This file is part of canu, a software program that assembles whole-genome
 *  sequencing reads into contigs.
 *
 *  This software is based on:
 *    'Celera Assembler' (http://wgs-assembler.sourceforge.net)
 *    the 'kmer package' (http://kmer.sourceforge.net)
 *  both originally distributed by Applera Corporation under the GNU General
 *  Public License, version 2.
 *
 *  Canu branched from Celera Assembler at its revision 4587.
 *  Canu branched from the kmer project at its revision 1994.
 *
 *  Modifications by:
 *
 *    Brian P. Walenz from 2007-AUG-03 to 2013-AUG-01
 *      are Copyright 2007-2009,2011-2013 J. Craig Venter Institute, and
 *      are subject to the GNU General Public License version 2
 *
 *    Sergey Koren on 2009-MAR-06
 *      are Copyright 2009 J. Craig Venter Institute, and
 *      are subject to the GNU General Public License version 2
 *
 *    Brian P. Walenz on 2015-MAR-03
 *      are Copyright 2015 Battelle National Biodefense Institute, and
 *      are subject to the BSD 3-Clause License
 *
 *    Brian P. Walenz beginning on 2015-NOV-08
 *      are a 'United States Government Work', and
 *      are released in the public domain
 *
 *  File 'README.licenses' in the root directory of this distribution contains
 *  full conditions and disclaimers for each license.
 */

#include "AS_global.H"
#include "canu_version.H"

#include "AS_UTL_stackTrace.H"
#include "AS_UTL_fileIO.H"

#include "timeAndSize.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();

  //  Force all algorithms to be parallel.
  //  Force some algs to be sequential by using a tag, eg:
  //    sort(a, a+end, __gnu_parallel::sequential_tag());
  //
  //s.algorithm_strategy = __gnu_parallel::force_parallel;

  //  The default seems to be 1000, way too small for us.
  s.sort_minimal_n = 128 * 1024;

  //  The default is MWMS, which, at least on FreeBSD 8.2 w/gcc46, is NOT inplace.
  //  Then again, the others also appear to be NOT inplace as well.
  //s.sort_algorithm = __gnu_parallel::MWMS;
  //s.sort_algorithm = __gnu_parallel::QS_BALANCED;
  //s.sort_algorithm = __gnu_parallel::QS;

  __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(CANU_VERSION, stderr);
      exit(0);
    }
  }


  //
  //  Logging.
  //

  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);

  return(argc);
}