10 #ifndef _ZOLTAN2_ALGMATRIX_HPP_
11 #define _ZOLTAN2_ALGMATRIX_HPP_
44 template <
typename Adapter>
63 const RCP<
const Comm<int> > &_problemComm,
65 : mEnv(_env), mProblemComm(_problemComm), mMatrixAdapter(_matrixAdapter)
80 const RCP<const Environment> mEnv;
81 const RCP<const Comm<int> > mProblemComm;
83 const RCP<const MatrixAdapter<user_t, userCoord_t> > mMatrixAdapter;
100 template <
typename Adapter>
105 int myrank = mEnv->myRank_;
106 int nprocs = mEnv->numProcs_;
112 int procDim = sqrt(nprocs);
113 assert(procDim * procDim == nprocs);
115 int myProcRow = myrank / procDim;
116 int myProcCol = myrank % procDim;
126 Teuchos::ParameterList params1D(
"Params for 1D partitioning");
128 params1D.set(
"algorithm",
"block");
129 params1D.set(
"imbalance_tolerance", 1.1);
130 params1D.set(
"num_global_parts", procDim);
178 mMatrixAdapter->getRowIDsView(rowIds);
180 size_t nLocIDs = mMatrixAdapter->getLocalNumRows();
182 std::vector<std::vector<gno_t> > idsInProcColI(procDim);
183 Teuchos::ArrayRCP<gno_t> colIDs;
185 for(
size_t i=0; i<nLocIDs; i++)
189 idsInProcColI[ parts[i] ].push_back(rowIds[i]);
201 for(
int procColI=0; procColI<procDim; procColI++)
207 if(myProcCol==procColI && myProcRow==0)
209 assert(myrank==procColI);
212 std::set<gno_t> gidSet;
217 for(
int i=0;i<idsInProcColI[procColI].size();i++)
219 gidSet.insert(idsInProcColI[procColI][i]);
226 std::vector<gno_t> recvBuf;
227 for(
int src=0;src<nprocs;src++)
233 Teuchos::receive<int,int>(*mProblemComm, src, 1, &buffSize);
237 recvBuf.resize(buffSize);
239 Teuchos::receive<int,gno_t>(*mProblemComm, src, buffSize, recvBuf.data());
241 for(
int i=0;i<buffSize;i++)
243 gidSet.insert(recvBuf[i]);
253 colIDs.resize(gidSet.size());
255 typename std::set<gno_t>::const_iterator iter;
257 for (iter=gidSet.begin(); iter!=gidSet.end(); ++iter)
259 colIDs[indx] = *iter;
271 int sizeToSend = idsInProcColI[procColI].size();
276 Teuchos::send<int,int>(*mProblemComm,1,&sizeToSend,procColI);
278 Teuchos::send<int,gno_t>(*mProblemComm,sizeToSend,idsInProcColI[procColI].data(),procColI);
300 for(
int procColRank=0; procColRank<procDim; procColRank++)
303 int dstRank = procColRank*procDim + myProcCol;
307 int sizeToSend = colIDs.size();
309 Teuchos::send<int,int>(*mProblemComm,1,&sizeToSend,dstRank);
310 Teuchos::send<int,gno_t>(*mProblemComm,sizeToSend,colIDs.get(),dstRank);
325 int srcRank = myProcCol;
328 Teuchos::receive<int,int>(*mProblemComm, srcRank, 1, &buffSize);
330 colIDs.resize(buffSize);
331 Teuchos::receive<int,gno_t>(*mProblemComm, srcRank, buffSize, colIDs.get());
345 ArrayRCP<gno_t> domRangeIDs;
347 size_t nCols = colIDs.size();
348 lno_t nColsDivDim = nCols / procDim;
349 lno_t nColsModDim = nCols % procDim;
355 if(myProcRow < nColsModDim)
357 sColIndx = myProcRow * (nColsDivDim+1);
358 domRangeSize = nColsDivDim+1;
363 sColIndx = nColsModDim*(nColsDivDim+1) + (myProcRow-nColsModDim) * nColsDivDim;
364 domRangeSize = nColsDivDim;
367 domRangeIDs.resize(domRangeSize);
369 for(
size_t i=0;i<domRangeSize;i++)
371 domRangeIDs[i] = colIDs[sColIndx+i];
386 std::vector<int> subcommRanks(procDim);
388 for(
unsigned int i=0; i<procDim; i++)
390 subcommRanks[i] = myProcRow*procDim + i;
393 ArrayView<const int> subcommRanksView = Teuchos::arrayViewFromVector (subcommRanks);
395 RCP<Teuchos::Comm<int> > rowcomm = mProblemComm->createSubcommunicator(subcommRanksView);
401 size_t maxProcRowNCols=0;
403 Teuchos::reduceAll<int, size_t>(*rowcomm,Teuchos::REDUCE_MAX,1,&domRangeSize,&maxProcRowNCols);
409 gno_t MAXVAL = std::numeric_limits<gno_t>::max();
411 std::vector<gno_t> locRowIDs(maxProcRowNCols,MAXVAL);
413 Teuchos::ArrayRCP<gno_t> rowIDs(maxProcRowNCols * procDim);
417 for(
size_t i=0;i<domRangeIDs.size();i++)
419 locRowIDs[i] = domRangeIDs[i];
423 Teuchos::gatherAll<int,gno_t>(*rowcomm,maxProcRowNCols, locRowIDs.data(),
424 maxProcRowNCols*procDim, rowIDs.get());
428 std::vector<int>().swap(locRowIDs);
434 std::set<gno_t> setRowIDs;
436 for(
size_t i=0;i<rowIDs.size();i++)
438 if(rowIDs[i]!=MAXVAL)
440 setRowIDs.insert(rowIDs[i]);
448 rowIDs.resize(setRowIDs.size());
450 typename std::set<gno_t>::const_iterator iter;
453 for(iter=setRowIDs.begin(); iter!=setRowIDs.end(); ++iter)
455 rowIDs[indx] = *iter;
465 solution->setIDLists(rowIDs,colIDs,domRangeIDs,domRangeIDs);
Zoltan2::BaseAdapter< userTypes_t > base_adapter_t
MatrixAdapter defines the adapter interface for matrices.
map_t::global_ordinal_type gno_t
Defines the PartitioningSolution class.
Adapter::userCoord_t userCoord_t
sub-steps, each method's entry and exit
SparseMatrixAdapter_t::part_t part_t
Adapter::scalar_t scalar_t
AlgMatrix(const RCP< const Environment > &_env, const RCP< const Comm< int > > &_problemComm, const RCP< const MatrixAdapter< user_t, userCoord_t > > &_matrixAdapter)
A PartitioningSolution is a solution to a partitioning problem.
const part_t * getPartListView() const
Returns the part list corresponding to the global ID list.
Algorithm defines the base class for all algorithms.
map_t::local_ordinal_type lno_t
void partitionMatrix(const RCP< MatrixPartitioningSolution< Adapter > > &solution)
Matrix Partitioning method.
PartitioningProblem sets up partitioning problems for the user.
Defines the PartitioningProblem class.
Adapter::base_adapter_t base_adapter_t
A PartitioningSolution is a solution to a partitioning problem.
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t