[c40e15d] | 1 | /*
|
---|
[ff9963] | 2 | * AllLevelSummator.hpp
|
---|
[c40e15d] | 3 | *
|
---|
| 4 | * Created on: 29.07.2012
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[ff9963] | 8 | #ifndef ALLLEVELSUMMATOR_HPP_
|
---|
| 9 | #define ALLLEVELSUMMATOR_HPP_
|
---|
[c40e15d] | 10 |
|
---|
| 11 | // include config.h
|
---|
| 12 | #ifdef HAVE_CONFIG_H
|
---|
| 13 | #include <config.h>
|
---|
| 14 | #endif
|
---|
| 15 |
|
---|
| 16 | #include <vector>
|
---|
| 17 |
|
---|
[ff9963] | 18 | #include "CodePatterns/Assert.hpp"
|
---|
| 19 |
|
---|
[c40e15d] | 20 | #include "Fragmentation/Summation/IndexSetContainer.hpp"
|
---|
| 21 | #include "Fragmentation/Summation/SubsetMap.hpp"
|
---|
| 22 | #include "Fragmentation/Summation/Summator.hpp"
|
---|
[da098d2] | 23 | #include "Fragmentation/Summation/ZeroInstance.hpp"
|
---|
[c40e15d] | 24 |
|
---|
| 25 | #include "Fragmentation/Summation/printKeyNames.hpp"
|
---|
| 26 |
|
---|
[ff9963] | 27 | /** Tiny template functor to use Summation, sum up each level, and store the
|
---|
| 28 | * result in a given vector.
|
---|
[c40e15d] | 29 | *
|
---|
| 30 | */
|
---|
| 31 | template <typename MapType>
|
---|
[ff9963] | 32 | struct AllLevelSummator {
|
---|
[c40e15d] | 33 | /** Constructor takes the arguments that \a Summator also needs and stores
|
---|
| 34 | * them internally.
|
---|
| 35 | *
|
---|
| 36 | * \param _subsetmap map with hierarchy of IndexSet's
|
---|
[c9f9bb] | 37 | * \param _data MPQCData converted to MPQCDataMap_t type, associated to job id
|
---|
[c40e15d] | 38 | * \param _container container of IndexSet's such that each set has correct order
|
---|
| 39 | * to job id and hence to _data.
|
---|
[675cd6] | 40 | * \param _MatrixNrLookup lookup from job id to ordering in above vectors, if
|
---|
| 41 | * out of range this value is set to zero, hence ignored.
|
---|
[b8f0b25] | 42 | * \param _levelresults vector place levelresults into
|
---|
[da098d2] | 43 | * \param _keysetresults results per index set, set by operator()
|
---|
| 44 | * \param _ZeroInstances zero instance to use in summation for each type
|
---|
[c40e15d] | 45 | */
|
---|
[ff9963] | 46 | AllLevelSummator(
|
---|
[c40e15d] | 47 | SubsetMap::ptr &_subsetmap,
|
---|
[c9f9bb] | 48 | const std::map<JobId_t, MapType> &_data,
|
---|
[c40e15d] | 49 | const IndexSetContainer::Container_t &_container,
|
---|
[3dd32f] | 50 | const std::map< JobId_t, size_t > &_MatrixNrLookup,
|
---|
[b8f0b25] | 51 | std::vector<MapType> &_levelresults,
|
---|
[da098d2] | 52 | std::map<IndexSet::ptr, std::pair<MapType, MapType> > &_keysetresults,
|
---|
| 53 | MapType &_ZeroInstances) :
|
---|
[c40e15d] | 54 | subsetmap(_subsetmap),
|
---|
| 55 | data(_data),
|
---|
| 56 | container(_container),
|
---|
[ff9963] | 57 | MatrixNrLookup(_MatrixNrLookup),
|
---|
[b8f0b25] | 58 | levelresults(_levelresults),
|
---|
[da098d2] | 59 | keysetresults(_keysetresults),
|
---|
| 60 | ZeroInstances(_ZeroInstances)
|
---|
[ff9963] | 61 | {
|
---|
[b8f0b25] | 62 | ASSERT( levelresults.size() >= subsetmap->getMaximumSetLevel(),
|
---|
[ff9963] | 63 | "AllLevelSummator() - result vector is not large enough.");
|
---|
| 64 | }
|
---|
[c40e15d] | 65 |
|
---|
| 66 | /** Operator that calls on Summator and prints the value.
|
---|
| 67 | *
|
---|
| 68 | * \note the parameter is needed for boost::mpl::for_each but is not
|
---|
| 69 | * used here.
|
---|
| 70 | */
|
---|
| 71 | template <typename MapKey>
|
---|
| 72 | void operator()(MapKey &) {
|
---|
| 73 | // We retrieve the type of the MPQCData member variable from the boost::fusion::map.
|
---|
| 74 | typedef typename boost::fusion::result_of::value_at_key<MapType, MapKey>::type MapValue;
|
---|
[b8f0b25] | 75 |
|
---|
[c40e15d] | 76 | // create Summator instance
|
---|
| 77 | Summator<MapType, MapKey> sum_value(
|
---|
[c9f9bb] | 78 | subsetmap, data, container, MatrixNrLookup
|
---|
[c40e15d] | 79 | );
|
---|
[b8f0b25] | 80 |
|
---|
[da098d2] | 81 | // set zero instance
|
---|
| 82 | const MapValue &DesiredZeroInstance = boost::fusion::at_key<MapKey>(ZeroInstances);
|
---|
| 83 | if (DesiredZeroInstance != ZeroInstance<MapValue>())
|
---|
| 84 | sum_value.setZeroInstance(DesiredZeroInstance);
|
---|
| 85 |
|
---|
[b8f0b25] | 86 | // fill levelresults
|
---|
[19c50e] | 87 | const size_t MaxLevel = subsetmap->getMaximumSetLevel();
|
---|
[ff9963] | 88 | for (size_t level=1; level <= MaxLevel; ++level) {
|
---|
[b8f0b25] | 89 | MapType &LevelResults = levelresults[level-1];
|
---|
| 90 | // sum up and store in levelresults
|
---|
[ff9963] | 91 | const MapValue value = sum_value(level);
|
---|
| 92 | boost::fusion::at_key<MapKey>(LevelResults) = value;
|
---|
| 93 | // print value
|
---|
| 94 | //LOG(0, "STATUS: Level " << level << " resulting " << printKeyNames::printName<MapKey>() << " is " << value << ".");
|
---|
| 95 | }
|
---|
[b8f0b25] | 96 |
|
---|
| 97 | // fill keysetresults
|
---|
| 98 | for (IndexSetContainer::Container_t::const_iterator indexsetiter = container.begin();
|
---|
| 99 | indexsetiter != container.end(); ++indexsetiter) {
|
---|
| 100 | const IndexSet::ptr &index = *indexsetiter;
|
---|
| 101 | // this either generates a new entry or updates the present one, as we obtain ref to value
|
---|
[79398d] | 102 | boost::fusion::at_key<MapKey>(keysetresults[index].first) =
|
---|
| 103 | sum_value.getValueForIndexSet(index);
|
---|
| 104 | boost::fusion::at_key<MapKey>(keysetresults[index].second) =
|
---|
[b8f0b25] | 105 | sum_value.getContributionForIndexSet(index);
|
---|
| 106 | }
|
---|
[c40e15d] | 107 | }
|
---|
| 108 |
|
---|
| 109 | private:
|
---|
| 110 | //!> Hierarchy of IndexSet's
|
---|
| 111 | SubsetMap::ptr &subsetmap;
|
---|
| 112 | //!> vector of data converted from MPQCData
|
---|
[c9f9bb] | 113 | const std::map<JobId_t, MapType> &data;
|
---|
[c40e15d] | 114 | //!> container with all IndexSet's
|
---|
| 115 | const IndexSetContainer::Container_t &container;
|
---|
| 116 | //!> lookup map from job ids to ordering in above vectors
|
---|
[3dd32f] | 117 | const std::map< JobId_t, size_t > &MatrixNrLookup;
|
---|
[b8f0b25] | 118 | //!> vector of levelresults
|
---|
| 119 | std::vector<MapType> &levelresults;
|
---|
[79398d] | 120 | typedef std::pair< IndexSet::ptr, std::pair<MapType, MapType> > keysetresults_pair_t;
|
---|
[b8f0b25] | 121 | //!> typedef for map for keyset and each resulting value
|
---|
[79398d] | 122 | typedef std::map<IndexSet::ptr, std::pair<MapType, MapType> > keysetresults_t;
|
---|
[b8f0b25] | 123 | //!> map for IndexSet and its associated contribution
|
---|
| 124 | keysetresults_t &keysetresults;
|
---|
[da098d2] | 125 | //!> map per type to sum of base/zero instances to enforce specific parameters in summation
|
---|
| 126 | MapType &ZeroInstances;
|
---|
[c40e15d] | 127 | };
|
---|
| 128 |
|
---|
[ff9963] | 129 | #endif /* ALLLEVELSUMMATOR_HPP_ */
|
---|