24 #include <Teuchos_DefaultComm.hpp>
25 #include <Teuchos_RCP.hpp>
26 #include <Teuchos_Comm.hpp>
27 #include <Teuchos_CommHelpers.hpp>
31 using Teuchos::rcp_const_cast;
34 typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
tmatrix_t;
35 typedef Xpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
xmatrix_t;
37 template<
typename offset_t>
39 const zgno_t *rowIds,
const offset_t *offsets,
const zgno_t *colIds)
41 int rank = comm->getRank();
42 int nprocs = comm->getSize();
44 for (
int p=0; p < nprocs; p++){
46 std::cout << rank <<
":" << std::endl;
47 for (
zlno_t i=0; i < nrows; i++){
48 std::cout <<
" row " << rowIds[i] <<
": ";
49 for (offset_t j=offsets[i]; j < offsets[i+1]; j++){
50 std::cout << colIds[j] <<
" ";
52 std::cout << std::endl;
61 template <
typename User>
67 RCP<const Comm<int> > comm = M.getComm();
68 int fail = 0, gfail=0;
73 if (M.getLocalNumRows()){
81 ArrayRCP<const zgno_t> colIds;
82 ArrayRCP<const offset_t> offsets;
91 if (nrows != M.getLocalNumRows())
97 printMatrix<offset_t>(comm, nrows, rowIds, offsets.getRawPtr(), colIds.getRawPtr());
100 if (!fail) fail = 10;
106 int main(
int narg,
char *arg[])
108 Tpetra::ScopeGuard tscope(&narg, &arg);
109 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
111 int rank = comm->getRank();
112 int fail = 0, gfail=0;
118 RCP<UserInputForTests> uinput;
119 Teuchos::ParameterList params;
120 params.set(
"input file",
"simple");
121 params.set(
"file type",
"Chaco");
126 catch(std::exception &e){
128 std::cout << e.what() << std::endl;
135 tM = uinput->getUITpetraCrsMatrix();
136 size_t nrows = tM->getLocalNumRows();
148 part_t *p =
new part_t [nrows];
149 memset(p, 0,
sizeof(part_t) * nrows);
150 ArrayRCP<part_t> solnParts(p, 0, nrows,
true);
152 soln_t solution(env, comm, nWeights);
153 solution.setParts(solnParts);
159 std::cout <<
"Input adapter for Tpetra::CrsMatrix" << std::endl;
161 RCP<const tmatrix_t> ctM = rcp_const_cast<
const tmatrix_t>(tM);
162 RCP<Zoltan2::XpetraCrsMatrixAdapter<tmatrix_t> > tMInput;
168 catch (std::exception &e){
170 std::cout << e.what() << std::endl;
174 fail = verifyInputAdapter<tmatrix_t>(*tMInput, *tM);
181 tMInput->applyPartitioningSolution(*tM, mMigrate, solution);
182 newM = rcp(mMigrate);
184 catch (std::exception &e){
186 std::cout <<
"Error caught: " << e.what() << std::endl;
192 RCP<const tmatrix_t> cnewM = rcp_const_cast<
const tmatrix_t>(newM);
193 RCP<Zoltan2::XpetraCrsMatrixAdapter<tmatrix_t> > newInput;
197 catch (std::exception &e){
199 std::cout << e.what() << std::endl;
205 "Input adapter for Tpetra::CrsMatrix migrated to proc 0" <<
208 fail = verifyInputAdapter<tmatrix_t>(*newInput, *newM);
209 if (fail) fail += 100;
222 std::cout <<
"Input adapter for Xpetra::CrsMatrix" << std::endl;
224 RCP<xmatrix_t> xM = uinput->getUIXpetraCrsMatrix();
225 RCP<const xmatrix_t> cxM = rcp_const_cast<
const xmatrix_t>(xM);
226 RCP<Zoltan2::XpetraCrsMatrixAdapter<xmatrix_t> > xMInput;
232 catch (std::exception &e){
234 std::cout << e.what() << std::endl;
238 fail = verifyInputAdapter<xmatrix_t>(*xMInput, *tM);
245 xMInput->applyPartitioningSolution(*xM, mMigrate, solution);
247 catch (std::exception &e){
248 std::cout <<
"Error caught: " << e.what() << std::endl;
255 RCP<const xmatrix_t> cnewM(mMigrate);
256 RCP<Zoltan2::XpetraCrsMatrixAdapter<xmatrix_t> > newInput;
261 catch (std::exception &e){
263 std::cout << e.what() << std::endl;
269 "Input adapter for Xpetra::CrsMatrix migrated to proc 0" <<
272 fail = verifyInputAdapter<xmatrix_t>(*newInput, *newM);
273 if (fail) fail += 100;
282 #ifdef HAVE_EPETRA_DATA_TYPES
285 typedef Epetra_CrsMatrix ematrix_t;
288 std::cout <<
"Input adapter for Epetra_CrsMatrix" << std::endl;
290 RCP<ematrix_t> eM = uinput->getUIEpetraCrsMatrix();
291 RCP<const ematrix_t> ceM = rcp_const_cast<
const ematrix_t>(eM);
292 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > eMInput;
294 bool goodAdapter =
true;
299 catch (std::exception &e){
300 if (std::is_same<znode_t, Xpetra::EpetraNode>::value) {
303 std::cout << e.what() << std::endl;
308 std::cout <<
"Node type is not supported by Xpetra's Epetra interface;"
309 <<
" Skipping this test." << std::endl;
310 std::cout <<
"FYI: Here's the exception message: " << std::endl
311 << e.what() << std::endl;
318 fail = verifyInputAdapter<ematrix_t>(*eMInput, *tM);
323 ematrix_t *mMigrate =NULL;
325 eMInput->applyPartitioningSolution(*eM, mMigrate, solution);
327 catch (std::exception &e){
328 std::cout <<
"Error caught: " << e.what() << std::endl;
335 RCP<const ematrix_t> cnewM(mMigrate,
true);
336 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > newInput;
341 catch (std::exception &e){
343 std::cout << e.what() << std::endl;
349 "Input adapter for Epetra_CrsMatrix migrated to proc 0" <<
352 fail = verifyInputAdapter<ematrix_t>(*newInput, *newM);
353 if (fail) fail += 100;
368 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