|
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 #include <EpetraExt_ZoltanQuery.h> 00043 00044 #include <Epetra_CrsGraph.h> 00045 #include <Epetra_BlockMap.h> 00046 #include <Epetra_Comm.h> 00047 00048 #include <algorithm> 00049 00050 EPETRAEXT_DEPRECATED 00051 EpetraExt::ZoltanQuery::ZoltanQuery( const Epetra_CrsGraph & graph, 00052 const Epetra_CrsGraph * tgraph, 00053 bool localEdgesOnly ) 00054 : graph_(graph), 00055 tgraph_(tgraph), 00056 localEdgesOnly_(localEdgesOnly) 00057 { 00058 int numMyRows = graph_.NumMyRows(); 00059 int maxRows; 00060 graph_.Comm().MaxAll( &numMyRows, &maxRows, 1 ); 00061 00062 LBProc_.resize( numMyRows ); 00063 00064 int numIndices; 00065 int maxNumIndices = graph_.MaxNumIndices(); 00066 std::vector<int> indexList( maxNumIndices ); 00067 for( int i = 0; i < numMyRows; ++i ) 00068 { 00069 graph_.ExtractGlobalRowCopy( graph_.GRID(i), 00070 maxNumIndices, 00071 numIndices, 00072 &indexList[0] ); 00073 LBProc_[i].resize( numIndices ); 00074 graph_.RowMap().RemoteIDList( numIndices, &indexList[0], &LBProc_[i][0], 0 ); 00075 } 00076 00077 for( int i = numMyRows; i < maxRows; ++i ) 00078 graph_.RowMap().RemoteIDList( numIndices, &indexList[0], &LBProc_[numMyRows-1][0], 0 ); 00079 00080 if( tgraph_ ) 00081 { 00082 LBProc_Trans_.resize( numMyRows ); 00083 00084 maxNumIndices = tgraph_->MaxNumIndices(); 00085 indexList.resize(maxNumIndices); 00086 for( int i = 0; i < numMyRows; ++i ) 00087 { 00088 tgraph_->ExtractGlobalRowCopy( tgraph_->GRID(i), 00089 maxNumIndices, 00090 numIndices, 00091 &indexList[0] ); 00092 LBProc_Trans_[i].resize( numIndices ); 00093 tgraph_->RowMap().RemoteIDList( numIndices, &indexList[0], &LBProc_Trans_[i][0], 0 ); 00094 } 00095 00096 for( int i = numMyRows; i < maxRows; ++i ) 00097 tgraph_->RowMap().RemoteIDList( numIndices, &indexList[0], &LBProc_Trans_[numMyRows-1][0], 0 ); 00098 } 00099 00100 graph_.Comm().Barrier(); 00101 } 00102 00103 //General Functions 00104 EPETRAEXT_DEPRECATED 00105 int EpetraExt::ZoltanQuery::Number_Objects ( void * data, 00106 int * ierr ) 00107 { 00108 *ierr = ZOLTAN_OK; 00109 00110 return graph_.NumMyRows(); 00111 } 00112 00113 EPETRAEXT_DEPRECATED 00114 void EpetraExt::ZoltanQuery::Object_List ( void * data, 00115 int num_gid_entries, 00116 int num_lid_entries, 00117 ZOLTAN_ID_PTR global_ids, 00118 ZOLTAN_ID_PTR local_ids, 00119 int weight_dim, 00120 float * object_weights, 00121 int * ierr ) 00122 { 00123 *ierr = ZOLTAN_OK; 00124 00125 int rows = graph_.NumMyRows(); 00126 00127 graph_.RowMap().MyGlobalElements( ((int *) global_ids) ); 00128 00129 int Index = graph_.RowMap().IndexBase(); 00130 for( int i = 0; i < rows; i++, Index++ ) 00131 local_ids[i] = Index; 00132 } 00133 00134 //Graph Based Functions 00135 EPETRAEXT_DEPRECATED 00136 int EpetraExt::ZoltanQuery::Number_Edges ( void * data, 00137 int num_gid_entities, 00138 int num_lid_entities, 00139 ZOLTAN_ID_PTR global_id, 00140 ZOLTAN_ID_PTR local_id, 00141 int * ierr ) 00142 { 00143 int LocalRow = graph_.LRID( *global_id ); 00144 00145 if( LocalRow != -1 && LocalRow == *local_id ) 00146 { 00147 *ierr = ZOLTAN_OK; 00148 00149 int NumIndices = graph_.NumMyIndices( LocalRow ); 00150 int IndiceCountReturn; 00151 00152 std::vector<int> nbr_edges( NumIndices ); 00153 int flag = graph_.ExtractGlobalRowCopy( ((int) *global_id), 00154 NumIndices, 00155 IndiceCountReturn, 00156 &(nbr_edges[0]) ); 00157 assert( flag == 0 ); 00158 assert( NumIndices == IndiceCountReturn ); 00159 std::sort( nbr_edges.begin(), nbr_edges.end() ); 00160 00161 bool self = false; 00162 for(int i = 0; i < NumIndices; ++i ) 00163 if( nbr_edges[i] == ((int) *global_id) ) 00164 { self = true; break; } 00165 00166 int nonLocalEdges = 0; 00167 if( localEdgesOnly_ ) 00168 for( int i = 0; i < NumIndices; ++i ) 00169 if( !graph_.MyGRID(nbr_edges[i]) ) ++nonLocalEdges; 00170 00171 if( tgraph_ ) 00172 { 00173 int tNumIndices = tgraph_->NumMyIndices( LocalRow ); 00174 std::vector<int> t_nbr_edges( tNumIndices ); 00175 00176 flag = tgraph_->ExtractGlobalRowCopy( ((int) *global_id), 00177 tNumIndices, 00178 IndiceCountReturn, 00179 &(t_nbr_edges[0]) ); 00180 assert( flag == 0 ); 00181 assert( tNumIndices == IndiceCountReturn ); 00182 00183 for( int i = 0; i < tNumIndices; ++i ) 00184 if( !std::binary_search( nbr_edges.begin(), nbr_edges.end(), t_nbr_edges[i] ) ) 00185 { 00186 ++NumIndices; 00187 if( localEdgesOnly_ && !graph_.MyGRID(t_nbr_edges[i]) ) ++nonLocalEdges; 00188 } 00189 } 00190 00191 //std::cout << "Indices Cnt: " << ((int)*global_id) << " " << ((int)*local_id) << " " << NumIndices-(self?1:0)-nonLocalEdges << std::endl; 00192 return NumIndices - (self?1:0) - nonLocalEdges; 00193 00194 } 00195 else 00196 { 00197 *ierr = ZOLTAN_FATAL; 00198 return -1; 00199 } 00200 } 00201 00202 EPETRAEXT_DEPRECATED 00203 void EpetraExt::ZoltanQuery::Edge_List ( void * data, 00204 int num_gid_entities, 00205 int num_lid_entities, 00206 ZOLTAN_ID_PTR global_id, 00207 ZOLTAN_ID_PTR local_id, 00208 ZOLTAN_ID_PTR neighbor_global_ids, 00209 int * neighbor_procs, 00210 int weight_dim, 00211 float * edge_weights, 00212 int * ierr ) 00213 { 00214 int NumIndices = graph_.NumMyIndices( ((int) *local_id) ); 00215 00216 int IndiceCountReturn; 00217 00218 if( NumIndices != -1 ) 00219 { 00220 std::vector<int> nbr_edges( NumIndices ); 00221 int flag = graph_.ExtractGlobalRowCopy( ((int) *global_id), 00222 NumIndices, 00223 IndiceCountReturn, 00224 &(nbr_edges[0]) ); 00225 assert( flag == 0 ); 00226 assert( NumIndices == IndiceCountReturn ); 00227 00228 int ii = 0; 00229 for( int i = 0; i < NumIndices; ++i ) 00230 if( nbr_edges[ i ] != ((int) *global_id) ) 00231 if( !localEdgesOnly_ || graph_.MyGRID(nbr_edges[i]) ) 00232 { 00233 neighbor_global_ids[ ii ] = nbr_edges[ i ]; 00234 neighbor_procs[ ii ] = LBProc_[(int) *local_id][ i ]; 00235 ++ii; 00236 } 00237 00238 if( tgraph_ ) 00239 { 00240 std::sort( nbr_edges.begin(), nbr_edges.end() ); 00241 00242 int tNumIndices = tgraph_->NumMyIndices( ((int) *local_id) ); 00243 std::vector<int> t_nbr_edges( tNumIndices ); 00244 00245 flag = tgraph_->ExtractGlobalRowCopy( ((int) *global_id), 00246 tNumIndices, 00247 IndiceCountReturn, 00248 &(t_nbr_edges[0]) ); 00249 assert( flag == 0 ); 00250 assert( tNumIndices == IndiceCountReturn ); 00251 00252 for( int i = 0; i < tNumIndices; ++i ) 00253 if( !std::binary_search( nbr_edges.begin(), nbr_edges.end(), t_nbr_edges[i] ) ) 00254 if( !localEdgesOnly_ || graph_.MyGRID(t_nbr_edges[i]) ) 00255 { 00256 neighbor_global_ids[ii] = t_nbr_edges[i]; 00257 neighbor_procs[ii] = LBProc_Trans_[(int) *local_id][i]; 00258 ++ii; 00259 } 00260 } 00261 00262 00263 /* 00264 std::cout << "Edge List: " << ((int) *global_id) << " " << ((int) *local_id) << std::endl; 00265 std::cout << "NumIndices: " << NumIndices << " " << "ii: " << ii << std::endl; 00266 for( int i = 0; i < ii; ++i ) 00267 std::cout << " " << ((int *) neighbor_global_ids)[i] << " " << 00268 neighbor_procs[i] << std::endl; 00269 std::cout << std::endl; 00270 */ 00271 00272 *ierr = ZOLTAN_OK; 00273 } 00274 else 00275 *ierr = ZOLTAN_FATAL; 00276 00277 } 00278 00279 EPETRAEXT_DEPRECATED 00280 int EpetraExt::ZoltanQuery::Number_HG_Edges ( void * data, 00281 int * ierr ) 00282 { 00283 int num = graph_.NumMyRows(); 00284 std::cout << "NRows: " << num << std::endl; 00285 00286 *ierr = ZOLTAN_OK; 00287 return num; 00288 } 00289 00290 EPETRAEXT_DEPRECATED 00291 int EpetraExt::ZoltanQuery::Number_HG_Pins ( void * data, 00292 int * ierr ) 00293 { 00294 int num = graph_.NumMyEntries(); 00295 std::cout << "NNZ: " << num << std::endl; 00296 00297 *ierr = ZOLTAN_OK; 00298 return num; 00299 } 00300 00301 EPETRAEXT_DEPRECATED 00302 int EpetraExt::ZoltanQuery::HG_Edge_List ( void * data, 00303 int num_gid_entries, 00304 int ewgt_dim, 00305 int nedge, 00306 int maxsize, 00307 int * edge_sizes, 00308 ZOLTAN_ID_PTR edge_verts, 00309 int * edge_procs, 00310 float * edge_weights ) 00311 00312 { 00313 int NumHEs = graph_.NumMyRows(); 00314 int maxEntries = graph_.MaxNumIndices(); 00315 00316 int numIndices; 00317 std::vector<int> indices( maxEntries ); 00318 00319 std::cout << "nedge: " << nedge << std::endl; 00320 std::cout << "maxsize: " << maxsize << std::endl; 00321 00322 int loc = 0; 00323 for( int i = 0; i < NumHEs; ++i ) 00324 { 00325 int flag = graph_.ExtractGlobalRowCopy( graph_.GRID(i), maxEntries, numIndices, &indices[0] ); 00326 assert( flag == 0 ); 00327 00328 edge_sizes[i] = numIndices; 00329 for( int j = 0; j < numIndices; ++j ) 00330 { 00331 edge_verts[loc] = indices[j]; 00332 edge_procs[loc] = LBProc_[i][j]; 00333 ++loc; 00334 } 00335 } 00336 00337 std::cout << "last_loc: " << loc << std::endl; 00338 00339 return ZOLTAN_OK; 00340 } 00341
1.7.4