00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef COMPONENTS_TRIG_CPU_ALGORITHM_H
00014 #define COMPONENTS_TRIG_CPU_ALGORITHM_H
00015
00016 #include <vector>
00017 #include <utility>
00018 #include <boost/tuple/tuple.hpp>
00019
00020 #include <sst/core/event.h>
00021 #include "trig_cpu.h"
00022
00023 class algorithm {
00024 public:
00025 virtual bool operator()(SST::Event *ev) = 0;
00026
00027 protected:
00028 algorithm(trig_cpu *cpu) : cpu(cpu), state(0)
00029 {
00030 my_id = cpu->getMyId();
00031 num_nodes = cpu->getNumNodes();
00032 }
00033
00034 virtual ~algorithm() { }
00035
00036
00037
00038
00039
00040 uint32_t floorLog2(uint32_t n) {
00041 uint32_t pos = 0;
00042 if (n >= 1<<16) { n >>= 16; pos += 16; }
00043 if (n >= 1<< 8) { n >>= 8; pos += 8; }
00044 if (n >= 1<< 4) { n >>= 4; pos += 4; }
00045 if (n >= 1<< 2) { n >>= 2; pos += 2; }
00046 if (n >= 1<< 1) { pos += 1; }
00047 return ((n == 0) ? (-1) : pos);
00048 }
00049
00050
00051
00052
00053
00054 std::pair<int, std::vector<int> >
00055 buildBinomialTree(int radix)
00056 {
00057 std::vector<int> my_children;
00058 int my_root;
00059
00060 for (int i = 1 ; i <= num_nodes ; i *= radix) {
00061 int tmp_radix = (num_nodes / i < radix) ? (num_nodes / i) : radix;
00062 my_root = (my_id / (tmp_radix * i)) * (tmp_radix * i);
00063 if (my_root != my_id) break;
00064 for (int j = 1 ; j < tmp_radix ; ++j) {
00065 my_children.push_back(my_id + i * j);
00066 }
00067 }
00068 std::reverse(my_children.begin(), my_children.end());
00069
00070 return std::make_pair(my_root, my_children);
00071 }
00072
00073 trig_cpu *cpu;
00074 int state;
00075 int my_id;
00076 int num_nodes;
00077
00078 private:
00079 algorithm(const algorithm& a);
00080 void operator=(algorithm const&);
00081 };
00082
00083
00084 #define crBegin() switch(state) { case 0:
00085 #define crReturn() do { state=__LINE__; return false; case __LINE__:; } while (0)
00086 #define crFinish() state = 0 ; }
00087
00088 #endif // COMPONENTS_TRIG_CPU_ALGORITHM_H