CppADCodeGen  2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
openmp_c.hpp
1 const char CPPADCG_OPENMP_C_FILE[] = R"*=*(/* --------------------------------------------------------------------------
2  * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
3  * Copyright (C) 2016 Ciengis
4  *
5  * CppADCodeGen is distributed under multiple licenses:
6  *
7  * - Eclipse Public License Version 1.0 (EPL1), and
8  * - GNU General Public License Version 3 (GPL3).
9  *
10  * EPL1 terms and conditions can be found in the file "epl-v10.txt", while
11  * terms and conditions for the GPL3 can be found in the file "gpl3.txt".
12  * ----------------------------------------------------------------------------
13  * Author: Joao Leal
14  */
15 
16 #include <omp.h>
17 #include <stdio.h>
18 
19 enum ScheduleStrategy {SCHED_STATIC = 1,
20  SCHED_DYNAMIC = 2,
21  SCHED_GUIDED = 3
22  };
23 
24 static volatile int cppadcg_openmp_enabled = 1; // false
25 static volatile int cppadcg_openmp_verbose = 1; // false
26 static volatile unsigned int cppadcg_openmp_n_threads = 2;
27 
28 static enum ScheduleStrategy schedule_strategy = SCHED_DYNAMIC;
29 
30 
31 void cppadcg_openmp_set_disabled(int disabled) {
32  cppadcg_openmp_enabled = !disabled;
33 }
34 
35 int cppadcg_openmp_is_disabled() {
36  return !cppadcg_openmp_enabled;
37 }
38 
39 void cppadcg_openmp_set_verbose(int v) {
40  cppadcg_openmp_verbose = v;
41 }
42 
43 int cppadcg_openmp_is_verbose() {
44  return cppadcg_openmp_verbose;
45 }
46 
47 void cppadcg_openmp_set_threads(unsigned int n) {
48  if(n <= 0)
49  n = 1;
50  cppadcg_openmp_n_threads = n;
51 }
52 
53 unsigned int cppadcg_openmp_get_threads() {
54  return cppadcg_openmp_n_threads;
55 }
56 
57 void cppadcg_openmp_set_scheduler_strategy(enum ScheduleStrategy s) {
58  schedule_strategy = s;
59 }
60 
61 enum ScheduleStrategy cppadcg_openmp_get_scheduler_strategy() {
62  return schedule_strategy;
63 }
64 
65 void cppadcg_openmp_apply_scheduler_strategy() {
66  if (schedule_strategy == SCHED_DYNAMIC) {
67  omp_set_schedule(omp_sched_dynamic, 1);
68  } else if (schedule_strategy == SCHED_GUIDED) {
69  omp_set_schedule(omp_sched_guided, 0);
70  } else {
71  omp_set_schedule(omp_sched_static, 0);
72  }
73 })*=*";
74 
75 const size_t CPPADCG_OPENMP_C_FILE_SIZE = 2066;
76