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 #ifdef ZOLTAN_ORDER
00030
00031 #include <EpetraExt_ZoltanOrder_CrsGraph.h>
00032
00033 #include <EpetraExt_Transpose_CrsGraph.h>
00034
00035 #include <EpetraExt_ZoltanQuery.h>
00036 #include <Zoltan_LoadBalance.h>
00037
00038 #include <Epetra_CrsGraph.h>
00039 #include <Epetra_Map.h>
00040 #include <Epetra_Import.h>
00041
00042 #include <Epetra_MpiComm.h>
00043
00044 #include <vector>
00045 #include <set>
00046
00047 using std::vector;
00048 using std::set;
00049
00050 namespace EpetraExt {
00051
00052 ZoltanOrder_CrsGraph::
00053 ~ZoltanOrder_CrsGraph()
00054 {
00055 if( newObj_ ) delete newObj_;
00056 if( NewRowMap_ ) delete NewRowMap_;
00057 }
00058
00059 ZoltanOrder_CrsGraph::NewTypeRef
00060 ZoltanOrder_CrsGraph::
00061 operator()( OriginalTypeRef orig )
00062 {
00063 origObj_ = &orig;
00064
00065 int err;
00066
00067
00068 float version;
00069 char * dummy = 0;
00070 Zoltan::LoadBalance LB( 0, &dummy, &version );
00071 err = LB.Create( dynamic_cast<const Epetra_MpiComm&>(orig.Comm()).Comm() );
00072 LB.Set_Param( "ORDER_METHOD", "METIS" );
00073 LB.Set_Param( "ORDER_TYPE", "LOCAL" );
00074
00075
00076 CrsGraph_Transpose transposeTransform;
00077 Epetra_CrsGraph & TransGraph = transposeTransform( orig );
00078 ZoltanQuery Query( orig, &TransGraph, true );
00079 if( err == ZOLTAN_OK ) err = LB.Set_QueryObject( &Query );
00080
00081 if( err != ZOLTAN_OK )
00082 { cout << "Setup of Zoltan Load Balancing Objects FAILED!\n"; exit(0); }
00083
00084
00085 int num_elements = orig.RowMap().NumMyElements();
00086 int num_gid_entries, num_lid_entries;
00087 vector<ZOLTAN_ID_TYPE> global_ids(num_elements,0);
00088 vector<ZOLTAN_ID_TYPE> local_ids(num_elements,0);
00089 vector<int> rank(num_elements);
00090 vector<int> iperm(num_elements);
00091
00092 orig.Comm().Barrier();
00093 err = LB.Order( &num_gid_entries,
00094 &num_lid_entries,
00095 num_elements,
00096 &global_ids[0],
00097 &local_ids[0],
00098 &rank[0],
00099 &iperm[0] );
00100 orig.Comm().Barrier();
00101
00102 #ifdef EDT_ZOLTANORDER_DEBUG
00103 cout << "------------------------------\n";
00104 cout << "#GIDs: " << num_gid_entries << endl;
00105 cout << "#LIDs: " << num_lid_entries << endl;
00106 cout << "GIDs and LIDs\n";
00107 for( int i = 0; i < num_elements; ++i ) cout << global_ids[i] << " " << local_ids[i] << endl;
00108 cout << "Rank and Perm\n";
00109 for( int i = 0; i < num_elements; ++i ) cout << rank[i] << " " << iperm[i] << endl;
00110 cout << "------------------------------\n";
00111 #endif
00112
00113
00114 vector<int> gids(num_elements);
00115 for( int i = 0; i < num_elements; ++i )
00116 gids[ (num_elements-1) - rank[i] ] = global_ids[i];
00117 NewRowMap_ = new Epetra_Map( orig.RowMap().NumGlobalElements(),
00118 num_elements,
00119 &gids[0],
00120 orig.RowMap().IndexBase(),
00121 orig.RowMap().Comm() );
00122
00123
00124 Epetra_Import Importer( *NewRowMap_, orig.RowMap() );
00125
00126
00127 Epetra_CrsGraph * NewGraph( new Epetra_CrsGraph( Copy, *NewRowMap_, 0 ) );
00128 NewGraph->Import( orig, Importer, Insert );
00129 NewGraph->FillComplete( true );
00130
00131 newObj_ = NewGraph;
00132
00133 return NewGraph;
00134 }
00135
00136 }
00137
00138 #endif //ZOLTAN_ORDER