29 #ifndef CORE_PARSER_ARRAYMATHPROGRAM_H
30 #define CORE_PARSER_ARRAYMATHPROGRAM_H 1
43 #include <boost/function.hpp>
44 #include <boost/variant.hpp>
45 #include <boost/noncopyable.hpp>
53 class ArrayMathIntepreter;
54 class ArrayMathFunction;
56 class ArrayMathProgram;
57 class ArrayMathProgramCode;
82 const std::string& function_id,
83 const std::string& function_type,
90 {
return (function_); }
111 function_(function),
index_(0), size_(1) {}
114 function_(0),
index_(0), size_(1) {}
118 function_ =
function;
130 if (j >= variables_.size()) variables_.resize(j+1);
131 variables_[j] = variable;
138 if (j >= variables_.size()) variables_.resize(j+1);
139 variables_[j] = vmesh;
146 if (j >= variables_.size()) variables_.resize(j+1);
147 variables_[j] = vfield;
154 if (j >= variables_.size()) variables_.resize(j+1);
155 variables_[j] = matrix;
158 #ifdef SCIRUN4_CODE_TO_BE_ENABLED_LATER
160 inline void set_pointer(
size_t j,
void* pointer)
162 if (j >= variables_.size()) variables_.resize(j+1);
163 variables_[j] = pointer;
169 if (j >= variables_.size()) variables_.resize(j+1);
170 variables_[j] = array;
175 if (j >= variables_.size()) variables_.resize(j+1);
176 variables_[j] = array;
181 if (j >= variables_.size()) variables_.resize(j+1);
182 variables_[j] = array;
196 {
return boost::get<double*>(variables_[j]); }
199 {
return boost::get<VMesh*>(variables_[j]); }
202 {
return boost::get<VField*>(variables_[j]); }
205 {
return boost::get<Core::Datatypes::MatrixHandle>(variables_[j]); }
208 {
return boost::get<std::vector<bool>*>(variables_[j]); }
210 {
return boost::get<std::vector<int>*>(variables_[j]); }
212 {
return boost::get<std::vector<double>*>(variables_[j]); }
223 {
return (function_(*
this)); }
236 typedef boost::variant<
262 name_(name), data_(data) {}
275 vmesh_(0), vfield_(0), matrix_(0), bool_array_(0), int_array_(0), double_array_(0) {}
306 std::vector<bool>* bool_array_;
307 std::vector<int>* int_array_;
308 std::vector<double>* double_array_;
325 size_type buffer_size,
int num_proc = -1) :
326 num_proc_(num_proc < 1 ? Core::
Thread::
Parallel::NumCores() : num_proc),
327 barrier_(
"ArrayMathProgram", num_proc_)
331 buffer_size_ = buffer_size;
332 array_size_ = array_size;
347 bool add_source(
const std::string&
name,
VField* vfield);
348 bool add_source(
const std::string&
name,
VMesh* vmesh);
350 bool add_source(
const std::string&
name, std::vector<bool>* array);
351 bool add_source(
const std::string&
name, std::vector<int>* array);
352 bool add_source(
const std::string&
name, std::vector<double>* array);
354 bool add_sink(
const std::string&
name,
VField* vfield);
355 bool add_sink(
const std::string&
name,
VMesh* vmesh);
357 bool add_sink(
const std::string&
name, std::vector<bool>* array);
358 bool add_sink(
const std::string&
name, std::vector<int>* array);
359 bool add_sink(
const std::string&
name, std::vector<double>* array);
362 { const_variables_.resize(sz); }
364 { single_variables_.resize(sz); }
367 sequential_variables_.resize(num_proc_);
368 for (
int np=0; np < num_proc_; np++)
369 sequential_variables_[np].resize(sz);
373 { const_functions_.resize(sz); }
375 { single_functions_.resize(sz); }
378 sequential_functions_.resize(num_proc_);
379 for (
int np=0; np < num_proc_; np++)
380 sequential_functions_[np].resize(sz);
385 { buffer_.resize(size);
return buffer_.empty() ? 0 : (&(buffer_[0])); }
390 { const_variables_[j] = handle; }
392 { single_variables_[j] = handle; }
394 { sequential_variables_[np][j] = handle; }
397 {
return (const_variables_[j]); }
399 {
return (single_variables_[j]); }
401 {
return (sequential_variables_[np][j]); }
405 { const_functions_[j] = pc; }
407 { single_functions_[j] = pc; }
409 { sequential_functions_[np][j] = pc; }
415 bool run_const(
size_t& error_line);
416 bool run_single(
size_t& error_line);
417 bool run_sequential(
size_t& error_line);
433 std::vector<double> buffer_;
436 std::map<std::string,ArrayMathProgramSource> input_sources_;
437 std::map<std::string,ArrayMathProgramSource> output_sinks_;
440 std::vector<ArrayMathProgramVariableHandle> const_variables_;
441 std::vector<ArrayMathProgramVariableHandle> single_variables_;
442 std::vector<std::vector<ArrayMathProgramVariableHandle> > sequential_variables_;
445 std::vector<ArrayMathProgramCodePtr> const_functions_;
446 std::vector<ArrayMathProgramCodePtr> single_functions_;
447 std::vector<std::vector<ArrayMathProgramCodePtr> > sequential_functions_;
453 void run_parallel(
int proc);
456 std::vector<size_type> error_line_;
457 std::vector<bool> success_;
479 const std::string&
name,
483 const std::string& name,
489 const std::string& name,
494 const std::string& name,
495 std::vector<bool>* array,
499 const std::string& name,
500 std::vector<int>* array,
504 const std::string& name,
505 std::vector<double>* array,
511 const std::string& name,
515 const std::string& name,
521 const std::string& name,
526 const std::string& name,
527 std::vector<bool>* array,
531 const std::string& name,
532 std::vector<int>* array,
536 const std::string& name,
537 std::vector<double>* array,
ArrayMathProgramVariableHandle get_sequential_variable(size_t j, size_t np) const
Definition: ArrayMathInterpreter.h:400
void set_const_variable(size_t j, ArrayMathProgramVariableHandle handle)
Definition: ArrayMathInterpreter.h:389
void set_function(ArrayMathFunctionPtr function)
Definition: ArrayMathInterpreter.h:116
void resize_sequential_variables(size_t sz)
Definition: ArrayMathInterpreter.h:365
size_type get_size() const
Definition: ArrayMathInterpreter.h:191
boost::shared_ptr< Matrix > MatrixHandle
Definition: MatrixFwd.h:44
ArrayMathFunctionPtr get_function() const
Definition: ArrayMathInterpreter.h:121
ArrayMathProgramVariableHandle get_const_variable(size_t j) const
Definition: ArrayMathInterpreter.h:396
void set_double_array(size_t j, std::vector< double > *array)
Definition: ArrayMathInterpreter.h:179
void set_vfield(size_t j, VField *vfield)
Definition: ArrayMathInterpreter.h:144
void set_sequential_program_code(size_t j, size_t np, ArrayMathProgramCodePtr pc)
Definition: ArrayMathInterpreter.h:408
boost::function< bool(ArrayMathProgramCode &)> ArrayMathFunctionPtr
Definition: ArrayMathInterpreter.h:75
std::vector< double > * get_double_array() const
Definition: ArrayMathInterpreter.h:298
ArrayMathProgramVariableHandle get_single_variable(size_t j) const
Definition: ArrayMathInterpreter.h:398
bool is_bool_array() const
Definition: ArrayMathInterpreter.h:291
std::vector< bool > * get_bool_array(size_t j)
Definition: ArrayMathInterpreter.h:207
void set_parser_program(ParserProgramHandle handle)
Definition: ArrayMathInterpreter.h:419
void set_matrix(size_t j, Core::Datatypes::MatrixHandle matrix)
Definition: ArrayMathInterpreter.h:152
ParserProgramHandle get_parser_program()
Definition: ArrayMathInterpreter.h:420
void resize_const_variables(size_t sz)
Definition: ArrayMathInterpreter.h:361
void set_int_array(std::vector< int > *array)
Definition: ArrayMathInterpreter.h:293
void set_double_array(std::vector< double > *array)
Definition: ArrayMathInterpreter.h:297
bool index_(ArrayMathProgramCode &pc)
Definition: ArrayMathFunctionSourceSink.cc:636
void set_size(size_type size)
Definition: ArrayMathInterpreter.h:190
VField * get_vfield() const
Definition: ArrayMathInterpreter.h:282
void set_variable(size_t j, double *variable)
Definition: ArrayMathInterpreter.h:128
#define SCISHARE
Definition: share.h:39
bool is_vfield() const
Definition: ArrayMathInterpreter.h:283
ArrayMathProgram(size_type array_size, size_type buffer_size, int num_proc=-1)
Definition: ArrayMathInterpreter.h:324
bool is_matrix() const
Definition: ArrayMathInterpreter.h:287
ArrayMathFunctionPtr get_function() const
Definition: ArrayMathInterpreter.h:89
virtual ~ArrayMathFunction()
Definition: ArrayMathInterpreter.h:87
boost::shared_ptr< ArrayMathProgramCode > ArrayMathProgramCodePtr
Definition: ArrayMathInterpreter.h:254
void set_vmesh(size_t j, VMesh *vmesh)
Definition: ArrayMathInterpreter.h:136
std::vector< int > * get_int_array() const
Definition: ArrayMathInterpreter.h:294
ArrayMathProgram()
Definition: ArrayMathInterpreter.h:315
Definition: ArrayMathInterpreter.h:462
Definition: ArrayMathInterpreter.h:271
void set_vmesh(VMesh *vmesh)
Definition: ArrayMathInterpreter.h:277
bool is_int_array() const
Definition: ArrayMathInterpreter.h:295
const char * name[]
Definition: BoostGraphExampleTests.cc:87
boost::shared_ptr< ArrayMathProgram > ArrayMathProgramHandle
Definition: ArrayMathInterpreter.h:65
void set_single_variable(size_t j, ArrayMathProgramVariableHandle handle)
Definition: ArrayMathInterpreter.h:391
long long size_type
Definition: Types.h:40
std::vector< int > * get_int_array(size_t j)
Definition: ArrayMathInterpreter.h:209
void resize_single_functions(size_t sz)
Definition: ArrayMathInterpreter.h:374
ArrayMathProgramVariable(const std::string &name, double *data)
Definition: ArrayMathInterpreter.h:261
Core::Datatypes::MatrixHandle get_matrix() const
Definition: ArrayMathInterpreter.h:286
void set_array_size(size_type array_size)
Definition: ArrayMathInterpreter.h:345
dictionary data
Definition: eabLatVolData.py:11
void set_bool_array(std::vector< bool > *array)
Definition: ArrayMathInterpreter.h:289
void set_const_program_code(size_t j, ArrayMathProgramCodePtr pc)
Definition: ArrayMathInterpreter.h:404
void set_sequential_variable(size_t j, size_t np, ArrayMathProgramVariableHandle handle)
Definition: ArrayMathInterpreter.h:393
bool is_vmesh() const
Definition: ArrayMathInterpreter.h:279
bool run()
Definition: ArrayMathInterpreter.h:222
boost::shared_ptr< ParserProgram > ParserProgramHandle
Definition: Parser.h:70
void resize_single_variables(size_t sz)
Definition: ArrayMathInterpreter.h:363
double * get_variable(size_t j)
Definition: ArrayMathInterpreter.h:195
boost::shared_ptr< ArrayMathProgramVariable > ArrayMathProgramVariableHandle
Definition: ArrayMathInterpreter.h:58
VMesh * get_vmesh(size_t j)
Definition: ArrayMathInterpreter.h:198
void set_single_program_code(size_t j, ArrayMathProgramCodePtr pc)
Definition: ArrayMathInterpreter.h:406
Definition: ArrayMathInterpreter.h:77
Definition: ArrayMathInterpreter.h:312
Definition: Parallel.h:61
void set_int_array(size_t j, std::vector< int > *array)
Definition: ArrayMathInterpreter.h:173
size_type get_buffer_size() const
Definition: ArrayMathInterpreter.h:339
ArrayMathProgramCode()
Definition: ArrayMathInterpreter.h:113
VField * get_vfield(size_t j)
Definition: ArrayMathInterpreter.h:201
int get_num_proc() const
Definition: ArrayMathInterpreter.h:341
long long index_type
Definition: Types.h:39
double * create_buffer(size_t size)
Definition: ArrayMathInterpreter.h:384
std::vector< double > * get_double_array(size_t j)
Definition: ArrayMathInterpreter.h:211
boost::shared_ptr< Field > FieldHandle
Definition: DatatypeFwd.h:65
void resize_const_functions(size_t sz)
Definition: ArrayMathInterpreter.h:372
void resize_sequential_functions(size_t sz)
Definition: ArrayMathInterpreter.h:376
void set_matrix(Core::Datatypes::MatrixHandle matrix)
Definition: ArrayMathInterpreter.h:285
Core::Datatypes::MatrixHandle get_matrix(size_t j)
Definition: ArrayMathInterpreter.h:204
void set_index(index_type index)
Definition: ArrayMathInterpreter.h:187
Definition: ArrayMathInterpreter.h:258
std::vector< bool > * get_bool_array() const
Definition: ArrayMathInterpreter.h:290
ArrayMathProgramSource()
Definition: ArrayMathInterpreter.h:274
ArrayMathProgramCode(ArrayMathFunctionPtr function)
Definition: ArrayMathInterpreter.h:110
void set_bool_array(size_t j, std::vector< bool > *array)
Definition: ArrayMathInterpreter.h:167
VMesh * get_vmesh() const
Definition: ArrayMathInterpreter.h:278
void set_vfield(VField *vfield)
Definition: ArrayMathInterpreter.h:281
bool is_double_array() const
Definition: ArrayMathInterpreter.h:299
double * get_data() const
Definition: ArrayMathInterpreter.h:263
Definition: ArrayMathInterpreter.h:106
int size
Definition: eabLatVolData.py:2
index_type get_index() const
Definition: ArrayMathInterpreter.h:215
size_type get_array_size() const
Definition: ArrayMathInterpreter.h:344