59 #include <Teuchos_DefaultComm.hpp>
60 #include <Teuchos_RCP.hpp>
61 #include <Teuchos_Comm.hpp>
62 #include <Teuchos_CommHelpers.hpp>
66 using Teuchos::rcp_const_cast;
69 typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
tmatrix_t;
70 typedef Xpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
xmatrix_t;
72 template<
typename offset_t>
74 const zgno_t *rowIds,
const offset_t *offsets,
const zgno_t *colIds)
76 int rank = comm->getRank();
77 int nprocs = comm->getSize();
79 for (
int p=0; p < nprocs; p++){
81 std::cout << rank <<
":" << std::endl;
82 for (
zlno_t i=0; i < nrows; i++){
83 std::cout <<
" row " << rowIds[i] <<
": ";
84 for (offset_t j=offsets[i]; j < offsets[i+1]; j++){
85 std::cout << colIds[j] <<
" ";
87 std::cout << std::endl;
96 template <
typename User>
102 RCP<const Comm<int> > comm = M.getComm();
103 int fail = 0, gfail=0;
108 if (M.getLocalNumRows()){
115 const zgno_t *rowIds=NULL;
116 ArrayRCP<const zgno_t> colIds;
117 ArrayRCP<const offset_t> offsets;
126 if (nrows != M.getLocalNumRows())
132 printMatrix<offset_t>(comm, nrows, rowIds, offsets.getRawPtr(), colIds.getRawPtr());
135 if (!fail) fail = 10;
141 int main(
int narg,
char *arg[])
143 Tpetra::ScopeGuard tscope(&narg, &arg);
144 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
146 int rank = comm->getRank();
147 int fail = 0, gfail=0;
153 RCP<UserInputForTests> uinput;
154 Teuchos::ParameterList params;
155 params.set(
"input file",
"simple");
156 params.set(
"file type",
"Chaco");
161 catch(std::exception &e){
163 std::cout << e.what() << std::endl;
170 tM = uinput->getUITpetraCrsMatrix();
171 size_t nrows = tM->getLocalNumRows();
183 part_t *p =
new part_t [nrows];
184 memset(p, 0,
sizeof(part_t) * nrows);
185 ArrayRCP<part_t> solnParts(p, 0, nrows,
true);
187 soln_t solution(env, comm, nWeights);
188 solution.setParts(solnParts);
194 std::cout <<
"Input adapter for Tpetra::CrsMatrix" << std::endl;
196 RCP<const tmatrix_t> ctM = rcp_const_cast<
const tmatrix_t>(tM);
197 RCP<Zoltan2::XpetraCrsMatrixAdapter<tmatrix_t> > tMInput;
203 catch (std::exception &e){
205 std::cout << e.what() << std::endl;
209 fail = verifyInputAdapter<tmatrix_t>(*tMInput, *tM);
216 tMInput->applyPartitioningSolution(*tM, mMigrate, solution);
217 newM = rcp(mMigrate);
219 catch (std::exception &e){
221 std::cout <<
"Error caught: " << e.what() << std::endl;
227 RCP<const tmatrix_t> cnewM = rcp_const_cast<
const tmatrix_t>(newM);
228 RCP<Zoltan2::XpetraCrsMatrixAdapter<tmatrix_t> > newInput;
232 catch (std::exception &e){
234 std::cout << e.what() << std::endl;
240 "Input adapter for Tpetra::CrsMatrix migrated to proc 0" <<
243 fail = verifyInputAdapter<tmatrix_t>(*newInput, *newM);
244 if (fail) fail += 100;
257 std::cout <<
"Input adapter for Xpetra::CrsMatrix" << std::endl;
259 RCP<xmatrix_t> xM = uinput->getUIXpetraCrsMatrix();
260 RCP<const xmatrix_t> cxM = rcp_const_cast<
const xmatrix_t>(xM);
261 RCP<Zoltan2::XpetraCrsMatrixAdapter<xmatrix_t> > xMInput;
267 catch (std::exception &e){
269 std::cout << e.what() << std::endl;
273 fail = verifyInputAdapter<xmatrix_t>(*xMInput, *tM);
280 xMInput->applyPartitioningSolution(*xM, mMigrate, solution);
282 catch (std::exception &e){
283 std::cout <<
"Error caught: " << e.what() << std::endl;
290 RCP<const xmatrix_t> cnewM(mMigrate);
291 RCP<Zoltan2::XpetraCrsMatrixAdapter<xmatrix_t> > newInput;
296 catch (std::exception &e){
298 std::cout << e.what() << std::endl;
304 "Input adapter for Xpetra::CrsMatrix migrated to proc 0" <<
307 fail = verifyInputAdapter<xmatrix_t>(*newInput, *newM);
308 if (fail) fail += 100;
317 #ifdef HAVE_EPETRA_DATA_TYPES
320 typedef Epetra_CrsMatrix ematrix_t;
323 std::cout <<
"Input adapter for Epetra_CrsMatrix" << std::endl;
325 RCP<ematrix_t> eM = uinput->getUIEpetraCrsMatrix();
326 RCP<const ematrix_t> ceM = rcp_const_cast<
const ematrix_t>(eM);
327 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > eMInput;
329 bool goodAdapter =
true;
334 catch (std::exception &e){
335 if (std::is_same<znode_t, Xpetra::EpetraNode>::value) {
338 std::cout << e.what() << std::endl;
343 std::cout <<
"Node type is not supported by Xpetra's Epetra interface;"
344 <<
" Skipping this test." << std::endl;
345 std::cout <<
"FYI: Here's the exception message: " << std::endl
346 << e.what() << std::endl;
353 fail = verifyInputAdapter<ematrix_t>(*eMInput, *tM);
358 ematrix_t *mMigrate =NULL;
360 eMInput->applyPartitioningSolution(*eM, mMigrate, solution);
362 catch (std::exception &e){
363 std::cout <<
"Error caught: " << e.what() << std::endl;
370 RCP<const ematrix_t> cnewM(mMigrate,
true);
371 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > newInput;
376 catch (std::exception &e){
378 std::cout << e.what() << std::endl;
384 "Input adapter for Epetra_CrsMatrix migrated to proc 0" <<
387 fail = verifyInputAdapter<ematrix_t>(*newInput, *newM);
388 if (fail) fail += 100;
403 std::cout <<
"PASS" << std::endl;
void printFailureCode(const Comm< int > &comm, int fail)
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
size_t getLocalNumColumns() const
Returns the number of columns on this process.
void getCRSView(ArrayRCP< const offset_t > &offsets, ArrayRCP< const gno_t > &colIds) const
int main(int narg, char **arg)
common code used by tests
SparseMatrixAdapter_t::part_t part_t
Defines the XpetraCrsMatrixAdapter class.
A PartitioningSolution is a solution to a partitioning problem.
size_t getLocalNumRows() const
Returns the number of rows on this process.
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
Tpetra::Map::local_ordinal_type zlno_t
static const std::string fail
int globalFail(const Comm< int > &comm, int fail)
Tpetra::Map::global_ordinal_type zgno_t
void getRowIDsView(const gno_t *&rowIds) const