FEI Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fei_CommMap.hpp
Go to the documentation of this file.
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2009 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #ifndef _fei_CommMap_hpp_
10 #define _fei_CommMap_hpp_
11 
12 #include <fei_macros.hpp>
13 #include <fei_ArrayUtils.hpp>
14 #include <set>
15 #include <map>
16 
17 namespace fei {
18 
20 template<typename T>
21 struct CommMap {
22  typedef std::map<int,std::vector<T> > Type;
23 };
24 
31 template<typename T>
32 void addItemsToCommMap(int proc, size_t numItems, const T* items,
33  typename CommMap<T>::Type& comm_map,
34  bool keep_sorted_and_unique = true)
35 {
36  typename CommMap<T>::Type::iterator iter = comm_map.find(proc);
37  if (iter == comm_map.end()) {
38  iter = comm_map.insert(std::make_pair(proc,std::vector<T>())).first;
39  }
40 
41  std::vector<T>& comm_items = iter->second;
42 
43  if (keep_sorted_and_unique) {
44  for(size_t i=0; i<numItems; ++i) {
45  fei::sortedListInsert(items[i], comm_items);
46  }
47  }
48  else {
49  for(size_t i=0; i<numItems; ++i) {
50  comm_items.push_back(items[i]);
51  }
52  }
53 }
54 
55 } //namespace fei
56 
57 #endif // _fei_CommMap_hpp_
58 
void addItemsToCommMap(int proc, size_t numItems, const T *items, typename CommMap< T >::Type &comm_map, bool keep_sorted_and_unique=true)
Definition: fei_CommMap.hpp:32
int sortedListInsert(const T &item, std::vector< T > &list)
std::map< int, std::vector< T > > Type
Definition: fei_CommMap.hpp:22