| [0398bd] | 1 | /* | 
|---|
|  | 2 | * SumUpPerLevel.hpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Aug 27, 2012 | 
|---|
|  | 5 | *      Author: heber | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #ifndef SUMUPPERLEVEL_HPP_ | 
|---|
|  | 9 | #define SUMUPPERLEVEL_HPP_ | 
|---|
|  | 10 |  | 
|---|
|  | 11 |  | 
|---|
|  | 12 | // include config.h | 
|---|
|  | 13 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 14 | #include <config.h> | 
|---|
|  | 15 | #endif | 
|---|
|  | 16 |  | 
|---|
|  | 17 | #include <map> | 
|---|
|  | 18 | #include <vector> | 
|---|
|  | 19 |  | 
|---|
| [fbf143] | 20 | #include "Fragmentation/Summation/Converter/DataConverter.hpp" | 
|---|
| [0398bd] | 21 | #include "Fragmentation/Summation/AllLevelSummator.hpp" | 
|---|
| [b8f0b25] | 22 | #include "Fragmentation/Summation/IndexSet.hpp" | 
|---|
| [0398bd] | 23 | #include "Fragmentation/Summation/IndexSetContainer.hpp" | 
|---|
|  | 24 |  | 
|---|
| [fbf143] | 25 | #include "Fragmentation/Summation/Containers/MPQCData.hpp" | 
|---|
| [0398bd] | 26 |  | 
|---|
|  | 27 | #include <boost/mpl/for_each.hpp> | 
|---|
|  | 28 |  | 
|---|
| [a3112d] | 29 | template <typename TypeMap, typename TypeData, typename TypeVector> | 
|---|
| [409a05] | 30 | struct SumUpPerLevel | 
|---|
| [0398bd] | 31 | { | 
|---|
| [409a05] | 32 | SumUpPerLevel(const std::map<JobId_t, TypeData> &fragmentData) | 
|---|
|  | 33 | { | 
|---|
|  | 34 | // place data into boost::fusion::map instance | 
|---|
|  | 35 | convertDataTo<TypeData, TypeMap>(fragmentData, Data_fused); | 
|---|
| [da098d2] | 36 |  | 
|---|
| [409a05] | 37 | // initialize zero instance map | 
|---|
|  | 38 | ZeroInstanceInitializer<TypeMap> initZeroInstance(ZeroInstances); | 
|---|
|  | 39 | boost::mpl::for_each<TypeVector>(boost::ref(initZeroInstance)); | 
|---|
|  | 40 | } | 
|---|
|  | 41 |  | 
|---|
|  | 42 | /** Setter for a specific zero value for the given \a MapValue type. | 
|---|
|  | 43 | * | 
|---|
|  | 44 | * \param _zeroinstance zero instance to set for type \a MapValue | 
|---|
|  | 45 | */ | 
|---|
|  | 46 | template <typename MapKey> | 
|---|
|  | 47 | void setZeroInstance( | 
|---|
|  | 48 | const typename boost::fusion::result_of::value_at_key<TypeMap, MapKey>::type &_zeroinstance) | 
|---|
|  | 49 | { | 
|---|
|  | 50 | boost::fusion::at_key<MapKey>(ZeroInstances) = _zeroinstance; | 
|---|
|  | 51 | } | 
|---|
| [0398bd] | 52 |  | 
|---|
| [409a05] | 53 | /** Perform the actual summation for each type in \a TypeMap, given by | 
|---|
|  | 54 | * \a TypeVector. | 
|---|
|  | 55 | * | 
|---|
|  | 56 | * i.e. we boost::fusion::for_each over each type in \a TypeVector and perform | 
|---|
|  | 57 | * an AllLevelSummator on the type. | 
|---|
|  | 58 | * | 
|---|
|  | 59 | * \param MatrixNrLookup lookup from job number to a consecutive index in a vector, starting at 0 | 
|---|
|  | 60 | * \param container container of all indexsets | 
|---|
|  | 61 | * \param subsetmap map with all subsets for each indexset | 
|---|
|  | 62 | * \param levelresults after summation contains results for each level | 
|---|
|  | 63 | * \param keysetresults after summation contains results for each keyset | 
|---|
|  | 64 | */ | 
|---|
|  | 65 | void operator()( | 
|---|
|  | 66 | const std::map< JobId_t, size_t > &MatrixNrLookup, | 
|---|
|  | 67 | const IndexSetContainer::ptr &container, | 
|---|
|  | 68 | SubsetMap::ptr &subsetmap, | 
|---|
|  | 69 | std::vector<TypeMap> &levelresults, | 
|---|
|  | 70 | std::map<IndexSet::ptr, std::pair<TypeMap, TypeMap> > &keysetresults | 
|---|
|  | 71 | ) | 
|---|
|  | 72 | { | 
|---|
|  | 73 | // instantiate summator | 
|---|
|  | 74 | levelresults.resize(subsetmap->getMaximumSetLevel()); | 
|---|
|  | 75 | AllLevelSummator<TypeMap> Summer( | 
|---|
|  | 76 | subsetmap, | 
|---|
|  | 77 | Data_fused, | 
|---|
|  | 78 | container->getContainer(), | 
|---|
|  | 79 | MatrixNrLookup, | 
|---|
|  | 80 | levelresults, | 
|---|
|  | 81 | keysetresults, | 
|---|
|  | 82 | ZeroInstances); | 
|---|
|  | 83 | // sum up for each type key in TypeVector | 
|---|
|  | 84 | boost::mpl::for_each<TypeVector>(boost::ref(Summer)); | 
|---|
|  | 85 | } | 
|---|
|  | 86 |  | 
|---|
|  | 87 | //!> map with all jobs placed into boost::fusion::maps | 
|---|
|  | 88 | std::map<JobId_t, TypeMap> Data_fused; | 
|---|
|  | 89 | //!> zero instances to use in summation | 
|---|
|  | 90 | TypeMap ZeroInstances; | 
|---|
|  | 91 | }; | 
|---|
| [0398bd] | 92 |  | 
|---|
|  | 93 | #endif /* SUMUPPERLEVEL_HPP_ */ | 
|---|