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