|
EpetraExt Development
|
00001 //@HEADER 00002 // *********************************************************************** 00003 // 00004 // EpetraExt: Epetra Extended - Linear Algebra Services Package 00005 // Copyright (2011) Sandia Corporation 00006 // 00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00008 // the U.S. Government retains certain rights in this software. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 //@HEADER 00041 00042 #ifdef ZOLTAN_ORDER 00043 00044 #include <EpetraExt_ZoltanOrder_CrsGraph.h> 00045 00046 #include <EpetraExt_Transpose_CrsGraph.h> 00047 00048 #include <EpetraExt_ZoltanQuery.h> 00049 #include <Zoltan_LoadBalance.h> 00050 00051 #include <Epetra_CrsGraph.h> 00052 #include <Epetra_Map.h> 00053 #include <Epetra_Import.h> 00054 00055 #include <Epetra_MpiComm.h> 00056 00057 #include <vector> 00058 #include <set> 00059 00060 using std::vector; 00061 using std::set; 00062 00063 namespace EpetraExt { 00064 00065 EPETRAEXT_DEPRECATED 00066 ZoltanOrder_CrsGraph:: 00067 ~ZoltanOrder_CrsGraph() 00068 { 00069 if( newObj_ ) delete newObj_; 00070 if( NewRowMap_ ) delete NewRowMap_; 00071 } 00072 00073 EPETRAEXT_DEPRECATED 00074 ZoltanOrder_CrsGraph::NewTypeRef 00075 ZoltanOrder_CrsGraph:: 00076 operator()( OriginalTypeRef orig ) 00077 { 00078 origObj_ = &orig; 00079 00080 int err; 00081 00082 //Setup Load Balance Object 00083 float version; 00084 char * dummy = 0; 00085 Zoltan::LoadBalance LB( 0, &dummy, &version ); 00086 err = LB.Create( dynamic_cast<const Epetra_MpiComm&>(orig.Comm()).Comm() ); 00087 LB.Set_Param( "ORDER_METHOD", "METIS" ); 00088 LB.Set_Param( "ORDER_TYPE", "LOCAL" ); 00089 00090 //Setup Query Object 00091 CrsGraph_Transpose transposeTransform; 00092 Epetra_CrsGraph & TransGraph = transposeTransform( orig ); 00093 ZoltanQuery Query( orig, &TransGraph, true ); 00094 if( err == ZOLTAN_OK ) err = LB.Set_QueryObject( &Query ); 00095 00096 if( err != ZOLTAN_OK ) 00097 { cout << "Setup of Zoltan Load Balancing Objects FAILED!\n"; exit(0); } 00098 00099 //Generate Reorder 00100 int num_elements = orig.RowMap().NumMyElements(); 00101 int num_gid_entries, num_lid_entries; 00102 vector<ZOLTAN_ID_TYPE> global_ids(num_elements,0); 00103 vector<ZOLTAN_ID_TYPE> local_ids(num_elements,0); 00104 vector<int> rank(num_elements); 00105 vector<int> iperm(num_elements); 00106 00107 orig.Comm().Barrier(); 00108 err = LB.Order( &num_gid_entries, 00109 &num_lid_entries, 00110 num_elements, 00111 &global_ids[0], 00112 &local_ids[0], 00113 &rank[0], 00114 &iperm[0] ); 00115 orig.Comm().Barrier(); 00116 00117 #ifdef EDT_ZOLTANORDER_DEBUG 00118 cout << "------------------------------\n"; 00119 cout << "#GIDs: " << num_gid_entries << endl; 00120 cout << "#LIDs: " << num_lid_entries << endl; 00121 cout << "GIDs and LIDs\n"; 00122 for( int i = 0; i < num_elements; ++i ) cout << global_ids[i] << " " << local_ids[i] << endl; 00123 cout << "Rank and Perm\n"; 00124 for( int i = 0; i < num_elements; ++i ) cout << rank[i] << " " << iperm[i] << endl; 00125 cout << "------------------------------\n"; 00126 #endif 00127 00128 //Generate New Row Map 00129 vector<int> gids(num_elements); 00130 for( int i = 0; i < num_elements; ++i ) 00131 gids[ (num_elements-1) - rank[i] ] = global_ids[i]; 00132 NewRowMap_ = new Epetra_Map( orig.RowMap().NumGlobalElements(), 00133 num_elements, 00134 &gids[0], 00135 orig.RowMap().IndexBase(), 00136 orig.RowMap().Comm() ); 00137 00138 //Create Importer 00139 Epetra_Import Importer( *NewRowMap_, orig.RowMap() ); 00140 00141 //Create New Graph 00142 Epetra_CrsGraph * NewGraph( new Epetra_CrsGraph( Copy, *NewRowMap_, 0 ) ); 00143 NewGraph->Import( orig, Importer, Insert ); 00144 NewGraph->FillComplete( true ); 00145 00146 newObj_ = NewGraph; 00147 00148 return NewGraph; 00149 } 00150 00151 } // namespace EpetraExt 00152 00153 #endif //ZOLTAN_ORDER
1.7.4