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())
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);
191 std::cout <<
"Input adapter for Tpetra::CrsMatrix" << std::endl;
193 RCP<const tmatrix_t> ctM = rcp_const_cast<
const tmatrix_t>(tM);
194 RCP<Zoltan2::XpetraCrsMatrixAdapter<tmatrix_t> > tMInput;
200 catch (std::exception &e){
202 std::cout << e.what() << 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);
254 std::cout <<
"Input adapter for Xpetra::CrsMatrix" << std::endl;
256 RCP<xmatrix_t> xM = uinput->getUIXpetraCrsMatrix();
257 RCP<const xmatrix_t> cxM = rcp_const_cast<
const xmatrix_t>(xM);
258 RCP<Zoltan2::XpetraCrsMatrixAdapter<xmatrix_t> > xMInput;
264 catch (std::exception &e){
266 std::cout << e.what() << 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);
314 #ifdef HAVE_EPETRA_DATA_TYPES 317 typedef Epetra_CrsMatrix ematrix_t;
320 std::cout <<
"Input adapter for Epetra_CrsMatrix" << std::endl;
322 RCP<ematrix_t> eM = uinput->getUIEpetraCrsMatrix();
323 RCP<const ematrix_t> ceM = rcp_const_cast<
const ematrix_t>(eM);
324 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > eMInput;
326 bool goodAdapter =
true;
331 catch (std::exception &e){
332 if (std::is_same<znode_t, Xpetra::EpetraNode>::value) {
335 std::cout << e.what() << std::endl;
340 std::cout <<
"Node type is not supported by Xpetra's Epetra interface;" 341 <<
" Skipping this test." << std::endl;
342 std::cout <<
"FYI: Here's the exception message: " << std::endl
343 << e.what() << std::endl;
350 fail = verifyInputAdapter<ematrix_t>(*eMInput, *tM);
355 ematrix_t *mMigrate =NULL;
357 eMInput->applyPartitioningSolution(*eM, mMigrate, solution);
359 catch (std::exception &e){
360 cout <<
"Error caught: " << e.what() << endl;
367 RCP<const ematrix_t> cnewM(mMigrate,
true);
368 RCP<Zoltan2::XpetraCrsMatrixAdapter<ematrix_t> > newInput;
373 catch (std::exception &e){
375 std::cout << e.what() << std::endl;
381 "Input adapter for Epetra_CrsMatrix migrated to proc 0" <<
384 fail = verifyInputAdapter<ematrix_t>(*newInput, *newM);
400 std::cout <<
"PASS" << std::endl;
int globalFail(const RCP< const Comm< int > > &comm, int fail)
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
size_t getLocalNumColumns() const
Returns the number of columns on this process.
size_t getLocalNumRows() const
Returns the number of rows on this process.
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
common code used by tests
Defines the XpetraCrsMatrixAdapter class.
A PartitioningSolution is a solution to a partitioning problem.
void getCRSView(const lno_t *&offsets, const gno_t *&colIds) const
Sets pointers to this process' matrix entries using compressed sparse row (CRS) format. All matrix adapters must implement either getCRSView or getCCSView, but implementation of both is not required.
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
static const std::string fail
void getRowIDsView(const gno_t *&rowIds) const
Sets pointer to this process' rows' global IDs.
void printFailureCode(const RCP< const Comm< int > > &comm, int fail)
std::string testDataFilePath(".")