34 "complete",
"tensor",
"total",
"smolyak" };
42 "total",
"lexicographic" };
74 ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
75 int wgt_dim,
float *obj_wgts,
int *ierr) {
80 for (
int i=0; i<n; ++i) {
98 ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
99 int num_dim,
double *geom_vec,
int *ierr)
120 geom_vec[3*idx ] = i;
121 geom_vec[3*idx+1] =
j;
122 geom_vec[3*idx+2] = k;
138 int rc = Zoltan_Initialize(argc,argv,&version);
144 "This example generates the sparsity pattern for the block stochastic Galerkin matrix.\n");
146 CLP.
setOption(
"dimension", &d,
"Stochastic dimension");
148 CLP.
setOption(
"order", &p,
"Polynomial order");
149 double drop = 1.0e-12;
150 CLP.
setOption(
"drop", &drop,
"Drop tolerance");
151 bool symmetric =
true;
152 CLP.
setOption(
"symmetric",
"asymmetric", &symmetric,
"Use basis polynomials with symmetric PDF");
158 CLP.
setOption(
"product_basis", &prod_basis_type,
161 "Product basis type");
163 CLP.
setOption(
"ordering", &ordering_type,
166 "Product basis ordering");
167 double imbalance_tol = 1.2;
168 CLP.
setOption(
"imbalance", &imbalance_tol,
"Imbalance tolerance");
170 CLP.
setOption(
"full",
"linear", &full,
"Use full or linear expansion");
172 CLP.
setOption(
"tile_size", &tile_size,
"Tile size");
173 bool save_3tensor =
false;
174 CLP.
setOption(
"save_3tensor",
"no-save_3tensor", &save_3tensor,
175 "Save full 3tensor to file");
176 std::string file_3tensor =
"Cijk.dat";
177 CLP.
setOption(
"filename_3tensor", &file_3tensor,
178 "Filename to store full 3-tensor");
181 CLP.
parse( argc, argv );
185 const double alpha = 1.0;
186 const double beta = symmetric ? 1.0 : 2.0 ;
187 for (
int i=0; i<d; i++) {
189 p, alpha, beta,
true, growth_type));
198 else if (prod_basis_type ==
TENSOR) {
208 else if (prod_basis_type ==
TOTAL) {
218 else if (prod_basis_type ==
SMOLYAK) {
223 bases, index_set, drop));
227 bases, index_set, drop));
234 Cijk = basis->computeTripleProductTensor();
236 Cijk = basis->computeLinearTripleProductTensor();
238 int basis_size = basis->size();
239 std::cout <<
"basis size = " << basis_size
240 <<
" num nonzero Cijk entries = " << Cijk->num_entries()
244 std::ofstream cijk_file;
246 cijk_file.open(file_3tensor.c_str());
247 cijk_file.precision(14);
248 cijk_file.setf(std::ios::scientific);
249 cijk_file <<
"i, j, k, part" << std::endl;
253 Zoltan_Struct *zz = Zoltan_Create(MPI_COMM_WORLD);
256 Zoltan_Set_Param(zz,
"DEBUG_LEVEL",
"2");
259 Zoltan_Set_Param(zz,
"LB_METHOD",
"RCB");
261 Zoltan_Set_Param(zz,
"NUM_GID_ENTRIES",
"1");
262 Zoltan_Set_Param(zz,
"NUM_LID_ENTRIES",
"1");
264 Zoltan_Set_Param(zz,
"RETURN_LISTS",
"PARTS");
265 Zoltan_Set_Param(zz,
"OBJ_WEIGHT_DIM",
"0");
266 int num_parts = basis_size / tile_size;
267 if (num_parts * tile_size < basis_size) ++num_parts;
268 Zoltan_Set_Param(zz,
"NUM_GLOBAL_PARTS",
toString(num_parts).c_str());
269 Zoltan_Set_Param(zz,
"NUM_LOCAL_PARTS",
toString(num_parts).c_str());
270 Zoltan_Set_Param(zz,
"IMBALANCE_TOL",
toString(imbalance_tol).c_str());
272 Zoltan_Set_Param(zz,
"KEEP_CUTS",
"1");
273 Zoltan_Set_Param(zz,
"RCB_RECTILINEAR_BLOCKS",
"1");
274 Zoltan_Set_Param(zz,
"RCB_RECOMPUTE_BOX",
"1");
275 Zoltan_Set_Param(zz,
"RCB_MAX_ASPECT_RATIO",
"3");
286 int changes, numGidEntries, numLidEntries, numImport, numExport;
287 ZOLTAN_ID_PTR importGlobalGids, importLocalGids, exportGlobalGids, exportLocalGids;
288 int *importProcs, *importToPart, *exportProcs, *exportToPart;
307 std::cout <<
"num parts requested = " << num_parts
308 <<
" changes= " << changes
309 <<
" num import = " << numImport
310 <<
" num export = " << numExport << std::endl;
337 Cijk_type::k_iterator k_begin = Cijk->k_begin();
338 Cijk_type::k_iterator k_end = Cijk->k_end();
339 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
341 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
342 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
343 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
345 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
346 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
347 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
349 int part = exportToPart[idx];
351 c.
i = i; c.
j =
j; c.
k = k; c.
gid = idx;
359 int dim_max = -1, dim_min = basis_size;
360 for (
int part=0; part<num_parts; ++part) {
361 int imin = basis_size, jmin = basis_size, kmin = basis_size;
362 int imax = -1, jmax = -1, kmax = -1;
363 for (
int idx=0; idx<part_list[part].
size(); ++idx) {
364 if (part_list[part][idx].i < imin) imin = part_list[part][idx].i;
365 if (part_list[part][idx].
j < jmin) jmin = part_list[part][idx].j;
366 if (part_list[part][idx].k < kmin) kmin = part_list[part][idx].k;
367 if (part_list[part][idx].i > imax) imax = part_list[part][idx].i;
368 if (part_list[part][idx].
j > jmax) jmax = part_list[part][idx].j;
369 if (part_list[part][idx].k > kmax) kmax = part_list[part][idx].k;
371 int delta_i = imax - imin;
372 int delta_j = jmax - jmin;
373 int delta_k = kmax - kmin;
374 if (delta_i < dim_min) dim_min = delta_i;
375 if (delta_j < dim_min) dim_min = delta_j;
376 if (delta_k < dim_min) dim_min = delta_k;
377 if (delta_i > dim_max) dim_max = delta_i;
378 if (delta_j > dim_max) dim_max = delta_j;
379 if (delta_k > dim_max) dim_max = delta_k;
381 std::cout <<
"max part dimension = " << dim_max
382 <<
" min part dimension = " << dim_min << std::endl;
386 Cijk_type::k_iterator k_begin = Cijk->k_begin();
387 Cijk_type::k_iterator k_end = Cijk->k_end();
388 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
390 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
391 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
392 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
394 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
395 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
396 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
398 cijk_file << i <<
", " << j <<
", " << k <<
", "
399 << exportToPart[idx++] << std::endl;
407 Zoltan_LB_Free_Part(&importGlobalGids, &importLocalGids,
408 &importProcs, &importToPart);
409 Zoltan_LB_Free_Part(&exportGlobalGids, &exportLocalGids,
410 &exportProcs, &exportToPart);
416 catch (std::exception& e) {
417 std::cout << e.what() << std::endl;
const ProductBasisType prod_basis_type_values[]
k_iterator k_begin() const
Iterator pointing to first k entry.
SparseArrayIterator< index_iterator, value_iterator >::value_type index(const SparseArrayIterator< index_iterator, value_iterator > &it)
Multivariate orthogonal polynomial basis generated from a total order tensor product of univariate po...
void get_object_list(void *data, int sizeGID, int sizeLID, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, int wgt_dim, float *obj_wgts, int *ierr)
void get_geometry_list(void *data, int sizeGID, int sizeLID, int num_obj, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, int num_dim, double *geom_vec, int *ierr)
kj_iterator j_begin(const k_iterator &k) const
Iterator pointing to first j entry for given k.
const int num_prod_basis_types
int get_number_of_objects(void *data, int *ierr)
GrowthPolicy
Enumerated type for determining Smolyak growth policies.
const char * growth_type_names[]
const OrderingType ordering_type_values[]
const char * toString(const EReductionType reductType)
const int num_ordering_types
A comparison functor implementing a strict weak ordering based total-order ordering, recursive on the dimension.
kj_iterator j_end(const k_iterator &k) const
Iterator pointing to last j entry for given k.
Bi-directional iterator for traversing a sparse array.
RCP< const Stokhos::ProductBasis< int, double > > basis
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
const int num_growth_types
std::string toString(const HashSet< Key > &h)
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
const Stokhos::GrowthPolicy growth_type_values[]
Multivariate orthogonal polynomial basis generated from a Smolyak sparse grid.
k_iterator k_end() const
Iterator pointing to last k entry.
Multivariate orthogonal polynomial basis generated from a tensor product of univariate polynomials...
Stokhos::Sparse3Tensor< int, double > Cijk_type
int main(int argc, char **argv)
void push_back(const value_type &x)
An isotropic total order index set.
void setDocString(const char doc_string[])
A comparison functor implementing a strict weak ordering based lexographic ordering.
int get_num_geometry(void *data, int *ierr)
Stokhos::Sparse3Tensor< int, double > Cijk_type
#define TEUCHOS_ASSERT(assertion_test)
RCP< const Stokhos::Sparse3Tensor< int, double > > Cijk
kji_iterator i_begin(const kj_iterator &j) const
Iterator pointing to first i entry for given j and k.
const char * ordering_type_names[]
kji_iterator i_end(const kj_iterator &j) const
Iterator pointing to last i entry for given j and k.
const char * prod_basis_type_names[]
ordinal_type num_entries() const
Return number of non-zero entries.