2323#define NEGLECT_IDLE 2 // Should never be == 1
2424#define MIN_STATS 6
2525#define STATS_COUNT 29 // The number of stats collected during reduction
26+ #define CLASSES 6
2627
2728#define MAXDOUBLE std::numeric_limits<double>::max()
2829
@@ -36,6 +37,7 @@ using std::max;
3637CkReductionMsg * lbDataCollection (int nMsg , CkReductionMsg * * msgs ) {
3738 double * lb_data ;
3839 lb_data = (double * )msgs [0 ]-> getData ();
40+ lb_data = (double * )msgs [0 ]-> getData ();
3941 for (int i = 1 ; i < nMsg ; i ++ ) {
4042 CkAssert (msgs [i ]-> getSize () == STATS_COUNT * sizeof (double ));
4143 if (msgs [i ]-> getSize () != STATS_COUNT * sizeof (double )) {
@@ -178,6 +180,12 @@ void MetaBalancer::init(void) {
178180 srand (time (NULL ));
179181 rFmodel = new ForestModel ;
180182 rFmodel -> readModel (_lb_args .metaLbModelDir ());
183+
184+ std ::vector < std ::string > features {"f0" , "f1" , "f2" , "f3" , "f4" , "f5" , "f6" , "f7" , "f8" , "f9" , "f10" , "f11" ,
185+ "f12" , "f13" , "f14" , "f15" , "f16" , "f17" , "f18" , "f19" , "f20" , "f21" , "f22" ,
186+ "f23" , "f24" };
187+ xgboost = fastforest ::load_txt ("model/model.txt" , features , CLASSES );
188+
181189 }
182190 }
183191}
@@ -295,9 +303,9 @@ bool MetaBalancer::AddLoad(int it_n, double load) {
295303 int index = it_n % VEC_SIZE ;
296304 total_count_vec [index ]++ ;
297305 adaptive_struct .total_syncs_called ++ ;
298- CkPrintf ("At PE %d Total contribution for iteration %d is %d \
306+ DEBAD ( ("At PE %d Total contribution for iteration %d is %d \
299307 total objs %d\n" , CkMyPe (), it_n , total_count_vec [index ],
300- lbmanager -> GetObjDataSz ());
308+ lbmanager -> GetObjDataSz ())) ;
301309
302310 if (it_n <= adaptive_struct .finished_iteration_no ) {
303311 CkAbort ("Error!! Received load for iteration that has contributed\n" );
@@ -324,6 +332,7 @@ bool MetaBalancer::AddLoad(int it_n, double load) {
324332 return true;
325333}
326334
335+ //NOTE: Data Collection
327336void MetaBalancer ::ContributeStats (int it_n ) {
328337#if CMK_LBDB_ON
329338 int index = it_n % VEC_SIZE ;
@@ -493,7 +502,7 @@ void MetaBalancer::ReceiveMinStats(double *load, int n) {
493502// avg_hops, avg_hop_bytes, _lb_args.alpha(), _lb_args.beta(),
494503// app_iteration_time);
495504
496- DEBAD (
505+ DEBAD (
497506 ("Features:%lf %lf %lf %lf %lf %lf %lf %lf \
498507 %lf %lf %lf %lf %lf %lf %lf %lf %lf \
499508 %lf %lf %lf %lf %lf %lf %lf %d %lf\n" ,
@@ -532,10 +541,24 @@ void MetaBalancer::ReceiveMinStats(double *load, int n) {
532541 avg_hops ,
533542 avg_hop_Kbytes ,
534543 comm_comp_ratio };
544+
545+ //Note:Predict LB
535546 // Model returns value [1,num_lbs]
536547 int predicted_lb = rFmodel -> forestTest (test_data , 1 , 26 );
537548 DEBAD (("***********Final classification = %d *****************\n" , predicted_lb ));
538549
550+ std ::vector < double > prob = xgboost .softmax (test_data .data ());
551+ int cur_pred = 1 ;
552+ double cur_prob = 0.0 ;
553+ for (int i = 0 ; i < prob .size (); ++ i ) {
554+ if (prob [i ] > cur_prob ) {
555+ cur_prob = prob [i ];
556+ cur_pred = i + 1 ;
557+ }
558+ }
559+
560+ predicted_lb = cur_pred ;
561+
539562 // predicted_lb-1 since predicted_lb class count in the model starts at 1
540563 thisProxy .MetaLBSetLBOnChares (current_balancer , predicted_lb - 1 );
541564 current_balancer = predicted_lb - 1 ;
0 commit comments