00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef COMPONENTS_TRIG_CPU_APPLICATION_H
00014 #define COMPONENTS_TRIG_CPU_APPLICATION_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 application {
00024 public:
00025 virtual bool operator()(SST::Event *ev) = 0;
00026
00027 protected:
00028 application(trig_cpu *cpu) : cpu(cpu), state(0)
00029 {
00030 my_id = cpu->getMyId();
00031 num_nodes = cpu->getNumNodes();
00032 }
00033
00034 virtual ~application() { }
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 = -1;
00059
00060 for (int i = 1 ; i <= num_nodes ; i *= radix) {
00061 int tmp_radix = (num_nodes / i < radix) ? (num_nodes / i) + 1 : 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 if (my_id + i * j < num_nodes) {
00066 my_children.push_back(my_id + i * j);
00067 }
00068 }
00069 }
00070 std::reverse(my_children.begin(), my_children.end());
00071
00072 return std::make_pair(my_root, my_children);
00073 }
00074
00075 std::pair<int, std::vector<int> >
00076 buildNaryTree(int radix)
00077 {
00078 std::vector<int> my_children;
00079 int my_root = (my_id - 1) / radix;
00080 for (int i = 1 ; i <= radix ; ++i) {
00081 int tmp = radix * my_id + i;
00082 if (tmp < num_nodes) my_children.push_back(tmp);
00083 }
00084
00085 return std::make_pair(my_root, my_children);
00086 }
00087
00088 void start_noise_section() {
00089 cpu->start_noise_section();
00090 }
00091
00092 void end_noise_section() {
00093 cpu->start_noise_section();
00094 }
00095
00096 trig_cpu *cpu;
00097 int state;
00098 int my_id;
00099 int num_nodes;
00100
00101 private:
00102 application(const application& a);
00103 void operator=(application const&);
00104 };
00105
00106
00107 #define crBegin() switch(state) { case 0:
00108 #define crReturn() do { state=__LINE__; return false; case __LINE__:; } while (0)
00109 #define crFinish() state = 0 ; }
00110
00111 #endif // COMPONENTS_TRIG_CPU_APPLICATION_H