00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef COMPONENTS_TRIG_CPU_ALLREDUCE_TREE_TRIGGERED_H
00014 #define COMPONENTS_TRIG_CPU_ALLREDUCE_TREE_TRIGGERED_H
00015
00016 #include "algorithm.h"
00017 #include "trig_cpu.h"
00018 #include "portals.h"
00019
00020 class allreduce_tree_triggered : public algorithm {
00021 public:
00022 allreduce_tree_triggered(trig_cpu *cpu) : algorithm(cpu)
00023 {
00024 radix = cpu->getRadix();
00025 ptl = cpu->getPortalsHandle();
00026
00027
00028 boost::tie(my_root, my_children) = buildBinomialTree(radix);
00029 num_children = my_children.size();
00030 }
00031
00032 bool
00033 operator()(Event *ev)
00034 {
00035 ptl_md_t md;
00036 ptl_me_t me;
00037
00038 switch (state) {
00039 case 0:
00040
00041
00042
00043 ptl->PtlCTAlloc(PTL_CT_OPERATION, up_tree_ct_h);
00044 me.start = NULL;
00045 me.length = 8;
00046 me.ignore_bits = ~0x0;
00047 me.ct_handle = up_tree_ct_h;
00048 ptl->PtlMEAppend(PT_UP, me, PTL_PRIORITY_LIST, NULL, up_tree_me_h);
00049
00050 md.start = NULL;
00051 md.length = 8;
00052 md.eq_handle = PTL_EQ_NONE;
00053 md.ct_handle = PTL_CT_NONE;
00054 ptl->PtlMDBind(md, &up_tree_md_h);
00055
00056 md.start = NULL;
00057 md.length = 8;
00058 md.eq_handle = PTL_EQ_NONE;
00059 md.ct_handle = PTL_CT_NONE;
00060 ptl->PtlMDBind(md, &zero_md_h);
00061
00062 state = 1;
00063 break;
00064
00065 case 1:
00066
00067
00068
00069 start_time = cpu->getCurrentSimTimeNano();
00070 cpu->addBusyTime("200ns");
00071
00072
00073
00074
00075 ptl->PtlCTAlloc(PTL_CT_OPERATION, user_ct_h);
00076 me.start = NULL;
00077 me.length = 8;
00078 me.ignore_bits = ~0x0;
00079 me.ct_handle = user_ct_h;
00080 ptl->PtlMEAppend(PT_DOWN, me, PTL_PRIORITY_LIST, NULL, user_me_h);
00081
00082 md.start = NULL;
00083 md.length = 8;
00084 md.eq_handle = PTL_EQ_NONE;
00085 md.ct_handle = PTL_CT_NONE;
00086 ptl->PtlMDBind(md, &user_md_h);
00087
00088 state = (num_children == 0) ? 2 : 3;
00089 break;
00090
00091 case 2:
00092
00093 ptl->PtlAtomic(user_md_h, 0, 8, 0, my_root, PT_UP, 0, 0, NULL, 0, PTL_SUM, PTL_DOUBLE);
00094 state = 8;
00095 break;
00096
00097 case 3:
00098
00099 ptl->PtlAtomic(user_md_h, 0, 8, 0, my_id, PT_UP, 0, 0, NULL,
00100 0, PTL_SUM, PTL_DOUBLE);
00101 state = 4;
00102 break;
00103
00104 case 4:
00105 if (0 == my_id) {
00106
00107
00108 ptl->PtlTriggeredPut(up_tree_md_h, 0, 8, 0, my_root, PT_DOWN, 0, 0, NULL,
00109 0, up_tree_ct_h, num_children+1);
00110 } else {
00111
00112 ptl->PtlTriggeredAtomic(up_tree_md_h, 0, 8, 0, my_root, PT_UP,
00113 0, 0, NULL, 0, PTL_SUM, PTL_DOUBLE,
00114 up_tree_ct_h, num_children+1);
00115 }
00116 state = 5;
00117 break;
00118
00119 case 5:
00120
00121 ptl->PtlTriggeredPut(zero_md_h, 0, 8, 0, my_id, PT_UP, 0, 0, NULL,
00122 0, up_tree_ct_h, num_children+1);
00123 state = 6;
00124 break;
00125
00126 case 6:
00127 ptl->PtlTriggeredCTInc(up_tree_ct_h, -(num_children+2), up_tree_ct_h, num_children+2);
00128
00129 loop_var = 0;
00130 state = 7;
00131 break;
00132
00133 case 7:
00134
00135 if (loop_var < num_children) {
00136 ptl->PtlTriggeredPut(user_md_h, 0, 8, 0, my_children[num_children-1-loop_var], PT_DOWN,
00137 0, 0, NULL, 0, user_ct_h, 1);
00138 loop_var++;
00139 break;
00140 }
00141 state = 8;
00142 break;
00143
00144 case 8:
00145 if (ptl->PtlCTWait(user_ct_h, 1)) state = 9;
00146 break;
00147
00148 case 9:
00149 trig_cpu::addTimeToStats(cpu->getCurrentSimTimeNano()-start_time);
00150
00151 ptl->PtlMEUnlink(user_me_h);
00152 state = 1;
00153 return true;
00154
00155 default:
00156 printf("triggered tree: unhandled state: %d\n", state);
00157 exit(1);
00158 }
00159
00160 return false;
00161 }
00162
00163 private:
00164 allreduce_tree_triggered();
00165 allreduce_tree_triggered(const algorithm& a);
00166 void operator=(allreduce_tree_triggered const&);
00167
00168 portals *ptl;
00169
00170 SimTime_t start_time;
00171 int radix;
00172 int curr_radix;
00173 int level;
00174 int loop_var;
00175
00176 ptl_handle_ct_t up_tree_ct_h;
00177 ptl_handle_me_t up_tree_me_h;
00178 ptl_handle_md_t up_tree_md_h;
00179
00180 ptl_handle_ct_t user_ct_h;
00181 ptl_handle_me_t user_me_h;
00182 ptl_handle_md_t user_md_h;
00183
00184 ptl_handle_md_t zero_md_h;
00185
00186 int my_root;
00187 std::vector<int> my_children;
00188 int num_children;
00189
00190 static const int PT_UP = 0;
00191 static const int PT_DOWN = 1;
00192 };
00193
00194 #endif // COMPONENTS_TRIG_CPU_ALLREDUCE_TREE_TRIGGERED_H