Line data Source code
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 : #include "partition_map.h"
34 :
35 : using namespace std;
36 :
37 : namespace ug{
38 :
39 : ////////////////////////////////////////////////////////////////////////////////
40 : // IMPLEMENTATION OF PartitionMap
41 0 : PartitionMap::PartitionMap()
42 : {
43 0 : m_shPartitions = make_sp(new SubsetHandler());
44 0 : }
45 :
46 0 : void PartitionMap::clear()
47 : {
48 : m_targetProcs.clear();
49 0 : m_shPartitions->clear();
50 0 : }
51 :
52 0 : void PartitionMap::assign_grid(Grid& grid)
53 : {
54 0 : if(&grid != m_shPartitions->grid())
55 0 : m_shPartitions->assign_grid(grid);
56 0 : }
57 :
58 0 : SmartPtr<SubsetHandler> PartitionMap::get_partition_handler()
59 0 : {return m_shPartitions;}
60 :
61 0 : void PartitionMap::add_target_proc(int tarProcRank)
62 0 : {m_targetProcs.push_back(tarProcRank);}
63 :
64 0 : void PartitionMap::add_target_procs(int first, int num)
65 : {
66 0 : for(int i = 0; i < num; ++i)
67 0 : add_target_proc(first + i);
68 0 : }
69 :
70 0 : size_t PartitionMap::num_target_procs()
71 0 : {return m_targetProcs.size();}
72 :
73 0 : int PartitionMap::get_target_proc(size_t index)
74 : {
75 0 : if(index < m_targetProcs.size())
76 0 : return m_targetProcs[index];
77 : UG_LOG("BAD INDEX in PartitionMap::get_target_proc: " << index);
78 0 : if(num_target_procs() > 0){
79 0 : UG_LOG(" Max valid index: " << num_target_procs() - 1 << endl);
80 : }
81 : else{
82 : UG_LOG(" No target processes available.\n");
83 : }
84 : return -1;
85 : }
86 :
87 0 : int* PartitionMap::get_target_procs()
88 0 : {return &m_targetProcs.front();}
89 :
90 0 : std::vector<int>& PartitionMap::get_target_proc_vec()
91 0 : {return m_targetProcs;}
92 :
93 0 : bool PartitionMap::change_target_proc(size_t index, int newRank)
94 : {
95 : // make sure that the given index is valid
96 0 : if(index >= num_target_procs()){
97 : UG_LOG("WARNING in PartitionMap::change_target_proc: Bad index given.\n");
98 0 : return false;
99 : }
100 :
101 0 : m_targetProcs[index] = newRank;
102 0 : return true;
103 : }
104 :
105 0 : int PartitionMap::find_target_proc(int procRank)
106 : {
107 0 : for(size_t i = 0; i < m_targetProcs.size(); ++i){
108 0 : if(m_targetProcs[i] == procRank)
109 0 : return i;
110 : }
111 : return -1;
112 : }
113 :
114 0 : void PartitionMap::shift_target_procs(int offset)
115 : {
116 0 : for(size_t i = 0; i < m_targetProcs.size(); ++i){
117 0 : m_targetProcs[i] += offset;
118 : }
119 0 : }
120 :
121 : }// end of namespace
|