00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "Ifpack_ConfigDefs.h"
00044 #include "Ifpack_Partitioner.h"
00045 #include "Ifpack_OverlappingPartitioner.h"
00046 #include "Ifpack_GreedyPartitioner.h"
00047 #include "Ifpack_Graph.h"
00048
00049 #include "Epetra_Comm.h"
00050 #include "Epetra_BlockMap.h"
00051 #include "Epetra_Map.h"
00052 #include "Epetra_CrsGraph.h"
00053 #include "Teuchos_ParameterList.hpp"
00054
00055
00056 int Ifpack_GreedyPartitioner::ComputePartitions()
00057 {
00058 std::vector<int> ElementsPerPart(NumLocalParts());
00059 std::vector<int> Count(NumLocalParts());
00060 for (int i = 0 ; i < NumLocalParts() ; ++i)
00061 Count[i] = 0;
00062
00063
00064 int div = NumMyRows() / NumLocalParts();
00065 int mod = NumMyRows() % NumLocalParts();
00066
00067 for (int i = 0 ; i < NumLocalParts() ; ++i) {
00068 Count[i] = 0;
00069 ElementsPerPart[i] = div;
00070 if (i < mod) ElementsPerPart[i]++;
00071 }
00072
00073 for( int i=0 ; i<NumMyRows() ; ++i ) {
00074 Partition_[i] = -1;
00075 }
00076
00077 int NumEntries;
00078 std::vector<int> Indices(MaxNumEntries());
00079
00080
00081 int CurrentPartition = 0;
00082 int TotalCount = 0;
00083
00084
00085 for (int i = 0 ; i < NumMyRows() ; ++i) {
00086 NumEntries = 0;
00087 int ierr = Graph_->ExtractMyRowCopy(i, MaxNumEntries(),
00088 NumEntries, &Indices[0]);
00089 IFPACK_CHK_ERR(ierr);
00090 if (NumEntries <= 1) {
00091 Partition_[i] = 0;
00092 TotalCount++;
00093 }
00094 }
00095
00096 if (TotalCount)
00097 CurrentPartition = 1;
00098
00099 std::vector<int> ThisLevel(1);
00100 ThisLevel[0] = RootNode_;
00101
00102
00103 if (Partition_[RootNode_] != -1) {
00104
00105 for (int i = 0 ; i < NumMyRows() ; ++i)
00106 if (Partition_[i] == -1) {
00107 ThisLevel[0] = i;
00108 break;
00109 }
00110 }
00111 else {
00112 Partition_[RootNode_] = CurrentPartition;
00113 }
00114
00115
00116 while (ThisLevel.size()) {
00117
00118 std::vector<int> NextLevel;
00119
00120 for (unsigned int i = 0 ; i < ThisLevel.size() ; ++i) {
00121
00122 int CurrentNode = ThisLevel[i];
00123 int ierr = Graph_->ExtractMyRowCopy(CurrentNode, MaxNumEntries(),
00124 NumEntries, &Indices[0]);
00125 IFPACK_CHK_ERR(ierr);
00126
00127 if (NumEntries <= 1)
00128 continue;
00129
00130 for (int j = 0 ; j < NumEntries ; ++j) {
00131
00132 int NextNode = Indices[j];
00133 if (NextNode >= NumMyRows()) continue;
00134
00135 if (Partition_[NextNode] == -1) {
00136
00137 NumLocalParts_ = CurrentPartition + 1;
00138 Partition_[NextNode] = CurrentPartition;
00139 ++Count[CurrentPartition];
00140 ++TotalCount;
00141 NextLevel.push_back(NextNode);
00142 }
00143 }
00144 }
00145
00146
00147 if (Count[CurrentPartition] >= ElementsPerPart[CurrentPartition])
00148 ++CurrentPartition;
00149
00150
00151 ThisLevel.resize(0);
00152 for (unsigned int i = 0 ; i < NextLevel.size() ; ++i)
00153 ThisLevel.push_back(NextLevel[i]);
00154
00155 if (ThisLevel.size() == 0 && (TotalCount != NumMyRows())) {
00156
00157 for (int i = 0 ; i < NumMyRows() ; i++) {
00158 if (Partition_[i] == -1)
00159 ThisLevel.push_back(i);
00160 break;
00161 }
00162 }
00163
00164 }
00165
00166 return(0);
00167 }
00168