Last change
on this file since 1677 was
833,
checked in by mhnguyen, 8 years ago
|
Improvements for dht
+) Implement adaptive hierarchy for dht, level of hierarchy depends on number of processes
+) Remove some redundant codes
Test
+) On Curie
+) All tests are correct
|
File size:
1.6 KB
|
Rev | Line | |
---|
[830] | 1 | /*! |
---|
| 2 | \file dht_data_types.hpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 17 Mars 2016 |
---|
| 5 | \date 17 Mars 2016 |
---|
| 6 | |
---|
| 7 | \brief Customized data type for dht |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #ifndef __XIOS_DHT_DATATYPES_HPP__ |
---|
| 11 | #define __XIOS_DHT_DATATYPES_HPP__ |
---|
| 12 | |
---|
| 13 | #include "utils.hpp" |
---|
| 14 | |
---|
| 15 | namespace xios |
---|
| 16 | { |
---|
[833] | 17 | typedef std::pair<int,int> PairIntInt; |
---|
[830] | 18 | |
---|
| 19 | template<typename T> |
---|
| 20 | struct ProcessDHTElement |
---|
| 21 | { |
---|
| 22 | typedef T Type; |
---|
| 23 | static int typeSize() |
---|
| 24 | { |
---|
| 25 | return sizeof(Type); |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | static void packElement(const T& inputElement, unsigned char* packedElement, int& index) |
---|
| 29 | { |
---|
| 30 | if (NULL == packedElement) index += sizeof(Type); |
---|
| 31 | else |
---|
| 32 | { |
---|
| 33 | *(T *)(&packedElement[index]) = inputElement; |
---|
| 34 | index+=sizeof(Type); |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | static void unpackElement(T& outputElement, unsigned char* unpackedElement, int& index) |
---|
| 39 | { |
---|
| 40 | outputElement = *(Type*)(&unpackedElement[index]); |
---|
| 41 | index+=sizeof(Type); |
---|
| 42 | } |
---|
| 43 | }; |
---|
| 44 | |
---|
| 45 | template<> |
---|
| 46 | struct ProcessDHTElement<PairIntInt> |
---|
| 47 | { |
---|
| 48 | typedef PairIntInt Type; |
---|
| 49 | static int typeSize() |
---|
| 50 | { |
---|
| 51 | return (2*sizeof(int)); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | static void packElement(const PairIntInt& inputElement, unsigned char* packedElement, int& index) |
---|
| 55 | { |
---|
| 56 | if (NULL == packedElement) index +=(2*sizeof(int)); |
---|
| 57 | else |
---|
| 58 | { |
---|
| 59 | *(int *)(&packedElement[index]) = inputElement.first; |
---|
| 60 | index+=sizeof(int); |
---|
| 61 | *(int *)(&packedElement[index]) = inputElement.second; |
---|
| 62 | index+=sizeof(int); |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | static void unpackElement(PairIntInt& outputElement, unsigned char* unpackedElement, int& index) |
---|
| 67 | { |
---|
| 68 | outputElement.first=*(int *)(&unpackedElement[index]); |
---|
| 69 | index+=sizeof(int); |
---|
| 70 | outputElement.second=*(int *)(&unpackedElement[index]); |
---|
| 71 | index+=sizeof(int); |
---|
| 72 | } |
---|
| 73 | }; |
---|
| 74 | |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | #endif // __XIOS_DHT_DATATYPES_HPP__ |
---|
Note: See
TracBrowser
for help on using the repository browser.