| 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 |
#include <Isorropia_EpetraLevelScheduler.hpp> |
| 41 |
#include <Teuchos_ParameterList.hpp> |
| 42 |
|
| 43 |
#ifdef HAVE_EPETRA |
| 44 |
#include <Epetra_CrsGraph.h> |
| 45 |
#endif |
| 46 |
|
| 47 |
namespace Isorropia { |
| 48 |
|
| 49 |
#ifdef HAVE_EPETRA |
| 50 |
|
| 51 |
namespace Epetra { |
| 52 |
|
| 53 |
|
| 54 |
LevelScheduler::~LevelScheduler() {} |
| 55 |
|
| 56 |
|
| 57 |
LevelScheduler::LevelScheduler(Teuchos::RCP<const Epetra_CrsGraph> input_graph, |
| 58 |
const Teuchos::ParameterList& paramlist, |
| 59 |
bool compute_now) |
| 60 |
: Operator(input_graph, paramlist,0) |
| 61 |
{ |
| 62 |
if (compute_now) |
| 63 |
schedule(true); |
| 64 |
} |
| 65 |
|
| 66 |
void |
| 67 |
LevelScheduler::schedule(bool force_scheduling) |
| 68 |
{ |
| 69 |
if (alreadyComputed() && !force_scheduling) |
| 70 |
return; |
| 71 |
|
| 72 |
const Epetra_CrsGraph &graph = *input_graph_; |
| 73 |
|
| 74 |
int nrows = graph.NumMyRows(); |
| 75 |
int maxNonZeros = graph.MaxNumIndices(); |
| 76 |
|
| 77 |
properties_.clear(); |
| 78 |
properties_.assign(nrows, 0); |
| 79 |
|
| 80 |
if ((nrows < 2) || (maxNonZeros < 1)){ |
| 81 |
computeNumberOfProperties(); |
| 82 |
return; |
| 83 |
} |
| 84 |
|
| 85 |
// algorithm from legacy Petra_CRS_Graph.cc |
| 86 |
|
| 87 |
if (graph.LowerTriangular()){ |
| 88 |
for (int i=0; i < nrows ; i++){ |
| 89 |
|
| 90 |
int numIDs = 0; |
| 91 |
int *IDs = NULL; |
| 92 |
graph.ExtractMyRowView(i, numIDs, IDs); |
| 93 |
|
| 94 |
int depth = -1; |
| 95 |
|
| 96 |
for (int j=0; j < numIDs; j++){ |
| 97 |
int col = IDs[j]; |
| 98 |
if ((col < i) && (properties_[col] > depth)) |
| 99 |
depth = properties_[col]; |
| 100 |
} |
| 101 |
depth++; |
| 102 |
|
| 103 |
properties_[i] = depth; |
| 104 |
} |
| 105 |
} |
| 106 |
else if (graph.UpperTriangular()){ |
| 107 |
|
| 108 |
for (int i=nrows-1; i >= 0 ; i--){ |
| 109 |
|
| 110 |
int numIDs = 0; |
| 111 |
int *IDs = NULL; |
| 112 |
graph.ExtractMyRowView(i, numIDs, IDs); |
| 113 |
|
| 114 |
int depth = -1; |
| 115 |
|
| 116 |
for (int j=0; j < numIDs; j++){ |
| 117 |
int col = IDs[j]; |
| 118 |
if ((col > i) && (properties_[col] > depth)) |
| 119 |
depth = properties_[col]; |
| 120 |
} |
| 121 |
depth++; |
| 122 |
|
| 123 |
properties_[i] = depth; |
| 124 |
} |
| 125 |
} |
| 126 |
else{ |
| 127 |
// error |
| 128 |
properties_.assign(nrows,-1); |
| 129 |
} |
| 130 |
|
| 131 |
operation_already_computed_ = true; |
| 132 |
|
| 133 |
computeNumberOfProperties(); |
| 134 |
} |
| 135 |
|
| 136 |
} // namespace EPETRA |
| 137 |
|
| 138 |
#endif //HAVE_EPETRA |
| 139 |
|
| 140 |
}//namespace Isorropia |
| 141 |
|