59 #include <Teuchos_GlobalMPISession.hpp> 60 #include <Teuchos_DefaultComm.hpp> 61 #include <Teuchos_RCP.hpp> 62 #include <Teuchos_Comm.hpp> 63 #include <Teuchos_CommHelpers.hpp> 68 using Teuchos::rcp_const_cast;
70 using Teuchos::DefaultComm;
72 typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
tmatrix_t;
73 typedef Xpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
xmatrix_t;
78 int rank = comm->getRank();
79 int nprocs = comm->getSize();
81 for (
int p=0; p < nprocs; p++){
83 std::cout << rank <<
":" << std::endl;
84 for (
zlno_t i=0; i < nrows; i++){
85 std::cout <<
" row " << rowIds[i] <<
": ";
86 for (
zlno_t j=offsets[i]; j < offsets[i+1]; j++){
87 std::cout << colIds[j] <<
" ";
89 std::cout << std::endl;
98 template <
typename User>
102 RCP<const Comm<int> > comm = M.getComm();
103 int fail = 0, gfail=0;
108 if (M.getNodeNumRows()){
115 const zgno_t *rowIds=NULL, *colIds=NULL;
116 const zlno_t *offsets=NULL;
125 if (nrows != M.getNodeNumRows())
134 if (!fail) fail = 10;
140 int main(
int argc,
char *argv[])
142 Teuchos::GlobalMPISession session(&argc, &argv);
143 RCP<const Comm<int> > comm = DefaultComm<int>::getComm();
144 int rank = comm->getRank();
145 int fail = 0, gfail=0;
151 RCP<UserInputForTests> uinput;
158 catch(std::exception &e){
160 std::cout << e.what() << std::endl;
167 tM = uinput->getUITpetraCrsMatrix();
168 size_t nrows = tM->getNodeNumRows();
178 typedef adapter_t::part_t part_t;
180 part_t *p =
new part_t [nrows];
181 memset(p, 0,
sizeof(part_t) * nrows);
182 ArrayRCP<part_t> solnParts(p, 0, nrows,
true);
184 soln_t solution(env, comm, nWeights);
185 solution.setParts(solnParts);
190 RCP<const tmatrix_t> ctM = rcp_const_cast<
const tmatrix_t>(tM);
191 RCP<Zoltan2::XpetraCrsMatrixAdapter<tmatrix_t> > tMInput;
197 catch (std::exception &e){
199 std::cout << e.what() << std::endl;
204 std::cout <<
"Input adapter for Tpetra::CrsMatrix" << std::endl;
206 fail = verifyInputAdapter<tmatrix_t>(*tMInput, *tM);
213 tMInput->applyPartitioningSolution(*tM, mMigrate, solution);
214 newM = rcp(mMigrate);
216 catch (std::exception &e){
218 cout <<
"Error caught: " << e.what() << endl;
224 RCP<const tmatrix_t> cnewM = rcp_const_cast<
const tmatrix_t>(newM);
225 RCP<Zoltan2::XpetraCrsMatrixAdapter<tmatrix_t> > newInput;
229 catch (std::exception &e){
231 std::cout << e.what() << std::endl;
237 "Input adapter for Tpetra::CrsMatrix migrated to proc 0" <<
240 fail = verifyInputAdapter<tmatrix_t>(*newInput, *newM);
241 if (fail) fail += 100;
253 RCP<xmatrix_t> xM = uinput->getUIXpetraCrsMatrix();
254 RCP<const xmatrix_t> cxM = rcp_const_cast<
const xmatrix_t>(xM);
255 RCP<Zoltan2::XpetraCrsMatrixAdapter<xmatrix_t> > xMInput;
261 catch (std::exception &e){
263 std::cout << e.what() << std::endl;
268 std::cout <<
"Input adapter for Xpetra::CrsMatrix" << std::endl;
270 fail = verifyInputAdapter<xmatrix_t>(*xMInput, *tM);
277 xMInput->applyPartitioningSolution(*xM, mMigrate, solution);
279 catch (std::exception &e){
280 cout <<
"Error caught: " << e.what() << endl;
287 RCP<const xmatrix_t> cnewM(mMigrate);
288 RCP<Zoltan2::XpetraCrsMatrixAdapter<xmatrix_t> > newInput;
293 catch (std::exception &e){
295 std::cout << e.what() << std::endl;
301 "Input adapter for Xpetra::CrsMatrix migrated to proc 0" <<
304 fail = verifyInputAdapter<xmatrix_t>(*newInput, *newM);
305 if (fail) fail += 100;
314 #ifdef HAVE_EPETRA_DATA_TYPES 317 typedef Epetra_CrsMatrix ematrix_t;
319 RCP<ematrix_t> eM = uinput->getUIEpetraCrsMatrix();
320 RCP<const ematrix_t> ceM = rcp_const_cast<
const ematrix_t>(eM);
321 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > eMInput;
327 catch (std::exception &e){
329 std::cout << e.what() << std::endl;
334 std::cout <<
"Input adapter for Epetra_CrsMatrix" << std::endl;
336 fail = verifyInputAdapter<ematrix_t>(*eMInput, *tM);
341 ematrix_t *mMigrate =NULL;
343 eMInput->applyPartitioningSolution(*eM, mMigrate, solution);
345 catch (std::exception &e){
346 cout <<
"Error caught: " << e.what() << endl;
353 RCP<const ematrix_t> cnewM(mMigrate,
true);
354 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > newInput;
359 catch (std::exception &e){
361 std::cout << e.what() << std::endl;
367 "Input adapter for Epetra_CrsMatrix migrated to proc 0" <<
370 fail = verifyInputAdapter<ematrix_t>(*newInput, *newM);
371 if (fail) fail += 100;
385 std::cout <<
"PASS" << std::endl;
int globalFail(const RCP< const Comm< int > > &comm, int fail)
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
void getCRSView(const lno_t *&offsets, const gno_t *&colIds) const
size_t getLocalNumColumns() const
Returns the number of columns on this process.
common code used by tests
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...
static const std::string fail
void printFailureCode(const RCP< const Comm< int > > &comm, int fail)
void getRowIDsView(const gno_t *&rowIds) const
std::string testDataFilePath(".")