TMB Documentation  v1.9.11
config.hpp
Go to the documentation of this file.
1 // Copyright (C) 2013-2015 Kasper Kristensen
2 // License: GPL-2
3 
24  /* Configuration variables.
25  - Default values _must_be_ specified with SET(var,value)
26  - Can be either bool or integer.
27  */
28  struct {
29  bool parallel;
30  bool optimize;
31  bool atomic;
32  } trace;
33  struct {
34  bool instantly;
35  bool parallel;
36  } optimize;
37  struct {
38  bool parallel;
39  } tape;
40  struct {
41  bool getListElement;
42  } debug;
43  struct {
48  } tmbad;
49  bool autopar;
50  int nthreads;
52  int cmd;
53  SEXP envir; /* PROTECTed because function argument - see
54  'TMBconfig' */
55  template<class T>
56  void set(const char* name, T &var, T default_value)
57  {
58  // cmd=0: set defaults in this struct.
59  // cmd=1: copy from this struct to R.
60  // cmd=2: copy from R to this struct.
61  SEXP name_symbol = Rf_install(name);
62  if (cmd==0) var = default_value;
63  if (cmd==1) Rf_defineVar(name_symbol, asSEXP(var), envir);
64  if (cmd==2) var = INTEGER(Rf_findVar(name_symbol, envir))[0];
65  }
66 #define SET(name,value)set(#name,name,value);
67  void set() CSKIP(
68  {
69  SET(trace.parallel,true);
70  SET(trace.optimize,true);
71  SET(trace.atomic,true);
72  SET(debug.getListElement,false);
73  SET(optimize.instantly,true);
74  SET(optimize.parallel,false);
75  SET(tape.parallel,true);
76  SET(tmbad.sparse_hessian_compress,false);
77  SET(tmbad.atomic_sparse_log_determinant,true);
78  SET(autopar,false);
79  SET(nthreads,1);
80  })
81 #undef SET
82  config_struct() CSKIP(
83  {
84  cmd=0;
85  set();
86  })
87 };
88 TMB_EXTERN config_struct config;
89 
90 extern "C"
91 {
92  SEXP TMBconfig(SEXP envir, SEXP cmd) CSKIP(
93  {
94  config.cmd=INTEGER(cmd)[0];
95  config.envir=envir;
96  config.set();
97  return R_NilValue;
98  })
99 }
Configuration variables of a user template.
Definition: config.hpp:23
bool optimize
Trace tape optimization.
Definition: config.hpp:30
bool atomic_sparse_log_determinant
Use atomic sparse log determinant (faster but limited order) ?
Definition: config.hpp:47
bool autopar
Enable automatic parallization (if OpenMP is enabled) ?
Definition: config.hpp:49
SEXP asSEXP(const matrix< Type > &a)
Convert TMB matrix, vector, scalar or int to R style.
Definition: convert.hpp:30
bool sparse_hessian_compress
Reduce memory of sparse hessian even if reducing speed ?
Definition: config.hpp:45
int nthreads
Number of OpenMP threads to use (if OpenMP is enabled)
Definition: config.hpp:50
bool instantly
Always optimize just after tape creation.
Definition: config.hpp:34
bool atomic
Trace construction of atomic functions.
Definition: config.hpp:31
bool parallel
Trace info from parallel for loops.
Definition: config.hpp:29
License: GPL v2