26 #include <queso/InterpolationSurrogateBuilder.h> 
   29 #include <queso/MpiComm.h> 
   30 #include <queso/GslVector.h> 
   31 #include <queso/GslMatrix.h> 
   32 #include <queso/InterpolationSurrogateHelper.h> 
   33 #include <queso/StreamUtilities.h> 
   40   template<
class V, 
class M>
 
   44     m_njobs(this->get_default_data().get_paramDomain().env().numSubEnvironments(), 0)
 
   49   template<
class V, 
class M>
 
   53     unsigned int n_values = this->get_default_data().n_values();
 
   54     unsigned int n_workers = this->get_default_data().get_paramDomain().env().numSubEnvironments();
 
   56     unsigned int n_jobs = n_values/n_workers;
 
   57     unsigned int n_leftover = this->get_default_data().n_values() % n_workers;
 
   63         for(
unsigned int n = 0; n < n_workers; n++)
 
   64           this->m_njobs[n] = n_jobs;
 
   69         for(
unsigned int n = 0; n < n_workers; n++)
 
   72               this->m_njobs[n] = n_jobs+1;
 
   74               this->m_njobs[n] = n_jobs;
 
   82   template<
class V, 
class M>
 
   85     unsigned int n_begin, n_end;
 
   86     this->set_work_bounds( n_begin, n_end );
 
   89     std::vector<unsigned int> local_n(n_end-n_begin);
 
   92     std::vector<std::vector<double> > local_values(this->m_data.size());
 
   93     for( std::vector<std::vector<double> >::iterator 
it = local_values.begin();
 
   94          it != local_values.end(); ++
it )
 
   95       it->resize(n_end-n_begin);
 
   97     unsigned int count = 0;
 
  100     V domain_vector(this->get_default_data().get_paramDomain().vectorSpace().zeroVector());
 
  103     std::vector<double> values(this->m_data.size());
 
  105     for( 
unsigned int n = n_begin; n < n_end; n++ )
 
  107         this->set_domain_vector( n, domain_vector );
 
  109         this->evaluate_model( domain_vector, values );
 
  113         for( 
unsigned int s = 0; s < this->m_data.size(); s++ )
 
  114           local_values[s][count] = values[s];
 
  122     for( 
unsigned int s = 0; s < this->m_data.size(); s++ )
 
  123       this->sync_data( local_n, local_values[s], this->m_data.get_dataset(s) );
 
  126   template<
class V, 
class M>
 
  129     unsigned int my_subid = this->get_default_data().get_paramDomain().env().subId();
 
  133     for( 
unsigned int n = 0; n < my_subid; n++ )
 
  134       n_begin += m_njobs[n];
 
  136     n_end = n_begin + m_njobs[my_subid];
 
  139   template<
class V, 
class M>
 
  141                                                       std::vector<double>& local_values,
 
  147     if( my_subrank == 0 )
 
  149         std::vector<double> all_values(data.
n_values());
 
  151         std::vector<unsigned int> all_indices(data.
n_values());
 
  153         std::vector<int> strides;
 
  154         this->compute_strides( strides );
 
  160         inter0comm.template Gatherv<unsigned int>(&local_n[0], local_n.size(),
 
  161             &all_indices[0], &m_njobs[0], &strides[0],
 
  162             0 , 
"InterpolationSurrogateBuilder::sync_data()",
 
  163             "MpiComm::gatherv() failed!");
 
  165         inter0comm.template Gatherv<double>(&local_values[0],
 
  166             local_values.size(), &all_values[0], &m_njobs[0], &strides[0],
 
  167             0 , 
"InterpolationSurrogateBuilder::sync_data()",
 
  168             "MpiComm::gatherv() failed!");
 
  177             for( 
unsigned int n = 0; n < data.
n_values(); n++ )
 
  178               data.
set_value( all_indices[n], all_values[n] );
 
  186   template<
class V, 
class M>
 
  190     std::vector<unsigned int> indices(this->get_default_data().
dim());
 
  194     for( 
unsigned int d = 0; d < this->get_default_data().dim(); d++ )
 
  196         domain_vector[d] = this->get_default_data().get_x( d, indices[d] );
 
  200   template<
class V, 
class M>
 
  203     unsigned int n_subenvs = this->get_default_data().get_paramDomain().env().numSubEnvironments();
 
  205     strides.resize(n_subenvs);
 
  211     for( 
unsigned int n = 1; n < n_subenvs; n++ )
 
  216         stride += this->m_njobs[n-1];
 
InterpolationSurrogateBuilder()
 
void partition_work()
Partition the workload of model evaluations across the subenvironments. 
 
void sync_values(unsigned int root)
Sync values across all processors from root processor. 
 
Container class for multiple, consistent InterpolationSurrogateData objects. 
 
void sync_data(std::vector< unsigned int > &local_n, std::vector< double > &local_values, InterpolationSurrogateData< V, M > &data)
Take the local values computed from each process and communicate. 
 
void set_domain_vector(unsigned int n, V &domain_vector) const 
Provide the spatial coordinates for the global index n. 
 
void build_values()
Execute the user's model and populate m_values for the given n_points. 
 
void compute_strides(std::vector< int > &strides) const 
Helper function to compute strides needed for MPI_Gatherv. 
 
Base class for builders of surrogates. 
 
that you receive source code or can get it if you want it
 
#define queso_assert_equal_to(expr1, expr2)
 
const BoxSubset< V, M > & get_paramDomain() const 
 
The QUESO MPI Communicator Class. 
 
void set_value(unsigned int n, double value)
 
unsigned int n_values() const 
 
Build interpolation-based surrogate. 
 
void set_work_bounds(unsigned int &n_begin, unsigned int &n_end) const 
Set the starting and ending global indices for the current subenvironment. 
 
static void globalToCoord(unsigned int global, const std::vector< unsigned int > &n_points, std::vector< unsigned int > &coord_indices)
Inverse of coordToGlobal map.