[0398bd] | 1 | /*
|
---|
| 2 | * DataConverter.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Aug 27, 2012
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef DATACONVERTER_HPP_
|
---|
| 9 | #define DATACONVERTER_HPP_
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | // include config.h
|
---|
| 13 | #ifdef HAVE_CONFIG_H
|
---|
| 14 | #include <config.h>
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
[c9f9bb] | 17 | #include <map>
|
---|
[0398bd] | 18 | #include <boost/fusion/sequence.hpp>
|
---|
| 19 |
|
---|
| 20 | #include "CodePatterns/Assert.hpp"
|
---|
| 21 |
|
---|
[8e84fe] | 22 | #ifdef HAVE_JOBMARKET
|
---|
[0398bd] | 23 | #include "JobMarket/types.hpp"
|
---|
[8e84fe] | 24 | #else
|
---|
| 25 | typedef size_t JobId_t;
|
---|
| 26 | #endif
|
---|
[0398bd] | 27 |
|
---|
| 28 | #include "Fragmentation/KeySetsContainer.hpp"
|
---|
[5c867e] | 29 | #include "Fragmentation/Summation/SetValues/Eigenvalues.hpp"
|
---|
[fbf143] | 30 | #include "Fragmentation/Summation/SetValues/Histogram.hpp"
|
---|
| 31 | #include "Fragmentation/Summation/SetValues/Fragment.hpp"
|
---|
| 32 | #include "Fragmentation/Summation/SetValues/IndexedVectors.hpp"
|
---|
[0398bd] | 33 |
|
---|
[fbf143] | 34 | #include "Fragmentation/Summation/Containers/MPQCData.hpp"
|
---|
| 35 | #include "Fragmentation/Summation/Containers/MPQCDataFused.hpp"
|
---|
| 36 | #include "Fragmentation/Summation/Containers/MPQCDataMap.hpp"
|
---|
[0398bd] | 37 | #ifdef HAVE_VMG
|
---|
[fbf143] | 38 | #include "Fragmentation/Summation/Containers/VMGData.hpp"
|
---|
| 39 | #include "Fragmentation/Summation/Containers/VMGDataFused.hpp"
|
---|
| 40 | #include "Fragmentation/Summation/Containers/VMGDataMap.hpp"
|
---|
[0398bd] | 41 | #endif
|
---|
| 42 |
|
---|
| 43 | template <typename source, typename dest>
|
---|
| 44 | inline void convertDataTo(
|
---|
[c9f9bb] | 45 | const std::map<JobId_t, source> &fragmentData,
|
---|
| 46 | std::map<JobId_t, dest> &MPQCData_fused)
|
---|
[0398bd] | 47 | {
|
---|
| 48 | MPQCData_fused.clear();
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | template <>
|
---|
| 52 | inline void convertDataTo<MPQCData, MPQCDataEnergyMap_t>(
|
---|
[c9f9bb] | 53 | const std::map<JobId_t, MPQCData> &fragmentData,
|
---|
| 54 | std::map<JobId_t, MPQCDataEnergyMap_t> &MPQCData_Energy_fused)
|
---|
[0398bd] | 55 | {
|
---|
| 56 | // energy_t
|
---|
| 57 | MPQCData_Energy_fused.clear();
|
---|
[c9f9bb] | 58 | for(std::map<JobId_t, MPQCData>::const_iterator dataiter = fragmentData.begin();
|
---|
[0398bd] | 59 | dataiter != fragmentData.end(); ++dataiter) {
|
---|
[c9f9bb] | 60 | const MPQCData &extractedData = dataiter->second;
|
---|
[0398bd] | 61 | LOG(4, "DEBUG: Current extracted Data is " << extractedData << ".");
|
---|
| 62 | MPQCDataEnergyMap_t instance;
|
---|
| 63 | boost::fusion::at_key<MPQCDataFused::energy_total>(instance) = extractedData.energies.total;
|
---|
| 64 | boost::fusion::at_key<MPQCDataFused::energy_nuclear_repulsion>(instance) = extractedData.energies.nuclear_repulsion;
|
---|
| 65 | boost::fusion::at_key<MPQCDataFused::energy_electron_coulomb>(instance) = extractedData.energies.electron_coulomb;
|
---|
| 66 | boost::fusion::at_key<MPQCDataFused::energy_electron_exchange>(instance) = extractedData.energies.electron_exchange;
|
---|
| 67 | boost::fusion::at_key<MPQCDataFused::energy_correlation>(instance) = extractedData.energies.correlation;
|
---|
| 68 | boost::fusion::at_key<MPQCDataFused::energy_overlap>(instance) = extractedData.energies.overlap;
|
---|
| 69 | boost::fusion::at_key<MPQCDataFused::energy_kinetic>(instance) = extractedData.energies.kinetic;
|
---|
| 70 | boost::fusion::at_key<MPQCDataFused::energy_hcore>(instance) = extractedData.energies.hcore;
|
---|
| 71 | boost::fusion::at_key<MPQCDataFused::energy_eigenvalues>(instance) = extractedData.energies.eigenvalues;
|
---|
[5c867e] | 72 | boost::fusion::at_key<MPQCDataFused::energy_eigenhistogram>(instance) = extractedData.energies.eigenvalues;
|
---|
[c9f9bb] | 73 | MPQCData_Energy_fused.insert( std::make_pair(dataiter->first, instance) );
|
---|
[0398bd] | 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | #ifdef HAVE_VMG
|
---|
| 78 | template <>
|
---|
| 79 | inline void convertDataTo<VMGData, VMGDataMap_t>(
|
---|
[c9f9bb] | 80 | const std::map<JobId_t, VMGData> &longrangeData,
|
---|
| 81 | std::map<JobId_t, VMGDataMap_t> &VMGData_fused)
|
---|
[0398bd] | 82 | {
|
---|
| 83 | // energy_t
|
---|
| 84 | VMGData_fused.clear();
|
---|
[c9f9bb] | 85 | for(std::map<JobId_t, VMGData>::const_iterator dataiter = longrangeData.begin();
|
---|
[0398bd] | 86 | dataiter != longrangeData.end(); ++dataiter) {
|
---|
[c9f9bb] | 87 | const VMGData &extractedData = dataiter->second;
|
---|
[0398bd] | 88 | LOG(4, "DEBUG: Current extracted Data is " << extractedData << ".");
|
---|
| 89 | VMGDataMap_t instance;
|
---|
[e2925fd] | 90 | boost::fusion::at_key<VMGDataFused::nuclei_long>(instance) = extractedData.nuclei_long;
|
---|
| 91 | boost::fusion::at_key<VMGDataFused::electron_long>(instance) = extractedData.electron_long;
|
---|
[c9f9bb] | 92 | VMGData_fused.insert( std::make_pair(dataiter->first, instance) );
|
---|
[0398bd] | 93 | }
|
---|
| 94 | }
|
---|
[83a425] | 95 |
|
---|
| 96 | template <>
|
---|
| 97 | inline void convertDataTo<VMGData, VMGDataGridMap_t>(
|
---|
| 98 | const std::map<JobId_t, VMGData> &longrangeData,
|
---|
| 99 | std::map<JobId_t, VMGDataGridMap_t> &VMGData_fused)
|
---|
| 100 | {
|
---|
| 101 | // energy_t
|
---|
| 102 | VMGData_fused.clear();
|
---|
| 103 | for(std::map<JobId_t, VMGData>::const_iterator dataiter = longrangeData.begin();
|
---|
| 104 | dataiter != longrangeData.end(); ++dataiter) {
|
---|
| 105 | const VMGData &extractedData = dataiter->second;
|
---|
| 106 | LOG(4, "DEBUG: Current extracted Data is " << extractedData << ".");
|
---|
| 107 | VMGDataGridMap_t instance;
|
---|
| 108 | boost::fusion::at_key<VMGDataFused::sampled_potential>(instance) = extractedData.sampled_potential;
|
---|
| 109 | boost::fusion::at_key<VMGDataFused::both_sampled_potential>(instance) = extractedData.both_sampled_potential;
|
---|
| 110 | VMGData_fused.insert( std::make_pair(dataiter->first, instance) );
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
[0398bd] | 113 | #endif
|
---|
| 114 |
|
---|
[94db13] | 115 | template <class datatype, class dataforcemap, class dataforcefused>
|
---|
| 116 | inline void convertDatatoForceMap(
|
---|
| 117 | const std::map<JobId_t, datatype> &fragmentData,
|
---|
[0398bd] | 118 | const KeySetsContainer &ForceKeySet,
|
---|
[94db13] | 119 | std::map<JobId_t, dataforcemap> &Data_Force_fused)
|
---|
[0398bd] | 120 | {
|
---|
| 121 | // forces
|
---|
| 122 | ASSERT( ForceKeySet.KeySets.size() == fragmentData.size(),
|
---|
| 123 | "FragmentationAutomationAction::performCall() - indices and fragmentData differ in size.");
|
---|
[94db13] | 124 | Data_Force_fused.clear();
|
---|
| 125 | typename std::map<JobId_t, datatype>::const_iterator dataiter = fragmentData.begin();
|
---|
[0398bd] | 126 | KeySetsContainer::ArrayOfIntVectors::const_iterator arrayiter = ForceKeySet.KeySets.begin();
|
---|
| 127 | for(;dataiter != fragmentData.end(); ++dataiter, ++arrayiter) {
|
---|
[94db13] | 128 | const datatype &extractedData = dataiter->second;
|
---|
[0398bd] | 129 | LOG(4, "DEBUG: Current extracted Data is " << extractedData << ".");
|
---|
[94db13] | 130 | dataforcemap instance;
|
---|
[0398bd] | 131 | // must convert int to index_t
|
---|
[98a293b] | 132 | if (DoLog(5)) {
|
---|
| 133 | std::stringstream output;
|
---|
| 134 | for (KeySetsContainer::IntVector::const_iterator outiter = arrayiter->begin();
|
---|
| 135 | outiter != arrayiter->end(); ++outiter) {
|
---|
| 136 | output << *outiter << "\t";
|
---|
| 137 | }
|
---|
| 138 | LOG(5, "DEBUG: indices are " << output.str());
|
---|
| 139 | }
|
---|
[0398bd] | 140 | IndexedVectors::indices_t indices(arrayiter->begin(), arrayiter->end());
|
---|
[94db13] | 141 | boost::fusion::at_key<typename dataforcefused::forces>(instance) =
|
---|
[0398bd] | 142 | IndexedVectors(indices, extractedData.forces);
|
---|
[94db13] | 143 | Data_Force_fused.insert( std::make_pair(dataiter->first, instance) );
|
---|
[0398bd] | 144 | }
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | template <>
|
---|
| 148 | inline void convertDataTo<MPQCData, MPQCDataGridMap_t>(
|
---|
[c9f9bb] | 149 | const std::map<JobId_t, MPQCData> &fragmentData,
|
---|
| 150 | std::map<JobId_t, MPQCDataGridMap_t> &MPQCData_Grid_fused)
|
---|
[0398bd] | 151 | {
|
---|
| 152 | // sampled_grid
|
---|
| 153 | MPQCData_Grid_fused.clear();
|
---|
[c9f9bb] | 154 | for(std::map<JobId_t, MPQCData>::const_iterator dataiter = fragmentData.begin();
|
---|
[0398bd] | 155 | dataiter != fragmentData.end(); ++dataiter) {
|
---|
[c9f9bb] | 156 | const MPQCData &extractedData = dataiter->second;
|
---|
[0398bd] | 157 | LOG(4, "DEBUG: Current extracted Data is " << extractedData << ".");
|
---|
| 158 | MPQCDataGridMap_t instance;
|
---|
| 159 | boost::fusion::at_key<MPQCDataFused::sampled_grid>(instance) = extractedData.sampled_grid;
|
---|
[c9f9bb] | 160 | MPQCData_Grid_fused.insert( std::make_pair(dataiter->first, instance) );
|
---|
[0398bd] | 161 | }
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | template <>
|
---|
| 165 | inline void convertDataTo<MPQCData, MPQCDataFragmentMap_t>(
|
---|
[c9f9bb] | 166 | const std::map<JobId_t, MPQCData> &fragmentData,
|
---|
| 167 | std::map<JobId_t, MPQCDataFragmentMap_t> &MPQCData_Fragment_fused)
|
---|
[0398bd] | 168 | {
|
---|
| 169 | // fragment
|
---|
| 170 | MPQCData_Fragment_fused.clear();
|
---|
[c9f9bb] | 171 | for(std::map<JobId_t, MPQCData>::const_iterator dataiter = fragmentData.begin();
|
---|
[0398bd] | 172 | dataiter != fragmentData.end(); ++dataiter) {
|
---|
[c9f9bb] | 173 | const MPQCData &extractedData = dataiter->second;
|
---|
[0398bd] | 174 | LOG(4, "DEBUG: Current extracted Data is " << extractedData << ".");
|
---|
| 175 | MPQCDataFragmentMap_t instance;
|
---|
| 176 | boost::fusion::at_key<MPQCDataFused::fragment>(instance) =
|
---|
[6829d2] | 177 | Fragment(extractedData.positions, extractedData.atomicnumbers, extractedData.charges);
|
---|
[c9f9bb] | 178 | MPQCData_Fragment_fused.insert( std::make_pair(dataiter->first, instance) );
|
---|
[0398bd] | 179 | }
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | template <>
|
---|
| 183 | inline void convertDataTo<MPQCData, MPQCDataTimeMap_t>(
|
---|
[c9f9bb] | 184 | const std::map<JobId_t, MPQCData> &fragmentData,
|
---|
| 185 | std::map<JobId_t, MPQCDataTimeMap_t> &MPQCData_Time_fused)
|
---|
[0398bd] | 186 | {
|
---|
| 187 | // times
|
---|
| 188 | MPQCData_Time_fused.clear();
|
---|
[c9f9bb] | 189 | for(std::map<JobId_t, MPQCData>::const_iterator dataiter = fragmentData.begin();
|
---|
[0398bd] | 190 | dataiter != fragmentData.end(); ++dataiter) {
|
---|
[c9f9bb] | 191 | const MPQCData &extractedData = dataiter->second;
|
---|
[0398bd] | 192 | LOG(4, "DEBUG: Current extracted Data is " << extractedData << ".");
|
---|
| 193 | MPQCDataTimeMap_t instance;
|
---|
[4aee30] | 194 | boost::fusion::at_key<MPQCDataFused::times_total_walltime>(instance) = extractedData.times.total_walltime;
|
---|
| 195 | boost::fusion::at_key<MPQCDataFused::times_total_cputime>(instance) = extractedData.times.total_cputime;
|
---|
| 196 | boost::fusion::at_key<MPQCDataFused::times_total_flops>(instance) = extractedData.times.total_flops;
|
---|
| 197 | boost::fusion::at_key<MPQCDataFused::times_gather_walltime>(instance) = extractedData.times.gather_walltime;
|
---|
| 198 | boost::fusion::at_key<MPQCDataFused::times_gather_cputime>(instance) = extractedData.times.gather_cputime;
|
---|
| 199 | boost::fusion::at_key<MPQCDataFused::times_gather_flops>(instance) = extractedData.times.gather_flops;
|
---|
[c9f9bb] | 200 | MPQCData_Time_fused.insert( std::make_pair(dataiter->first, instance) );
|
---|
[0398bd] | 201 | }
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | #endif /* DATACONVERTER_HPP_ */
|
---|