| 1 |
//@HEADER |
| 2 |
//************************************************************************ |
| 3 |
// |
| 4 |
// Isorropia: Partitioning and Load Balancing Package |
| 5 |
// Copyright (2006) Sandia Corporation |
| 6 |
// |
| 7 |
//Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive |
| 8 |
//license for use of this work by or on behalf of the U.S. Government. |
| 9 |
// |
| 10 |
// Redistribution and use in source and binary forms, with or without |
| 11 |
// modification, are permitted provided that the following conditions are |
| 12 |
// met: |
| 13 |
// |
| 14 |
// 1. Redistributions of source code must retain the above copyright |
| 15 |
// notice, this list of conditions and the following disclaimer. |
| 16 |
// |
| 17 |
// 2. Redistributions in binary form must reproduce the above copyright |
| 18 |
// notice, this list of conditions and the following disclaimer in the |
| 19 |
// documentation and/or other materials provided with the distribution. |
| 20 |
// |
| 21 |
// 3. Neither the name of the Corporation nor the names of the |
| 22 |
// contributors may be used to endorse or promote products derived from |
| 23 |
// this software without specific prior written permission. |
| 24 |
// |
| 25 |
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY |
| 26 |
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 27 |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 28 |
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE |
| 29 |
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 30 |
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 31 |
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 32 |
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 33 |
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 34 |
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 |
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 |
// |
| 37 |
//************************************************************************ |
| 38 |
//@HEADER |
| 39 |
|
| 40 |
#ifndef _Isorropia_EpetraMatcher_hpp_ |
| 41 |
#define _Isorropia_EpetraMatcher_hpp_ |
| 42 |
|
| 43 |
#include <Isorropia_Epetra.hpp> |
| 44 |
|
| 45 |
#include <Epetra_SerialComm.h> |
| 46 |
#include <Epetra_Map.h> |
| 47 |
#include <Epetra_CrsMatrix.h> |
| 48 |
#include <Epetra_Import.h> |
| 49 |
|
| 50 |
#ifdef ISORROPIA_HAVE_OMP |
| 51 |
#include <omp.h> |
| 52 |
#endif |
| 53 |
|
| 54 |
#include <Isorropia_ConfigDefs.hpp> |
| 55 |
#include <iostream> |
| 56 |
#include <fstream> |
| 57 |
#include <string> |
| 58 |
#include <vector> |
| 59 |
#include <algorithm> |
| 60 |
|
| 61 |
#ifdef MIN |
| 62 |
#undef MIN |
| 63 |
#endif |
| 64 |
|
| 65 |
#define MIN(a,b) ((a)<(b)?(a):(b)) |
| 66 |
|
| 67 |
namespace Isorropia { |
| 68 |
namespace Epetra { |
| 69 |
|
| 70 |
/** @ingroup matching_grp |
| 71 |
An implementation of the Matcher interface that operates on Epetra matrices |
| 72 |
and Graphs. |
| 73 |
|
| 74 |
One of the use of Maximum Cardinality Matching is that it provides nonzero |
| 75 |
diagonal for the sparse matrices. This multithreaded version of the |
| 76 |
matching algorithms provides an interface to solve the Bipartite Matching |
| 77 |
problem as well as it also provides permutation to get zero free diagonal |
| 78 |
for input sparse matrices. |
| 79 |
*/ |
| 80 |
class Matcher { |
| 81 |
private: |
| 82 |
int* mateU_; |
| 83 |
int* mateV_; |
| 84 |
int* Queue_; |
| 85 |
int* LV_; |
| 86 |
int* LU_; |
| 87 |
int* unmatchedU_; |
| 88 |
int *parent_; |
| 89 |
int *lookahead_; |
| 90 |
int *CRS_pointers_; |
| 91 |
int *CRS_indices_; |
| 92 |
double *CRS_vals_; |
| 93 |
bool finish_; |
| 94 |
int U_,V_,E_,avgDegU_,k_star_,icm_,BFSInd_,numThread_,Qst_,Qend_,matched_,choice_; |
| 95 |
const Epetra_CrsMatrix *A_; |
| 96 |
|
| 97 |
#ifdef ISORROPIA_HAVE_OMP |
| 98 |
omp_lock_t *scannedV_; |
| 99 |
#endif |
| 100 |
|
| 101 |
void delete_matched_v(); |
| 102 |
void complete_nonperfect_permutation(); |
| 103 |
int SGM(); |
| 104 |
int match_dfs(); |
| 105 |
int match_hk(); |
| 106 |
int construct_layered_graph(); |
| 107 |
int find_set_del_M(); |
| 108 |
int recursive_path_finder(int, int); |
| 109 |
int dfs_path_finder(int); |
| 110 |
int dfs_augment(); |
| 111 |
int augment_matching(int); |
| 112 |
int DW_phase(); |
| 113 |
|
| 114 |
public: |
| 115 |
/** @ingroup matching_grp |
| 116 |
Constructor |
| 117 |
\param[in] Epetra_CRSMatrix* compressed row matrix |
| 118 |
\param[in] paramlist this parameter list is used to select the algorithm. |
| 119 |
The input is a string. "PHK","PHKDW", "PDFS" and "PPF" for parallel |
| 120 |
Hopcroft-Karp, parallel Hopcroft-Karp with Duff-Wiberg , parallel DFS and |
| 121 |
parallel Pothen-Fan respectively. The default is the "PHKDW". |
| 122 |
*/ |
| 123 |
Matcher(const Epetra_CrsMatrix*, const Teuchos::ParameterList& |
| 124 |
paramlist=Teuchos::ParameterList("EmptyParameterList")); |
| 125 |
|
| 126 |
/** @ingroup matching_grp |
| 127 |
Constructor |
| 128 |
\param[in] RCP of the CrsMatrix |
| 129 |
\param[in] paramlist this parameter list is used to select the algorithm. |
| 130 |
The input is a string. "PHK","PHKDW", "PDFS" and "PPF" for parallel |
| 131 |
Hopcroft-Karp, parallel Hopcroft-Karp with Duff-Wiberg , parallel DFS and |
| 132 |
parallel Pothen-Fan respectively. The default is the "PHKDW". |
| 133 |
*/ |
| 134 |
Matcher(Teuchos::RCP<const Epetra_CrsMatrix>,const Teuchos::ParameterList& |
| 135 |
paramlist=Teuchos::ParameterList("EmptyParameterList")); |
| 136 |
|
| 137 |
/** @ingroup matching_grp |
| 138 |
Constructor |
| 139 |
\param[in] Pointer to the Epetra_CrsGraph |
| 140 |
\param[in] paramlist this parameter list is used to select the algorithm. |
| 141 |
The input is a string. "PHK","PHKDW", "PDFS" and "PPF" for parallel |
| 142 |
Hopcroft-Karp, parallel Hopcroft-Karp with Duff-Wiberg , parallel DFS and |
| 143 |
parallel Pothen-Fan respectively. The default is the "PHKDW". |
| 144 |
*/ |
| 145 |
Matcher(const Epetra_CrsGraph *,const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList")); |
| 146 |
|
| 147 |
/** @ingroup matching_grp |
| 148 |
Constructor |
| 149 |
\param[in] RCP of the Epetra_CrsGraph |
| 150 |
\param[in] paramlist this parameter list is used to select the algorithm. |
| 151 |
The input is a string. "PHK","PHKDW", "PDFS" and "PPF" for parallel |
| 152 |
Hopcroft-Karp, parallel Hopcroft-Karp with Duff-Wiberg , parallel DFS and |
| 153 |
parallel Pothen-Fan respectively. The default is the "PHKDW". |
| 154 |
*/ |
| 155 |
Matcher(Teuchos::RCP<const Epetra_CrsGraph>,const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList")); |
| 156 |
|
| 157 |
/** @ingroup matching_grp |
| 158 |
Destructor |
| 159 |
*/ |
| 160 |
virtual ~Matcher(); |
| 161 |
|
| 162 |
/** @ingroup matching_grp |
| 163 |
Copies the matched columns corresponding to each row in a user given |
| 164 |
array. |
| 165 |
|
| 166 |
\param[in] The length of the array provided by the user |
| 167 |
\param[out] The amount of data copied into the array |
| 168 |
\param[in/out] The user array |
| 169 |
*/ |
| 170 |
void getMatchedColumnsForRowsCopy(int, int&, int* ) const; |
| 171 |
|
| 172 |
/** @ingroup matching_grp |
| 173 |
Copies the matched rows corresponding to each column in a user given |
| 174 |
array. |
| 175 |
|
| 176 |
\param[in] The length of the array provided by the user |
| 177 |
\param[out] The amount of data copied into the array |
| 178 |
\param[in/out] The user array |
| 179 |
*/ |
| 180 |
void getMatchedRowsForColumnsCopy(int, int&, int*) const; |
| 181 |
|
| 182 |
/* @ingroup matching_grp |
| 183 |
Returns the number of matched vertices from Maximum Cardinality |
| 184 |
Matching set |
| 185 |
*/ |
| 186 |
int getNumberOfMatchedVertices(); |
| 187 |
|
| 188 |
/** @ingroup matching_grp |
| 189 |
Applies the row permutation from matching and returns a new matrix. |
| 190 |
|
| 191 |
*/ |
| 192 |
Teuchos::RCP<Epetra_CrsMatrix> applyRowPermutation(); |
| 193 |
|
| 194 |
/** @ingroup matching_grp |
| 195 |
Applies the column permutation from matching and returns a new matrix. |
| 196 |
|
| 197 |
*/ |
| 198 |
Teuchos::RCP<Epetra_CrsMatrix> applyColumnPermutation(); |
| 199 |
|
| 200 |
//Epetra_Map* getPermutedRowMap(); |
| 201 |
|
| 202 |
/* @ingroup matching_grp |
| 203 |
Provides the row map which is actually the complete row permutation |
| 204 |
*/ |
| 205 |
//Epetra_Map* getPermutedColumnMap(); |
| 206 |
|
| 207 |
/** @ingroup matching_grp |
| 208 |
Provides the column map which is actually the complete column |
| 209 |
* permutation |
| 210 |
*/ |
| 211 |
|
| 212 |
/** @ingroup matching_grp |
| 213 |
Computes the maximum cardinality matching. |
| 214 |
*/ |
| 215 |
int match(); |
| 216 |
}; |
| 217 |
} |
| 218 |
} |
| 219 |
#endif |
| 220 |
|
| 221 |
#if defined(Isorropia_SHOW_DEPRECATED_WARNINGS) |
| 222 |
#ifdef __GNUC__ |
| 223 |
#warning "The Isorropia package is deprecated" |
| 224 |
#endif |
| 225 |
#endif |
| 226 |
|