13 #include "Isorropia_Epetra.hpp"
14 #include "Isorropia_EpetraPartitioner.hpp"
42 "hermite",
"legendre",
"clenshaw-curtis",
"gauss-patterson",
"rys",
"jacobi" };
56 "complete",
"tensor",
"total",
"smolyak" };
64 "total",
"lexicographic" };
85 MPI_Init(&argc,&argv);
91 "This example generates the sparsity pattern for the block stochastic Galerkin matrix.\n");
93 CLP.
setOption(
"dimension", &d,
"Stochastic dimension");
95 CLP.
setOption(
"order", &p,
"Polynomial order");
96 double drop = 1.0e-12;
97 CLP.
setOption(
"drop", &drop,
"Drop tolerance");
98 std::string file =
"A.mm";
99 CLP.
setOption(
"filename", &file,
"Matrix Market filename");
109 CLP.
setOption(
"product_basis", &prod_basis_type,
112 "Product basis type");
114 CLP.
setOption(
"ordering", &ordering_type,
117 "Product basis ordering");
119 CLP.
setOption(
"partitioning", &partitioning_type,
122 "Partitioning Method");
123 double imbalance_tol = 1.0;
124 CLP.
setOption(
"imbalance", &imbalance_tol,
"Imbalance tolerance");
126 CLP.
setOption(
"alpha", &alpha,
"Jacobi alpha index");
128 CLP.
setOption(
"beta", &beta,
"Jacobi beta index");
130 CLP.
setOption(
"full",
"linear", &full,
"Use full or linear expansion");
132 CLP.
setOption(
"tile_size", &tile_size,
"Tile size");
133 bool save_3tensor =
false;
134 CLP.
setOption(
"save_3tensor",
"no-save_3tensor", &save_3tensor,
135 "Save full 3tensor to file");
136 std::string file_3tensor =
"Cijk.dat";
137 CLP.
setOption(
"filename_3tensor", &file_3tensor,
138 "Filename to store full 3-tensor");
141 CLP.
parse( argc, argv );
145 for (
int i=0; i<d; i++) {
148 p,
true, growth_type));
151 p,
true, growth_type));
160 else if (basis_type ==
RYS)
162 p, 1.0,
true, growth_type));
163 else if (basis_type ==
JACOBI)
165 p, alpha, beta,
true, growth_type));
174 else if (prod_basis_type ==
TENSOR) {
185 else if (prod_basis_type ==
TOTAL) {
195 else if (prod_basis_type ==
SMOLYAK) {
200 bases, index_set, drop));
204 bases, index_set, drop));
211 Cijk = basis->computeTripleProductTensor();
213 Cijk = basis->computeLinearTripleProductTensor();
215 int basis_size = basis->size();
216 std::cout <<
"basis size = " << basis_size
217 <<
" num nonzero Cijk entries = " << Cijk->num_entries()
227 std::ofstream cijk_file;
229 cijk_file.open(file_3tensor.c_str());
230 cijk_file.precision(14);
231 cijk_file.setf(std::ios::scientific);
232 cijk_file <<
"i, j, k, part" << std::endl;
236 if (partitioning_type ==
RCB) {
238 int num_cijk_entries = Cijk->num_entries();
242 Cijk_type::k_iterator k_begin = Cijk->k_begin();
243 Cijk_type::k_iterator k_end = Cijk->k_end();
244 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
246 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
247 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
248 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
250 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
251 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
252 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it) {
254 ijk_triples[0][idx] = i;
255 ijk_triples[1][idx] =
j;
256 ijk_triples[2][idx] = k;
264 params.
set(
"partitioning method",
"rcb");
265 int num_parts = num_cijk_entries / tile_size;
266 if (num_cijk_entries % tile_size > 0)
268 std::stringstream ss;
270 params.
set<std::string>(
"num parts", ss.str());
272 rcp(&ijk_triples,
false);
273 Isorropia::Epetra::Partitioner partitioner(ijk_triples_rcp, params);
274 partitioner.compute();
276 std::cout <<
"num parts requested = " << num_parts
277 <<
" num parts computed = " << partitioner.numProperties() << std::endl;
279 parts.
resize(num_cijk_entries);
281 partitioner.extractPartsCopy(num_cijk_entries, sz, &parts[0]);
286 for (
int i=0; i<num_cijk_entries; ++i) {
287 cijk_file << ijk_triples[0][i] <<
", "
288 << ijk_triples[1][i] <<
", "
289 << ijk_triples[2][i] <<
", "
290 << parts[i] << std::endl;
295 else if (partitioning_type ==
HG_MATRIX) {
306 params.
set(
"partitioning method",
"hypergraph");
308 int num_parts = comm.
NumProc();
309 std::stringstream ss;
311 params.
set<std::string>(
"num parts", ss.str());
312 std::stringstream ss2;
313 ss2 << imbalance_tol;
314 params.
set<std::string>(
"imbalance tol", ss2.str());
339 std::cout << permuted_map << std::endl;
345 EpetraExt::RowMatrixToMatrixMarketFile(file.c_str(), mat);
349 Cijk_type::k_iterator k_begin = Cijk->k_begin();
350 Cijk_type::k_iterator k_end = Cijk->k_end();
351 for (Cijk_type::k_iterator k_it=k_begin; k_it!=k_end; ++k_it) {
353 Cijk_type::kj_iterator j_begin = Cijk->j_begin(k_it);
354 Cijk_type::kj_iterator j_end = Cijk->j_end(k_it);
355 for (Cijk_type::kj_iterator j_it = j_begin; j_it != j_end; ++j_it) {
357 Cijk_type::kji_iterator i_begin = Cijk->i_begin(j_it);
358 Cijk_type::kji_iterator i_end = Cijk->i_end(j_it);
359 for (Cijk_type::kji_iterator i_it = i_begin; i_it != i_end; ++i_it){
361 cijk_file << i <<
", " << j <<
", " << k <<
", " << parts[i]
376 catch (std::exception& e) {
377 std::cout << e.what() << std::endl;
const ProductBasisType prod_basis_type_values[]
Hermite polynomial basis.
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...
const char * basis_type_names[]
const BasisType basis_type_values[]
Teuchos::RCP< const Epetra_CrsGraph > getStochasticGraph() const
Get stochastic graph.
const int num_prod_basis_types
GrowthPolicy
Enumerated type for determining Smolyak growth policies.
const char * growth_type_names[]
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
const OrderingType ordering_type_values[]
const char * partitioning_type_names[]
const int num_ordering_types
A comparison functor implementing a strict weak ordering based total-order ordering, recursive on the dimension.
Teuchos::RCP< const EpetraExt::MultiComm > buildMultiComm(const Epetra_Comm &globalComm, int num_global_stochastic_blocks, int num_spatial_procs=-1)
int FillComplete(bool OptimizeDataStorage=true)
int PutScalar(double ScalarConstant)
Legendre polynomial basis using Gauss-Patterson quadrature points.
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
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
void resize(size_type new_size, const value_type &x=value_type())
const int num_partitioning_types
const Stokhos::GrowthPolicy growth_type_values[]
Multivariate orthogonal polynomial basis generated from a Smolyak sparse grid.
Multivariate orthogonal polynomial basis generated from a tensor product of univariate polynomials...
Legendre polynomial basis.
Stokhos::Sparse3Tensor< int, double > Cijk_type
int main(int argc, char **argv)
An isotropic total order index set.
Legendre polynomial basis using Clenshaw-Curtis quadrature points.
void setDocString(const char doc_string[])
A comparison functor implementing a strict weak ordering based lexographic ordering.
const int num_basis_types
#define TEUCHOS_ASSERT(assertion_test)
const char * ordering_type_names[]
const char * prod_basis_type_names[]
const PartitioningType partitioning_type_values[]