contrib/openblas/driver/others/openblas_env.c
Line | Count | Source |
1 | | /*************************************************************************** |
2 | | Copyright (c) 2011-2016, The OpenBLAS Project |
3 | | All rights reserved. |
4 | | |
5 | | Redistribution and use in source and binary forms, with or without |
6 | | modification, are permitted provided that the following conditions are |
7 | | met: |
8 | | |
9 | | 1. Redistributions of source code must retain the above copyright |
10 | | notice, this list of conditions and the following disclaimer. |
11 | | |
12 | | 2. Redistributions in binary form must reproduce the above copyright |
13 | | notice, this list of conditions and the following disclaimer in |
14 | | the documentation and/or other materials provided with the |
15 | | distribution. |
16 | | |
17 | | 3. Neither the name of the OpenBLAS project nor the names of |
18 | | its contributors may be used to endorse or promote products |
19 | | derived from this software without specific prior written permission. |
20 | | |
21 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
22 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
23 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
24 | | ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE |
25 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
26 | | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
27 | | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
28 | | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
29 | | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
30 | | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | | |
32 | | *****************************************************************************/ |
33 | | |
34 | | #include "common.h" |
35 | | |
36 | | static int openblas_env_verbose=0; |
37 | | static unsigned int openblas_env_thread_timeout=0; |
38 | | static int openblas_env_block_factor=0; |
39 | | static int openblas_env_openblas_num_threads=0; |
40 | | static int openblas_env_goto_num_threads=0; |
41 | | static int openblas_env_omp_num_threads=0; |
42 | | static int openblas_env_omp_adaptive=0; |
43 | | |
44 | 18 | int openblas_verbose(void) { return openblas_env_verbose;} |
45 | 0 | unsigned int openblas_thread_timeout(void) { return openblas_env_thread_timeout;} |
46 | 0 | int openblas_block_factor(void) { return openblas_env_block_factor;} |
47 | 0 | int openblas_num_threads_env(void) { return openblas_env_openblas_num_threads;} |
48 | 0 | int openblas_goto_num_threads_env(void) { return openblas_env_goto_num_threads;} |
49 | 9 | int openblas_omp_num_threads_env(void) { return openblas_env_omp_num_threads;} |
50 | 0 | int openblas_omp_adaptive_env(void) { return openblas_env_omp_adaptive;} |
51 | | |
52 | 9 | void openblas_read_env(void) { |
53 | 9 | int ret=0; |
54 | 9 | env_var_t p; |
55 | 9 | if (readenv(p,"OPENBLAS_VERBOSE")) ret = atoi(p); |
56 | 9 | if(ret<0) ret=0; |
57 | 9 | openblas_env_verbose=ret; |
58 | | |
59 | 9 | ret=0; |
60 | 9 | if (readenv(p,"OPENBLAS_BLOCK_FACTOR")) ret = atoi(p); |
61 | 9 | if(ret<0) ret=0; |
62 | 9 | openblas_env_block_factor=ret; |
63 | | |
64 | 9 | ret=0; |
65 | 9 | if (readenv(p,"OPENBLAS_THREAD_TIMEOUT")) ret = atoi(p); |
66 | 9 | if(ret<0) ret=0; |
67 | 9 | openblas_env_thread_timeout=(unsigned int)ret; |
68 | | |
69 | 9 | ret=0; |
70 | 9 | if (readenv(p,"OPENBLAS_DEFAULT_NUM_THREADS")) ret = atoi(p); |
71 | 9 | if(ret<0) ret=0; |
72 | 9 | openblas_env_openblas_num_threads=ret; |
73 | | |
74 | 9 | ret=0; |
75 | 9 | if (readenv(p,"OPENBLAS_NUM_THREADS")) ret = atoi(p); |
76 | 9 | if(ret<0) ret=0; |
77 | 9 | if(ret != 0 || openblas_env_openblas_num_threads == 0) |
78 | 9 | openblas_env_openblas_num_threads=ret; |
79 | | |
80 | 9 | ret=0; |
81 | 9 | if (readenv(p,"GOTO_NUM_THREADS")) ret = atoi(p); |
82 | 9 | if(ret<0) ret=0; |
83 | 9 | openblas_env_goto_num_threads=ret; |
84 | | |
85 | 9 | ret=0; |
86 | 9 | if (readenv(p,"OMP_NUM_THREADS")) ret = atoi(p); |
87 | 9 | if(ret<0) ret=0; |
88 | 9 | openblas_env_omp_num_threads=ret; |
89 | | |
90 | 9 | ret=0; |
91 | 9 | if (readenv(p,"OMP_ADAPTIVE")) ret = atoi(p); |
92 | 9 | if(ret<0) ret=0; |
93 | 9 | openblas_env_omp_adaptive=ret; |
94 | | |
95 | 9 | } |
96 | | |
97 | | |