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;
67 using Teuchos::rcp_dynamic_cast;
70 typedef Tpetra::CrsMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
ztcrsmatrix_t;
71 typedef Tpetra::RowMatrix<zscalar_t, zlno_t, zgno_t, znode_t>
ztrowmatrix_t;
75 template<
typename offset_t>
77 const zgno_t *rowIds,
const offset_t *offsets,
const zgno_t *colIds)
79 int rank = comm->getRank();
80 int nprocs = comm->getSize();
82 for (
int p=0; p < nprocs; p++){
84 std::cout << rank <<
":" << std::endl;
85 for (
zlno_t i=0; i < nrows; i++){
86 std::cout <<
" row " << rowIds[i] <<
": ";
87 for (offset_t j=offsets[i]; j < offsets[i+1]; j++){
88 std::cout << colIds[j] <<
" ";
90 std::cout << std::endl;
101 template <
typename User>
107 RCP<const Comm<int> > comm = M.getComm();
108 int fail = 0, gfail=0;
113 if (M.getNodeNumRows()){
120 const zgno_t *rowIds=NULL, *colIds=NULL;
121 const offset_t *offsets=NULL;
130 if (nrows != M.getNodeNumRows())
136 printMatrix<offset_t>(comm, nrows, rowIds, offsets, colIds);
146 int main(
int narg,
char *arg[])
148 Tpetra::ScopeGuard tscope(&narg, &arg);
149 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
151 int rank = comm->getRank();
152 int fail = 0, gfail=0;
157 RCP<UserInputForTests> uinput;
164 catch(std::exception &e){
166 std::cout << e.what() << std::endl;
171 RCP<ztcrsmatrix_t> tM = uinput->getUITpetraCrsMatrix();
172 RCP<ztrowmatrix_t> trM = rcp_dynamic_cast<ztrowmatrix_t>(tM);
174 RCP<ztrowmatrix_t> newM;
176 size_t nrows = trM->getNodeNumRows();
189 memset(p, 0,
sizeof(
part_t) * nrows);
190 ArrayRCP<part_t> solnParts(p, 0, nrows,
true);
192 soln_t solution(env, comm, nWeights);
193 solution.setParts(solnParts);
199 std::cout <<
"Input adapter for Tpetra::RowMatrix" << std::endl;
201 RCP<const ztrowmatrix_t> ctrM = rcp_const_cast<const ztrowmatrix_t>(
202 rcp_dynamic_cast<ztrowmatrix_t>(tM));
203 RCP<adapter_t> trMInput;
206 trMInput = rcp(
new adapter_t(ctrM));
208 catch (std::exception &e){
210 std::cout << e.what() << std::endl;
214 fail = verifyInputAdapter<ztrowmatrix_t>(*trMInput, *trM);
221 trMInput->applyPartitioningSolution(*trM, mMigrate, solution);
222 newM = rcp(mMigrate);
224 catch (std::exception &e){
226 std::cout <<
"Error caught: " << e.what() << std::endl;
232 RCP<const ztrowmatrix_t> cnewM =
233 rcp_const_cast<const ztrowmatrix_t>(newM);
234 RCP<adapter_t> newInput;
236 newInput = rcp(
new adapter_t(cnewM));
238 catch (std::exception &e){
240 std::cout << e.what() << std::endl;
246 "Input adapter for Tpetra::RowMatrix migrated to proc 0" <<
249 fail = verifyInputAdapter<ztrowmatrix_t>(*newInput, *newM);
263 std::cout <<
"PASS" << std::endl;