00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef COMPONENTS_TRIG_CPU_BARRIER_TREE_H
00014 #define COMPONENTS_TRIG_CPU_BARRIER_TREE_H
00015
00016 #include "algorithm.h"
00017 #include "trig_cpu.h"
00018
00019 class barrier_tree : public algorithm {
00020 public:
00021 barrier_tree(trig_cpu *cpu) : algorithm(cpu)
00022 {
00023 radix = cpu->getRadix();
00024
00025
00026 boost::tie(my_root, my_children) = buildBinomialTree(radix);
00027 num_children = my_children.size();
00028 }
00029
00030 bool
00031 operator()(Event *ev)
00032 {
00033 int handle;
00034
00035 crBegin();
00036
00037
00038 start_time = cpu->getCurrentSimTimeNano();
00039 cpu->addBusyTime("200ns");
00040 crReturn();
00041
00042 for (i = 0 ; i < num_children ; ++i) {
00043 while (!cpu->irecv(my_children[i] , NULL, handle)) { crReturn(); }
00044 crReturn();
00045 }
00046 if (num_children != 0) {
00047 while (!cpu->waitall()) { crReturn(); }
00048 crReturn();
00049 }
00050 if (my_root != my_id) {
00051 cpu->isend(my_root, NULL, 0);
00052 crReturn();
00053 while (!cpu->irecv(my_root, NULL, handle)) { crReturn(); }
00054 crReturn();
00055 while (!cpu->waitall()) { crReturn(); }
00056 crReturn();
00057 }
00058 for (i = 0 ; i < num_children ; ++i) {
00059 cpu->isend(my_children[i], NULL, 0);
00060 crReturn();
00061 }
00062
00063 trig_cpu::addTimeToStats(cpu->getCurrentSimTimeNano()-start_time);
00064
00065 crFinish();
00066 return true;
00067 }
00068
00069 private:
00070 barrier_tree();
00071 barrier_tree(const algorithm& a);
00072 void operator=(barrier_tree const&);
00073
00074 SimTime_t start_time;
00075 int radix;
00076 int i;
00077
00078 int my_root;
00079 std::vector<int> my_children;
00080 int num_children;
00081 };
00082
00083 #endif // COMPONENTS_TRIG_CPU_BARRIER_TREE_H