MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ML_Linker.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 // Unmaintained code snippet to use Muelu's aggregation algorithms in ML
47 
48 #include "ml_aggregate.h"
49 #include "ml_epetra_utils.h"
50 
51 extern MueLu_Graph *MueLu_BuildGraph(ML_Matrix *Amatrix, char *name);
52 extern int MueLu_DestroyGraph(MueLu_Graph *graph);
53 
54 /**********************************************************************************/
55 /* Function to execute new MueLu aggregation via old ML */
56 /* This function should go away soon as we should start executing new MueLu */
57 /* aggregation inside MueLu.
58 /**********************************************************************************/
59 int ML_Aggregate_CoarsenUncoupled(ML_Aggregate *mlAggregates,
60  ML_Matrix *Amatrix, ML_Matrix **Pmatrix, ML_Comm *comm)
61 {
62  MueLu_Graph *graph;
63  graph = MueLu_BuildGraph(Amatrix,"ML_Uncoupled");
64 
65  if (graph->eGraph->Comm().MyPID() == 0 && mlAggregates->printFlag < MueLu_PrintLevel())
66  printf("ML_Aggregate_CoarsenUncoupled : \n");
67 
68  MueLu_AggOptions aggregateOptions;
69 
70  aggregateOptions.printFlag = mlAggregates->print_flag;
71  aggregateOptions.minNodesPerAggregate = mlAggregates->min_nodes_per_aggregate;
72  aggregateOptions.maxNeighAlreadySelected = mlAggregates->max_neigh_already_selected;
73  aggregateOptions.ordering = mlAggregates->ordering;
74  aggregateOptions.phase3AggCreation = mlAggregates->phase3_agg_creation;
75 
76 
77  Aggregates *aggregates = NULL;
78 
79  aggregates = MueLu_Aggregate_CoarsenUncoupled(&aggregateOptions,graph);
80 
81 
82  MueLu_AggregateLeftOvers(&aggregateOptions, aggregates, "UC_CleanUp", graph);
83 
84 //#ifdef out
85 Epetra_IntVector Final( aggregates->vertex2AggId->Map() );
86 for (int i = 0; i < aggregates->vertex2AggId->Map().NumMyElements(); i++)
87  Final[i] = (*(aggregates->vertex2AggId))[i] + (*(aggregates->procWinner))[i]*1000;
88 printf("finals\n");
89 cout << Final << endl; sleep(2);
90 //#endif
91 
92  MueLu_AggregateDestroy(aggregates);
93  MueLu_DestroyGraph(graph);
94  return 0;
95 }
96 
97 /**********************************************************************************/
98 /* Function to take an ML_Matrix (which actually wraps an Epetra_CrsMatrix) and */
99 /* extract out the Epetra_CrsGraph. My guess is that this should be changed soon */
100 /* so that the first argument is some MueLu API Matrix. */
101 /**********************************************************************************/
102 MueLu_Graph *MueLu_BuildGraph(ML_Matrix *Amatrix, char *name)
103 {
104  MueLu_Graph *graph;
105  double *dtmp = NULL;
106  Epetra_CrsMatrix *A;
107 
108  graph = (MueLu_Graph *) malloc(sizeof(MueLu_Graph));
109  graph->eGraph = NULL;
110  graph->name = NULL;
111  graph->name = (char *) malloc(sizeof(char)*80); strcpy(Graph->name,name);
112  graph->nVertices = Amatrix->invec_leng;
113 
114  if ( Amatrix->getrow->nrows == 0) {
115  graph->vertexNeighbors = NULL;
116  graph->vertexNeighborsPtr = NULL;
117  graph->nEdges = 0;
118  }
119  else {
120  Epetra_ML_GetCrsDataptrs(Amatrix, &dtmp, &(graph->vertexNeighbors),&(graph->vertexNeighborsPtr));
121  if ( graph->vertexNeighborsPtr == NULL) {
122  printf("MueLu_BuildGraph: Only functions for an Epetra_CrsMatrix.\n");
123  exit(1);
124  }
125  graph->nEdges = (graph->vertexNeighborsPtr)[Amatrix->getrow->Nrows];
126  Epetra_ML_GetCrsMatrix( Amatrix, (void **) &A );
127  graph->eGraph = &(A->graph());
128  }
129  if (graph->eGraph == NULL) graph->nGhost = 0;
130  else {
131  graph->nGhost = A->RowMatrixColMap().NumMyElements() - A->MatrixDomainMap().NumMyElements();
132  if (graph->nGhost < 0) graph->nGhost = 0;
133  }
134  return graph;
135 }
136 
137 int MueLu_DestroyGraph(MueLu_Graph *graph)
138 {
139  if ( graph != NULL) {
140  if (graph->name != NULL) free(graph->name);
141  free(graph);
142  }
143  return 0;
144 }
int MueLu_DestroyGraph(MueLu_Graph *graph)
Definition: ML_Linker.hpp:137
MueLu_Graph * MueLu_BuildGraph(ML_Matrix *Amatrix, char *name)
Definition: ML_Linker.hpp:102
int ML_Aggregate_CoarsenUncoupled(ML_Aggregate *mlAggregates, ML_Matrix *Amatrix, ML_Matrix **Pmatrix, ML_Comm *comm)
Definition: ML_Linker.hpp:59
int NumMyElements() const
Keep data only for this run. Used to keep data useful for Hierarchy::Iterate(). Data will be deleted ...
const Epetra_Map & RowMatrixColMap() const