Doxygen
1.9.1
|
Functions | |
template<bool parallel_construction = true, bool overwrite_loaded = false> | |
void | TasGrid::loadNeededValues (std::function< void(double const x[], double y[], size_t thread_id)> model, TasmanianSparseGrid &grid, size_t num_threads) |
Loads the current grid with model values, does not perform any refinement. More... | |
template<bool parallel_construction = true, bool overwrite_loaded = false> | |
void | TasGrid::loadNeededValues (std::function< void(std::vector< double > const &x, std::vector< double > &y, size_t thread_id)> model, TasmanianSparseGrid &grid, size_t num_threads) |
Overload that uses vectors for the model inputs and outputs. More... | |
template<bool parallel_construction = true, bool overwrite_loaded = false> | |
void | TasGrid::loadNeededPoints (std::function< void(double const x[], double y[], size_t thread_id)> model, TasmanianSparseGrid &grid, size_t num_threads) |
Alias to loadNeededValues(), array variant. | |
template<bool parallel_construction = true, bool overwrite_loaded = false> | |
void | TasGrid::loadNeededPoints (std::function< void(std::vector< double > const &x, std::vector< double > &y, size_t thread_id)> model, TasmanianSparseGrid &grid, size_t num_threads) |
Alias to loadNeededValues(), vector variant. | |
Handy templates to automate the common use case of evaluating a model at the needed (or loaded) points and feeding the values to the grid.
void TasGrid::loadNeededValues | ( | std::function< void(double const x[], double y[], size_t thread_id)> | model, |
TasmanianSparseGrid & | grid, | ||
size_t | num_threads | ||
) |
Loads the current grid with model values, does not perform any refinement.
Loads model values into the grid using the provided lambda function, the model can be computed either sequentially or in parallel. This is a non-adaptive procedure, i.e., the points will not be changes only the associated model values will be modified.
parallel_construction | defines whether to run in parallel or sequential mode. |
overwrite_loaded | defines whether to overwrite the currently loaded model values or to assign values to the needed points. |
model | is the lambda representation of a model with inputs x and outputs y, the lambda must accept arrays with size equal to the grid dimensions and outputs. For each x, the y must be overwritten with the corresponding model values. If parallel sampling is uses, then thread_id will be a unique number between 0 and num_threads-1 associated with the running thread. The id can help associate each thread with additional external resources, e.g., a separate CUDA device can be associated with each thread. |
grid | is the sparse grid that will be loaded. The grid must not be set for construction and the number of inputs must be positive. The method grid.loadNeededValues() will be called with values corresponding to the model outputs at either the loaded or the needed points. |
num_threads | is the number of parallel calls to the model lambda. If set to zero, sequential mode will be used without launching any threads, the number is ignored in sequential mode. Note that this is using the C++ native std::thread as opposed to OpenMP. |
std::runtime_error | if grid.isUsingConstruction() is true or if grid.getNumOutputs() is zero. |
Example:
void TasGrid::loadNeededValues | ( | std::function< void(std::vector< double > const &x, std::vector< double > &y, size_t thread_id)> | model, |
TasmanianSparseGrid & | grid, | ||
size_t | num_threads | ||
) |
Overload that uses vectors for the model inputs and outputs.
The template will accept the array inputs from the main implementation and copy those to the vectors. Thus, there is an extra copy of data, which is unavoidable since TasGrid::TasmanianSparseGrid returns contiguous vectors that cannot be split without copy.