FEI Version of the Day
fei_CommMap.hpp
00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2009 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #ifndef _fei_CommMap_hpp_
00010 #define _fei_CommMap_hpp_
00011 
00012 #include <fei_macros.hpp>
00013 #include <fei_ArrayUtils.hpp>
00014 #include <set>
00015 #include <map>
00016 
00017 namespace fei {
00018 
00020 template<typename T>
00021 struct CommMap {
00022   typedef std::map<int,std::vector<T> > Type;
00023 };
00024 
00031 template<typename T>
00032 void addItemsToCommMap(int proc, size_t numItems, const T* items,
00033                        typename CommMap<T>::Type& comm_map,
00034                        bool keep_sorted_and_unique = true)
00035 {
00036   typename CommMap<T>::Type::iterator iter = comm_map.find(proc);
00037   if (iter == comm_map.end()) {
00038     iter = comm_map.insert(std::make_pair(proc,std::vector<T>())).first;
00039   }
00040 
00041   std::vector<T>& comm_items = iter->second;
00042 
00043   if (keep_sorted_and_unique) {
00044     for(size_t i=0; i<numItems; ++i) {
00045       fei::sortedListInsert(items[i], comm_items);
00046     }
00047   }
00048   else {
00049     for(size_t i=0; i<numItems; ++i) {
00050       comm_items.push_back(items[i]);
00051     }
00052   }
00053 }
00054 
00055 } //namespace fei
00056 
00057 #endif // _fei_CommMap_hpp_
00058 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends