ug4
partition_map.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG__partition_map__
34 #define __H__UG__partition_map__
35 
37 #include "lib_grid/grid/grid.h"
40 
41 namespace ug
42 {
43 
48 
55  public:
56  PartitionMap();
57 
58  void clear();
59 
60  void assign_grid(Grid& grid);
61 
63 
64  void add_target_proc(int tarProcRank);
65 
66  void add_target_procs(int first, int num);
67 
68  size_t num_target_procs();
69 
70  int get_target_proc(size_t index);
71 
72  int* get_target_procs();
73 
74  std::vector<int>& get_target_proc_vec();
75 
77  bool change_target_proc(size_t index, int newRank);
78 
80  int find_target_proc(int procRank);
81 
83  void shift_target_procs(int offset);
84 
85  private:
87  std::vector<int> m_targetProcs;
88 };
89 
91 
92 
93 
95 
101 template <class TAPos>
102 bool SavePartitionMapToFile(PartitionMap& pm, const char* filename,
103  TAPos& aPos)
104 {
105  SubsetHandler& partsh = *pm.get_partition_handler();
106 
107 // make sure that a grid exists
108  if(!partsh.grid()){
109  UG_LOG("WARNING IN SavePartitionMapToFile: a grid has to be assigned "
110  "to the PartitionMap. Aborting.\n");
111  return false;
112  }
113 
114  Grid& grid = *partsh.grid();
115 
116 // we need a subset-handler, which will have a 1-1 subset-process relation.
117  SubsetHandler sh(grid);
118 
119 // add all partitions to the handler
120  for(int si = 0; si < partsh.num_subsets(); ++si){
121  int newSI = pm.get_target_proc(si);
122  sh.assign_subset(partsh.begin<Vertex>(si),
123  partsh.end<Vertex>(si), newSI);
124  sh.assign_subset(partsh.begin<Edge>(si),
125  partsh.end<Edge>(si), newSI);
126  sh.assign_subset(partsh.begin<Face>(si),
127  partsh.end<Face>(si), newSI);
128  sh.assign_subset(partsh.begin<Volume>(si),
129  partsh.end<Volume>(si), newSI);
130  }
131 
132 // now save the grid to file
133  return SaveGridToFile(grid, sh, filename, aPos);
134 }
135 
138 }// end of namespace
139 
140 #endif
Definition: smart_pointer.h:108
Base-class for edges.
Definition: grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
Partitions elements of a grid into several subsets.
Definition: subset_handler_grid.h:53
void assign_subset(Vertex *elem, int subsetIndex)
assigns a vertex to a subset.
Definition: subset_handler_grid.cpp:204
geometry_traits< TElem >::iterator end(int subsetIndex)
returns the end-iterator for the elements of type TElem in the given subset.
Definition: subset_handler_grid_impl.hpp:63
geometry_traits< TElem >::iterator begin(int subsetIndex)
returns the begin-iterator for the elements of type TElem in the given subset.
Definition: subset_handler_grid_impl.hpp:44
Grid * grid() const
returns a pointer to the grid on which the subset-handler works.
Definition: subset_handler_interface.cpp:304
int num_subsets() const
returns the number of subset-infos (return value is int, since SubsetIndices are of type int)
Definition: subset_handler_interface.h:317
Used to describe how a domain shall be distributed in a parallel environment.
Definition: partition_map.h:54
SmartPtr< SubsetHandler > m_shPartitions
Definition: partition_map.h:86
bool change_target_proc(size_t index, int newRank)
changes an existing target process. Make sure that index < num_target_procs
Definition: partition_map.cpp:93
int * get_target_procs()
Definition: partition_map.cpp:87
SmartPtr< SubsetHandler > get_partition_handler()
Definition: partition_map.cpp:58
std::vector< int > m_targetProcs
Definition: partition_map.h:87
void shift_target_procs(int offset)
adds the given offset to all target-proc-ranks
Definition: partition_map.cpp:114
void clear()
Definition: partition_map.cpp:46
size_t num_target_procs()
Definition: partition_map.cpp:70
void assign_grid(Grid &grid)
Definition: partition_map.cpp:52
int get_target_proc(size_t index)
Definition: partition_map.cpp:73
std::vector< int > & get_target_proc_vec()
Definition: partition_map.cpp:90
void add_target_proc(int tarProcRank)
Definition: partition_map.cpp:61
int find_target_proc(int procRank)
returns the index at which the given process lies. -1 if it doesn't exist.
Definition: partition_map.cpp:105
PartitionMap()
Definition: partition_map.cpp:41
void add_target_procs(int first, int num)
Definition: partition_map.cpp:64
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
#define UG_LOG(msg)
Definition: log.h:367
the ug namespace
bool SaveGridToFile(Grid &grid, ISubsetHandler &sh, const char *filename, TAPos &aPos)
Saves a grid to a file. Position data is read from the specified attachment.
Definition: file_io.cpp:468
bool SavePartitionMapToFile(PartitionMap &pm, const char *filename, TAPos &aPos)
Save the partition map to a file.
Definition: partition_map.h:102
SmartPtr< PartitionMap > SPPartitionMap
Save the partition map to a file.
Definition: partition_map.h:90