/[escript]/trunk/escriptcore/src/EscriptParams.cpp
ViewVC logotype

Contents of /trunk/escriptcore/src/EscriptParams.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5972 - (show annotations)
Wed Feb 24 04:05:30 2016 UTC (3 years, 1 month ago) by caltinay
File size: 6272 byte(s)
Major rework of our exceptions. We now have specific
AssertException
NotImplementedError
ValueError
which translate to the corresponding python exception type.
I have gone through a few places and replaced things but not everywhere.


1
2
3 /*****************************************************************************
4 *
5 * Copyright (c) 2003-2016 by The University of Queensland
6 * http://www.uq.edu.au
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
13 * Development 2012-2013 by School of Earth Sciences
14 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
15 *
16 *****************************************************************************/
17
18 #define ESNEEDPYTHON
19 #include "esysUtils/first.h"
20
21 #include "EscriptParams.h"
22 #include "EsysException.h"
23 #include "esysUtils/Esys_MPI.h"
24
25 #include <cstring>
26 #include <cmath> // to test if we know how to check for nan
27 #include <boost/python/tuple.hpp>
28
29 namespace escript
30 {
31
32 EscriptParams escriptParams; // externed in header file
33
34
35 EscriptParams::EscriptParams()
36 {
37 too_many_lines=80;
38 autolazy=0;
39 too_many_levels=70;
40 lazy_str_fmt=0;
41 lazy_verbose=0;
42 #ifdef USE_NETCDF
43 has_netcdf=1;
44 #else
45 has_netcdf=0;
46 #endif
47 #ifdef USE_LAPACK
48 lapack_support=1;
49 #else
50 lapack_support=0;
51 #endif
52
53 gmsh = gmsh_mpi = 0;
54 #if defined(GMSH) || defined(GMSH_MPI)
55 gmsh = 1;
56 #endif
57 //only mark gmsh as mpi if escript built with mpi, otherwise comm_spawns
58 //might just fail terribly
59 #if defined(GMSH_MPI) && defined(ESYS_MPI)
60 gmsh_mpi = 1;
61 #endif
62
63 #ifdef ESYS_MPI
64 amg_disabled=true;
65 #else
66 amg_disabled=false;
67 #endif
68
69 temp_direct_solver=false; // This variable is to be removed once proper
70 // SolverOptions support is in place
71 #ifdef MKL
72 temp_direct_solver=true;
73 #endif
74 #ifdef USE_UMFPACK
75 temp_direct_solver=true;
76 #endif
77 #ifdef PASTIX
78 temp_direct_solver=true;
79 #endif
80
81 // These #defs are for performance testing only
82 // in general, I don't want people tweaking the
83 // default value using compiler options
84 // I've provided a python interface for that
85 #ifdef FAUTOLAZYON
86 autolazy=1;
87 #endif
88 #ifdef FAUTOLAZYOFF
89 autolazy=0;
90 #endif
91
92 #ifdef FRESCOLLECTON
93 resolve_collective=1;
94 #endif
95 #ifdef FRESCOLLECTOFF
96 resolve_collective=0;
97 #endif
98 }
99
100 int
101 EscriptParams::getInt(const char* name, int sentinel) const
102 {
103 if (!strcmp(name,"TOO_MANY_LINES"))
104 {
105 return too_many_lines;
106 }
107 if (!strcmp(name,"AUTOLAZY"))
108 {
109 return autolazy;
110 }
111 if (!strcmp(name,"TOO_MANY_LEVELS"))
112 {
113 return too_many_levels;
114 }
115 if (!strcmp(name,"RESOLVE_COLLECTIVE"))
116 {
117 return resolve_collective;
118 }
119 if (!strcmp(name,"LAZY_STR_FMT"))
120 {
121 return lazy_str_fmt;
122 }
123 if (!strcmp(name,"LAPACK_SUPPORT"))
124 {
125 return lapack_support;
126 }
127 if (!strcmp(name, "NAN_CHECK"))
128 {
129 #ifdef isnan
130 return 1;
131 #else
132 return 0;
133 #endif
134 }
135 if (!strcmp(name,"LAZY_VERBOSE"))
136 {
137 return lazy_verbose;
138 }
139 if (!strcmp(name, "DISABLE_AMG"))
140 {
141 return amg_disabled;
142 }
143 if (!strcmp(name, "MPIBUILD"))
144 {
145 #ifdef ESYS_MPI
146 return 1;
147 #else
148 return 0;
149 #endif
150 }
151 if (!strcmp(name, "PASO_DIRECT"))
152 {
153 // This is not in the constructor because escriptparams could be constructed
154 // before main (and hence no opportunity to call INIT)
155 #ifdef ESYS_MPI
156 int size;
157 if (MPI_Comm_size(MPI_COMM_WORLD, &size)!=MPI_SUCCESS) // This would break in a subworld
158 {
159 temp_direct_solver=false;
160 }
161 if (size>1)
162 {
163 temp_direct_solver=false;
164 }
165 #endif
166 return temp_direct_solver;
167 }
168 if (!strcmp(name, "NETCDF_BUILD"))
169 {
170 return has_netcdf;
171 }
172 if (!strcmp(name, "GMSH_SUPPORT"))
173 return gmsh;
174 if (!strcmp(name, "GMSH_MPI"))
175 return gmsh_mpi;
176 return sentinel;
177 }
178
179 void
180 EscriptParams::setInt(const char* name, int value)
181 {
182 // Note: there is no way to modify the LAPACK_SUPPORT variable ATM
183 if (!strcmp(name,"TOO_MANY_LINES"))
184 too_many_lines=value;
185 else if (!strcmp(name,"AUTOLAZY"))
186 autolazy=!(value==0); // set to 1 or zero
187 else if (!strcmp(name,"TOO_MANY_LEVELS"))
188 too_many_levels=value;
189 else if (!strcmp(name,"RESOLVE_COLLECTIVE"))
190 resolve_collective=value;
191 else if (!strcmp(name,"LAZY_STR_FMT"))
192 lazy_str_fmt=value;
193 else if (!strcmp(name,"LAZY_VERBOSE"))
194 lazy_verbose=value;
195 else
196 throw EsysException("Invalid parameter name");
197 }
198
199 void
200 setEscriptParamInt(const char* name, int value)
201 {
202 escriptParams.setInt(name,value);
203 }
204
205
206 int
207 getEscriptParamInt(const char* name, int sentinel)
208 {
209 return escriptParams.getInt(name, sentinel);
210 }
211
212 boost::python::list
213 EscriptParams::listEscriptParams()
214 {
215 using namespace boost::python;
216 boost::python::list l;
217 l.append(make_tuple("TOO_MANY_LINES", too_many_lines, "Maximum number of lines to output when printing data before printing a summary instead."));
218 l.append(make_tuple("AUTOLAZY", autolazy, "{0,1} Operations involving Expanded Data will create lazy results."));
219 l.append(make_tuple("RESOLVE_COLLECTIVE",resolve_collective ,"(TESTING ONLY) {0.1} Collective operations will resolve their data."));
220 l.append(make_tuple("TOO_MANY_LEVELS", too_many_levels, "(TESTING ONLY) maximum levels allowed in an expression."));
221 l.append(make_tuple("LAZY_STR_FMT", lazy_str_fmt, "{0,1,2}(TESTING ONLY) change output format for lazy expressions."));
222 l.append(make_tuple("LAZY_VERBOSE", lazy_verbose, "{0,1} Print a warning when expressions are resolved because they are too large."));
223 l.append(make_tuple("DISABLE_AMG", amg_disabled, "{0,1} AMG is disabled."));
224 l.append(make_tuple("NETCDF_BUILD", has_netcdf, "{0,1} Was this build made with netcdf libraries?"));
225 l.append(make_tuple("GMSH_SUPPORT", gmsh, "{0,1} Non-python GMSH support is available."));
226 l.append(make_tuple("GMSH_MPI", gmsh_mpi, "{0,1} Both GMSH and escript have MPI capabilities."));
227 return l;
228 }
229
230
231
232
233 } // end namespace

  ViewVC Help
Powered by ViewVC 1.1.26