Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
algebra_id.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__LIB_ALGEBRA__PARALLELIZATION__ALGEBRA_ID__
34#define __H__LIB_ALGEBRA__PARALLELIZATION__ALGEBRA_ID__
35
36#include <utility>
37#include <vector>
38#include <map>
39#include "common/util/hash.h"
40#include "pcl/pcl.h"
41
42namespace ug{
43
45struct AlgebraID : public std::pair<int, size_t>
46{
47 AlgebraID() { first = -1; second = -1; }
48 AlgebraID(int _masterProc, size_t _indexOnMaster)
49 {
50 first = _masterProc;
51 second = _indexOnMaster;
52 }
53
54 int master_proc() const { return first; }
55 size_t index_on_master() const { return second; }
56 bool is_slave() const { return master_proc() != pcl::ProcRank(); }
57 bool is_master() const { return master_proc() == pcl::ProcRank(); }
58};
59
60template<>
61size_t hash_key<AlgebraID>(const AlgebraID& key);
62
63typedef std::vector<AlgebraID> AlgebraIDVec;
65
66std::ostream& operator<<(std::ostream &out, const AlgebraID &ID);
67
68
71{
72 PROFILE_FUNC_GROUP("algebra");
73// clear and resize the hash
74// We'll resize the hash to the number of algebraIDs, in order to have a
75// hopefully good mapping...
76 hash.clear();
77 hash.resize_hash(algebraIDs.size());
78 hash.reserve(algebraIDs.size());
79
80// now add all ids. We use the algebraID as key and the local index as value
81 for(size_t i = 0; i < algebraIDs.size(); ++i)
82 hash.insert(algebraIDs[i], i);
83}
84
85} // end namespace ug
86
87#endif /* __H__LIB_ALGEBRA__PARALLELIZATION__ALGEBRA_ID__ */
Definition hash.h:48
void insert(const key_t &key, const value_t &val)
Definition hash_impl.hpp:199
void reserve(size_t size)
Reserves memory for key-value-pair storage.
Definition hash_impl.hpp:113
void resize_hash(size_t size)
Definition hash_impl.hpp:66
void clear()
Definition hash_impl.hpp:129
std::ostream & operator<<(std::ostream &outStream, const ug::MathMatrix< 2, 2 > &m)
Definition math_matrix.cpp:38
int ProcRank()
returns the rank of the process
Definition pcl_base.cpp:83
the ug namespace
size_t hash_key< AlgebraID >(const AlgebraID &key)
Definition parallelization_util.cpp:48
std::vector< AlgebraID > AlgebraIDVec
Definition algebra_id.h:63
void GenerateAlgebraIDHashList(AlgebraIDHashList &hash, AlgebraIDVec &algebraIDs)
Creates a hash which allows a algebraID->localIndex mapping.
Definition algebra_id.h:70
Hash< AlgebraID, size_t > AlgebraIDHashList
Definition algebra_id.h:64
#define PROFILE_FUNC_GROUP(groups)
Definition profiler.h:258
this type is used to identify distributed objects.
Definition algebra_id.h:46
AlgebraID()
Definition algebra_id.h:47
int master_proc() const
Definition algebra_id.h:54
AlgebraID(int _masterProc, size_t _indexOnMaster)
Definition algebra_id.h:48
size_t index_on_master() const
Definition algebra_id.h:55
bool is_slave() const
Definition algebra_id.h:56
bool is_master() const
Definition algebra_id.h:57