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