43 #include <Epetra_ConfigDefs.h> 47 #include "Epetra_MpiComm.h" 51 #include "Epetra_SerialComm.h" 52 #include "Epetra_Time.h" 53 #include "Epetra_Map.h" 54 #include "Epetra_CrsGraph.h" 55 #include "Epetra_IntVector.h" 56 #include "Epetra_MapColoring.h" 59 #include "../epetra_test_err.h" 64 void printColoring (
const Epetra_MapColoring & ColorMap, Epetra_CrsGraph *A,
bool verbose);
66 int main(
int argc,
char *argv[]) {
73 MPI_Init( &argc, &argv );
95 cout <<
"Usage: " << argv[0] <<
" [-v [nx [ny]]]" << endl;
101 if(argv[loc][0]==
'-' && argv[loc][1]==
'v')
102 { verbose =
true; ++loc; }
104 if (loc < argc) nx = atoi( argv[loc++] );
105 if( loc < argc) ny = atoi( argv[loc] );
109 Epetra_MpiComm Comm(MPI_COMM_WORLD);
111 Epetra_SerialComm Comm;
114 int MyPID = Comm.MyPID();
115 int NumProc = Comm.NumProc();
117 bool verbose1 =
false;
118 if(verbose) verbose1 = (MyPID==0);
125 if(verbose) cout << Comm << endl << flush;
128 int NumGlobalElements = nx * ny;
129 if( NumGlobalElements < NumProc )
131 cout <<
"NumGlobalElements = " << NumGlobalElements <<
132 " cannot be < number of processors = " << NumProc;
137 Epetra_Map Map( NumGlobalElements, IndexBase, Comm );
140 int NumMyElements = Map.NumMyElements();
141 std::vector<int> MyGlobalElements( NumMyElements );
142 Map.MyGlobalElements( &MyGlobalElements[0] );
143 if( verbose ) cout << Map;
147 std::vector<int> NumNz( NumMyElements, 5 );
150 for (
int i = 0; i < NumMyElements; ++i)
152 global_j = MyGlobalElements[i] / nx;
153 global_i = MyGlobalElements[i] - global_j * nx;
154 if (global_i == 0) NumNz[i] -= 1;
155 if (global_i == nx-1) NumNz[i] -= 1;
156 if (global_j == 0) NumNz[i] -= 1;
157 if (global_j == ny-1) NumNz[i] -= 1;
161 cout << endl <<
"NumNz: ";
162 for (
int i = 0; i < NumMyElements; i++) cout << NumNz[i] <<
" ";
167 Epetra_CrsGraph A( Copy, Map, &NumNz[0] );
169 std::vector<int> Indices(5);
172 for (
int i = 0; i < NumMyElements; ++i )
174 global_j = MyGlobalElements[i] / nx;
175 global_i = MyGlobalElements[i] - global_j * nx;
178 if (global_j > 0 && ny > 1)
179 Indices[NumEntries++] = global_i + (global_j-1)*nx;
182 Indices[NumEntries++] = global_i-1 + global_j *nx;
184 Indices[NumEntries++] = MyGlobalElements[i];
187 Indices[NumEntries++] = global_i+1 + global_j *nx;
189 if (global_j < ny-1 && ny > 1)
190 Indices[NumEntries++] = global_i + (global_j+1)*nx;
193 A.InsertGlobalIndices( MyGlobalElements[i], NumEntries, &Indices[0] );
202 Epetra_MapColoring & Greedy0ColorMap = Greedy0MapColoringTransform( A );
208 Epetra_MapColoring & Greedy1ColorMap = Greedy1MapColoringTransform( A );
214 Epetra_MapColoring & Greedy2ColorMap = Greedy2MapColoringTransform( A );
220 Epetra_MapColoring & Lubi0ColorMap = Lubi0MapColoringTransform( A );
226 Epetra_MapColoring & Lubi1ColorMap = Lubi1MapColoringTransform( A );
232 Epetra_MapColoring & Lubi2ColorMap = Lubi2MapColoringTransform( A );
236 if( verbose ) cout <<
"Parallel Map Coloring 1!\n";
240 Epetra_MapColoring & Parallel1ColorMap = Parallel1MapColoringTransform( A );
243 if( verbose ) cout <<
"Parallel Map Coloring 2!\n";
247 Epetra_MapColoring & Parallel2ColorMap = Parallel2MapColoringTransform( A );
259 void printColoring (
const Epetra_MapColoring & ColorMap, Epetra_CrsGraph * A,
bool verbose) {
261 int NumColors = ColorMap.NumColors();
262 int * ListOfColors = ColorMap.ListOfColors();
265 vector<Epetra_IntVector> & ColIndices = MapColoringIndexTransform( *A );
271 cout <<
"***************************************\n";
272 cout <<
"Column Indexing by Color:\n";
273 cout <<
"***************************************\n";
275 for(
int i = 0; i < NumColors; ++i )
277 cout <<
"COLOR: " << ListOfColors[i] << endl;
278 cout << ColIndices[i];
std::string EpetraExt_Version()
Map Coloring of independent columns in a Graph.
int main(int argc, char *argv[])
void printColoring(const Epetra_MapColoring &ColorMap, Epetra_CrsGraph *A, bool verbose)