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 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 // Unmaintained code snippet to use Muelu's aggregation algorithms in ML
11 
12 #include "ml_aggregate.h"
13 #include "ml_epetra_utils.h"
14 
15 extern MueLu_Graph *MueLu_BuildGraph(ML_Matrix *Amatrix, char *name);
16 extern int MueLu_DestroyGraph(MueLu_Graph *graph);
17 
18 /**********************************************************************************/
19 /* Function to execute new MueLu aggregation via old ML */
20 /* This function should go away soon as we should start executing new MueLu */
21 /* aggregation inside MueLu.
22 /**********************************************************************************/
23 int ML_Aggregate_CoarsenUncoupled(ML_Aggregate *mlAggregates,
24  ML_Matrix *Amatrix, ML_Matrix **Pmatrix, ML_Comm *comm) {
25  MueLu_Graph *graph;
26  graph = MueLu_BuildGraph(Amatrix, "ML_Uncoupled");
27 
28  if (graph->eGraph->Comm().MyPID() == 0 && mlAggregates->printFlag < MueLu_PrintLevel())
29  printf("ML_Aggregate_CoarsenUncoupled : \n");
30 
31  MueLu_AggOptions aggregateOptions;
32 
33  aggregateOptions.printFlag = mlAggregates->print_flag;
34  aggregateOptions.minNodesPerAggregate = mlAggregates->min_nodes_per_aggregate;
35  aggregateOptions.maxNeighAlreadySelected = mlAggregates->max_neigh_already_selected;
36  aggregateOptions.ordering = mlAggregates->ordering;
37  aggregateOptions.phase3AggCreation = mlAggregates->phase3_agg_creation;
38 
39  Aggregates *aggregates = NULL;
40 
41  aggregates = MueLu_Aggregate_CoarsenUncoupled(&aggregateOptions, graph);
42 
43  MueLu_AggregateLeftOvers(&aggregateOptions, aggregates, "UC_CleanUp", graph);
44 
45  //#ifdef out
46  Epetra_IntVector Final(aggregates->vertex2AggId->Map());
47  for (int i = 0; i < aggregates->vertex2AggId->Map().NumMyElements(); i++)
48  Final[i] = (*(aggregates->vertex2AggId))[i] + (*(aggregates->procWinner))[i] * 1000;
49  printf("finals\n");
50  cout << Final << endl;
51  sleep(2);
52  //#endif
53 
54  MueLu_AggregateDestroy(aggregates);
55  MueLu_DestroyGraph(graph);
56  return 0;
57 }
58 
59 /**********************************************************************************/
60 /* Function to take an ML_Matrix (which actually wraps an Epetra_CrsMatrix) and */
61 /* extract out the Epetra_CrsGraph. My guess is that this should be changed soon */
62 /* so that the first argument is some MueLu API Matrix. */
63 /**********************************************************************************/
64 MueLu_Graph *MueLu_BuildGraph(ML_Matrix *Amatrix, char *name) {
65  MueLu_Graph *graph;
66  double *dtmp = NULL;
68 
69  graph = (MueLu_Graph *)malloc(sizeof(MueLu_Graph));
70  graph->eGraph = NULL;
71  graph->name = NULL;
72  graph->name = (char *)malloc(sizeof(char) * 80);
73  strcpy(Graph->name, name);
74  graph->nVertices = Amatrix->invec_leng;
75 
76  if (Amatrix->getrow->nrows == 0) {
77  graph->vertexNeighbors = NULL;
78  graph->vertexNeighborsPtr = NULL;
79  graph->nEdges = 0;
80  } else {
81  Epetra_ML_GetCrsDataptrs(Amatrix, &dtmp, &(graph->vertexNeighbors), &(graph->vertexNeighborsPtr));
82  if (graph->vertexNeighborsPtr == NULL) {
83  printf("MueLu_BuildGraph: Only functions for an Epetra_CrsMatrix.\n");
84  exit(1);
85  }
86  graph->nEdges = (graph->vertexNeighborsPtr)[Amatrix->getrow->Nrows];
87  Epetra_ML_GetCrsMatrix(Amatrix, (void **)&A);
88  graph->eGraph = &(A->graph());
89  }
90  if (graph->eGraph == NULL)
91  graph->nGhost = 0;
92  else {
93  graph->nGhost = A->RowMatrixColMap().NumMyElements() - A->MatrixDomainMap().NumMyElements();
94  if (graph->nGhost < 0) graph->nGhost = 0;
95  }
96  return graph;
97 }
98 
99 int MueLu_DestroyGraph(MueLu_Graph *graph) {
100  if (graph != NULL) {
101  if (graph->name != NULL) free(graph->name);
102  free(graph);
103  }
104  return 0;
105 }
int MueLu_DestroyGraph(MueLu_Graph *graph)
Definition: ML_Linker.hpp:99
MueLu_Graph * MueLu_BuildGraph(ML_Matrix *Amatrix, char *name)
Definition: ML_Linker.hpp:64
int ML_Aggregate_CoarsenUncoupled(ML_Aggregate *mlAggregates, ML_Matrix *Amatrix, ML_Matrix **Pmatrix, ML_Comm *comm)
Definition: ML_Linker.hpp:23
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