source: src/Fragmentation/Summation/SumUpPerLevel.hpp

Candidate_v1.6.1
Last change on this file was 409a05, checked in by Frederik Heber <heber@…>, 8 years ago

..SumUpPerLevel are now functors that allow to set the zero instance of a specific type.

  • Property mode set to 100644
File size: 2.9 KB
Line 
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
20#include "Fragmentation/Summation/Converter/DataConverter.hpp"
21#include "Fragmentation/Summation/AllLevelSummator.hpp"
22#include "Fragmentation/Summation/IndexSet.hpp"
23#include "Fragmentation/Summation/IndexSetContainer.hpp"
24
25#include "Fragmentation/Summation/Containers/MPQCData.hpp"
26
27#include <boost/mpl/for_each.hpp>
28
29template <typename TypeMap, typename TypeData, typename TypeVector>
30struct SumUpPerLevel
31{
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);
36
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 }
52
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};
92
93#endif /* SUMUPPERLEVEL_HPP_ */
Note: See TracBrowser for help on using the repository browser.