Handle dynamic insertion
authorHarshitha <gplkrsh2@illinois.edu>
Mon, 17 Sep 2012 15:39:15 +0000 (10:39 -0500)
committerHarshitha <gplkrsh2@illinois.edu>
Mon, 17 Sep 2012 15:39:15 +0000 (10:39 -0500)
src/ck-core/cklocation.C
src/ck-ldb/LBDatabase.C
src/ck-ldb/LBDatabase.h

index e55f64274844d922f96b6f2110b2285d02c61a07..3b5aac4451000a580377a0163e085288141a7ebe 100644 (file)
@@ -973,8 +973,12 @@ void CkMigratable::commonInit(void) {
        usesAtSync=CmiFalse;
        usesAutoMeasure=CmiTrue;
        barrierRegistered=CmiFalse;
-       atsync_iteration = -1;
-  clearAdaptiveData();
+
+  local_state = OFF;
+  prev_load = 0.0;
+  can_reset = false;
+  atsync_iteration = myRec->getLBDB()->get_iteration();
+
        /*
        FAULT_EVAC
        */
@@ -1100,19 +1104,16 @@ void CkMigratable::recvLBPeriod(void *data) {
 
   if (local_state == PAUSE) {
     if (atsync_iteration < lb_period) {
-    //  CkPrintf("---[pe %s] pause and decided\n", idx2str(thisIndexMax));
       local_state = DECIDED;
       ResumeFromSync();
       return;
     }
-   // CkPrintf("---[pe %s] load balance\n", idx2str(thisIndexMax));
     local_state = LOAD_BALANCE;
 
     can_reset = true;
     myRec->getLBDB()->AtLocalBarrier(ldBarrierHandle);
     return;
   }
- // CkPrintf("---[pe %s] decided\n", idx2str(thisIndexMax));
   local_state = DECIDED;
 }
 
@@ -1159,32 +1160,29 @@ void CkMigratable::AtSync(int waitForMigration)
   double tmp = prev_load;
   prev_load = myRec->getObjTime();
   double current_load = prev_load - tmp;
+  if (atsync_iteration < myRec->getLBDB()->get_iteration()) {
+    CkPrintf("[%d:%s] Error!! Contributing to iter %d < current iter %d\n",
+      CkMyPe(), idx2str(thisIndexMax), atsync_iteration,
+      myRec->getLBDB()->get_iteration());
+    CkAbort("Not contributing to the right iteration\n");
+  }
 
   if (atsync_iteration != 0) {
     myRec->getLBDB()->AddLoad(atsync_iteration, current_load);
   }
 
-//
-//  if (atsync_iteration == 3) {
-//    myRec->getLBDB()->AtLocalBarrier(ldBarrierHandle);
-//    return;
-//  } else {
-//    ResumeFromSync();
-//    return;
-//  }
-
   bool is_tentative;
   if (atsync_iteration < myRec->getLBDB()->getPredictedLBPeriod(is_tentative)) {
     ResumeFromSync();
   } else if (is_tentative) {
     local_state = PAUSE;
   } else if (local_state == DECIDED) {
-    DEBAD(("[pe %s] Went to load balance iter %d\n", idx2str(thisIndexMax), atsync_iteration));
+    DEBAD(("[%d:%s] Went to load balance iter %d\n", CkMyPe(), idx2str(thisIndexMax), atsync_iteration));
     local_state = LOAD_BALANCE;
     can_reset = true;
     myRec->getLBDB()->AtLocalBarrier(ldBarrierHandle);
   } else {
-    DEBAD(("[pe %s] Went to pause state iter %d\n", idx2str(thisIndexMax), atsync_iteration));
+    DEBAD(("[%d:%s] Went to pause state iter %d\n", CkMyPe(), idx2str(thisIndexMax), atsync_iteration));
     local_state = PAUSE;
   }
 }
index 8360fd128aff603a5ad823a6d9691103cf4280f4..0450d1d822e7304174aea0e8c6048deb51a84b58 100644 (file)
@@ -38,7 +38,7 @@ struct AdaptiveData {
 struct AdaptiveLBDatabase {
   std::vector<AdaptiveData> history_data;
   int lb_iter_no;
-} adaptive_lbdb;
+};
 
 struct AdaptiveLBInfo {
   AdaptiveLBInfo() {
@@ -79,7 +79,7 @@ struct AdaptiveLBStructure {
   AdaptiveLBInfo refine_info;
   AdaptiveLBInfo comm_info;
   AdaptiveLBInfo comm_refine_info;
-} adaptive_struct;
+};
 
 
 CkReductionMsg* lbDataCollection(int nMsg, CkReductionMsg** msgs) {
@@ -135,6 +135,9 @@ CkpvDeclare(int, numLoadBalancers);  /**< num of lb created */
 CkpvDeclare(int, hasNullLB);         /**< true if NullLB is created */
 CkpvDeclare(int, lbdatabaseInited);  /**< true if lbdatabase is inited */
 
+CkpvDeclare(AdaptiveLBDatabase, adaptive_lbdb);
+CkpvDeclare(AdaptiveLBStructure, adaptive_struct);
+
 // command line options
 CkLBArgs _lb_args;
 int _lb_predict=0;
@@ -465,25 +468,28 @@ void LBDatabase::init(void)
   max_iteration = -1;
   prev_idle = 0.0;
   alpha_beta_cost_to_load = 1.0; // Some random value. TODO: Find the actual
-  adaptive_lbdb.lb_iter_no = -1;
+
+  CkpvInitialize(AdaptiveLBDatabase, adaptive_lbdb);
+  CkpvInitialize(AdaptiveLBStructure, adaptive_struct);
+
+  CkpvAccess(adaptive_lbdb).lb_iter_no = -1;
 
   // If metabalancer enabled, initialize the variables
-  adaptive_struct.tentative_period =  INT_MAX;
-  adaptive_struct.final_lb_period =  INT_MAX;
-  adaptive_struct.lb_calculated_period = INT_MAX;
-  adaptive_struct.lb_iteration_no = -1;
-  adaptive_struct.global_max_iter_no = 0;
-  adaptive_struct.tentative_max_iter_no = -1;
-  adaptive_struct.global_recv_iter_counter = 0;
-  adaptive_struct.in_progress = false;
-  adaptive_struct.lb_strategy_cost = 0.0;
-  adaptive_struct.lb_migration_cost = 0.0;
-  adaptive_struct.lb_msg_send_no = 0;
-  adaptive_struct.lb_msg_recv_no = 0;
-  adaptive_struct.total_syncs_called = 0;
-  adaptive_struct.last_lb_type = -1;
-
-  adaptive_lbdb.lb_iter_no = -1;
+  CkpvAccess(adaptive_struct).tentative_period =  INT_MAX;
+  CkpvAccess(adaptive_struct).final_lb_period =  INT_MAX;
+  CkpvAccess(adaptive_struct).lb_calculated_period = INT_MAX;
+  CkpvAccess(adaptive_struct).lb_iteration_no = -1;
+  CkpvAccess(adaptive_struct).global_max_iter_no = 0;
+  CkpvAccess(adaptive_struct).tentative_max_iter_no = -1;
+  CkpvAccess(adaptive_struct).global_recv_iter_counter = 0;
+  CkpvAccess(adaptive_struct).in_progress = false;
+  CkpvAccess(adaptive_struct).lb_strategy_cost = 0.0;
+  CkpvAccess(adaptive_struct).lb_migration_cost = 0.0;
+  CkpvAccess(adaptive_struct).lb_msg_send_no = 0;
+  CkpvAccess(adaptive_struct).lb_msg_recv_no = 0;
+  CkpvAccess(adaptive_struct).total_syncs_called = 0;
+  CkpvAccess(adaptive_struct).last_lb_type = -1;
+
 
   // This is indicating if the load balancing strategy and migration started.
   // This is mainly used to register callbacks for noobj pes. They would
@@ -623,21 +629,21 @@ void LBDatabase::EstObjLoad(const LDObjHandle &_h, double cputime)
 
 void LBDatabase::ResumeClients() {
   // If metabalancer enabled, initialize the variables
-  adaptive_lbdb.history_data.clear();
-
-  adaptive_struct.tentative_period =  INT_MAX;
-  adaptive_struct.final_lb_period =  INT_MAX;
-  adaptive_struct.lb_calculated_period = INT_MAX;
-  adaptive_struct.lb_iteration_no = -1;
-  adaptive_struct.global_max_iter_no = 0;
-  adaptive_struct.tentative_max_iter_no = -1;
-  adaptive_struct.global_recv_iter_counter = 0;
-  adaptive_struct.in_progress = false;
-  adaptive_struct.lb_strategy_cost = 0.0;
-  adaptive_struct.lb_migration_cost = 0.0;
-  adaptive_struct.lb_msg_send_no = 0;
-  adaptive_struct.lb_msg_recv_no = 0;
-  adaptive_struct.total_syncs_called = 0;
+  CkpvAccess(adaptive_lbdb).history_data.clear();
+
+  CkpvAccess(adaptive_struct).tentative_period =  INT_MAX;
+  CkpvAccess(adaptive_struct).final_lb_period =  INT_MAX;
+  CkpvAccess(adaptive_struct).lb_calculated_period = INT_MAX;
+  CkpvAccess(adaptive_struct).lb_iteration_no = -1;
+  CkpvAccess(adaptive_struct).global_max_iter_no = 0;
+  CkpvAccess(adaptive_struct).tentative_max_iter_no = -1;
+  CkpvAccess(adaptive_struct).global_recv_iter_counter = 0;
+  CkpvAccess(adaptive_struct).in_progress = false;
+  CkpvAccess(adaptive_struct).lb_strategy_cost = 0.0;
+  CkpvAccess(adaptive_struct).lb_migration_cost = 0.0;
+  CkpvAccess(adaptive_struct).lb_msg_send_no = 0;
+  CkpvAccess(adaptive_struct).lb_msg_recv_no = 0;
+  CkpvAccess(adaptive_struct).total_syncs_called = 0;
 
   prev_idle = 0.0;
   if (lb_in_progress) {
@@ -654,16 +660,23 @@ void LBDatabase::ResumeClients() {
   LDResumeClients(myLDHandle);
 }
 
+int LBDatabase::get_iteration() {
+  return CkpvAccess(adaptive_struct).lb_iteration_no;
+}
+
 bool LBDatabase::AddLoad(int it_n, double load) {
   int index = it_n % VEC_SIZE;
   total_count_vec[index]++;
-  adaptive_struct.total_syncs_called++;
+  CkpvAccess(adaptive_struct).total_syncs_called++;
   DEBAD(("At PE %d Total contribution for iteration %d is %d total objs %d\n",
   CkMyPe(), it_n,
     total_count_vec[index], getLBDB()->ObjDataCount()));
 
-  if (it_n > adaptive_struct.lb_iteration_no) {
-    adaptive_struct.lb_iteration_no = it_n;
+  if (it_n < CkpvAccess(adaptive_struct).lb_iteration_no) {
+    CkAbort("Error!! Received load for previous iteration\n");
+  }
+  if (it_n > CkpvAccess(adaptive_struct).lb_iteration_no) {
+    CkpvAccess(adaptive_struct).lb_iteration_no = it_n;
   }
   total_load_vec[index] += load;
   if (total_count_vec[index] > getLBDB()->ObjDataCount()) {
@@ -677,7 +690,7 @@ bool LBDatabase::AddLoad(int it_n, double load) {
     IdleTime(&idle_time);
     BackgroundLoad(&bg_walltime, &cpu_bgtime);
 
-    int sync_for_bg = adaptive_struct.total_syncs_called +
+    int sync_for_bg = CkpvAccess(adaptive_struct).total_syncs_called +
         getLBDB()->ObjDataCount();
     bg_walltime = bg_walltime * getLBDB()->ObjDataCount() / sync_for_bg;
 
@@ -688,7 +701,7 @@ bool LBDatabase::AddLoad(int it_n, double load) {
 
     // The chares do not contribute their 0th iteration load. So the total syncs
     // in reality is total_syncs_called + obj_counts
-    int total_countable_syncs = adaptive_struct.total_syncs_called +
+    int total_countable_syncs = CkpvAccess(adaptive_struct).total_syncs_called +
         (1 - NEGLECT_IDLE) * getLBDB()->ObjDataCount(); // TODO: Fix me! weird!
     if (total_countable_syncs != 0) {
       idle_time = idle_time * getLBDB()->ObjDataCount() / total_countable_syncs;
@@ -736,7 +749,7 @@ void LBDatabase::ReceiveMinStats(CkReductionMsg *msg) {
   delete msg;
 
 #if EXTRA_FEATURE
-  if (adaptive_struct.final_lb_period != iteration_n) {
+  if (CkpvAccess(adaptive_struct).final_lb_period != iteration_n) {
     for (int i = 0; i < lbdb_no_obj_callback.size(); i++) {
       thisProxy[lbdb_no_obj_callback[i]].TriggerAdaptiveReduction();
     }
@@ -744,20 +757,20 @@ void LBDatabase::ReceiveMinStats(CkReductionMsg *msg) {
 #endif
 
   // Store the data for this iteration
-  adaptive_lbdb.lb_iter_no = iteration_n;
+  CkpvAccess(adaptive_lbdb).lb_iter_no = iteration_n;
   AdaptiveData data;
-  data.iteration = adaptive_lbdb.lb_iter_no;
+  data.iteration = CkpvAccess(adaptive_lbdb).lb_iter_no;
   data.max_load = max;
   data.avg_load = avg;
   data.utilization = utilization;
   data.idle_time = avg_idle;
-  adaptive_lbdb.history_data.push_back(data);
+  CkpvAccess(adaptive_lbdb).history_data.push_back(data);
 
   // If lb period inform is in progress, dont inform again.
   // If this is the lb data corresponding to the final lb period informed, then
   // don't recalculate as some of the processors might have already gone into
   // LB_STAGE.
-  if (adaptive_struct.in_progress || (adaptive_struct.final_lb_period == iteration_n)) {
+  if (CkpvAccess(adaptive_struct).in_progress || (CkpvAccess(adaptive_struct).final_lb_period == iteration_n)) {
     return;
   }
 
@@ -786,8 +799,8 @@ void LBDatabase::ReceiveMinStats(CkReductionMsg *msg) {
 
   if (generatePlan(period, ratio_at_t)) {
     DEBAD(("Generated period and calculated %d and period %d max iter %d\n",
-      adaptive_struct.lb_calculated_period, period,
-      adaptive_struct.tentative_max_iter_no));
+      CkpvAccess(adaptive_struct).lb_calculated_period, period,
+      CkpvAccess(adaptive_struct).tentative_max_iter_no));
     // set the imbalance tolerance to be ratio_at_calculated_lb_period
     if (ratio_at_t != 1.0) {
       CkPrintf("Changed tolerance to %lf after line eq whereas max/avg is %lf\n", ratio_at_t, max/avg);
@@ -799,7 +812,7 @@ void LBDatabase::ReceiveMinStats(CkReductionMsg *msg) {
     CkPrintf("Prev LB Data Type %d, max/avg %lf, local/remote %lf\n", tmp_lb_type, tmp_max_avg_ratio, tmp_comm_ratio);
 
     if ((utilization < utilization_threshold || max/avg >= tolerate_imb) &&
-          adaptive_lbdb.history_data.size() > MIN_STATS) {
+          CkpvAccess(adaptive_lbdb).history_data.size() > MIN_STATS) {
       CkPrintf("Trigger soon even though we calculated lbperiod max/avg(%lf) and utilization ratio (%lf)\n", max/avg, utilization);
       TriggerSoon(iteration_n, max/avg, tolerate_imb);
       return;
@@ -808,15 +821,15 @@ void LBDatabase::ReceiveMinStats(CkReductionMsg *msg) {
     // If the new lb period from linear extrapolation is greater than maximum
     // iteration known from previously collected data, then inform all the
     // processors about the new calculated period.
-    if (period > adaptive_struct.tentative_max_iter_no && period !=
-          adaptive_struct.final_lb_period) {
-      adaptive_struct.doCommStrategy = false;
-      adaptive_struct.lb_calculated_period = period;
-      adaptive_struct.in_progress = true;
+    if (period > CkpvAccess(adaptive_struct).tentative_max_iter_no && period !=
+          CkpvAccess(adaptive_struct).final_lb_period) {
+      CkpvAccess(adaptive_struct).doCommStrategy = false;
+      CkpvAccess(adaptive_struct).lb_calculated_period = period;
+      CkpvAccess(adaptive_struct).in_progress = true;
       CkPrintf("Sticking to the calculated period %d\n",
-        adaptive_struct.lb_calculated_period);
-      thisProxy.LoadBalanceDecision(adaptive_struct.lb_msg_send_no++,
-        adaptive_struct.lb_calculated_period);
+        CkpvAccess(adaptive_struct).lb_calculated_period);
+      thisProxy.LoadBalanceDecision(CkpvAccess(adaptive_struct).lb_msg_send_no++,
+        CkpvAccess(adaptive_struct).lb_calculated_period);
       return;
     }
     // TODO: Shouldn't we return from here??
@@ -825,7 +838,7 @@ void LBDatabase::ReceiveMinStats(CkReductionMsg *msg) {
   CkPrintf("Prev LB Data Type %d, max/avg %lf, local/remote %lf\n", tmp_lb_type, tmp_max_avg_ratio, tmp_comm_ratio);
 
   // This would be called when the datasize is not enough to calculate lb period
-  if ((utilization < utilization_threshold || max/avg >= tolerate_imb) && adaptive_lbdb.history_data.size() > 4) {
+  if ((utilization < utilization_threshold || max/avg >= tolerate_imb) && CkpvAccess(adaptive_lbdb).history_data.size() > 4) {
     CkPrintf("Carry out load balancing step at iter max/avg(%lf) and utilization ratio (%lf)\n", max/avg, utilization);
     TriggerSoon(iteration_n, max/avg, tolerate_imb);
     return;
@@ -839,27 +852,27 @@ void LBDatabase::TriggerSoon(int iteration_n, double imbalance_ratio,
   // If the previously calculated_period (not the final decision) is greater
   // than the iter +1 and if it is greater than the maximum iteration we have
   // seen so far, then we can inform this
-  if ((iteration_n + 1 > adaptive_struct.tentative_max_iter_no) &&
-      (iteration_n+1 < adaptive_struct.lb_calculated_period) &&
-      (iteration_n + 1 != adaptive_struct.final_lb_period)) {
+  if ((iteration_n + 1 > CkpvAccess(adaptive_struct).tentative_max_iter_no) &&
+      (iteration_n+1 < CkpvAccess(adaptive_struct).lb_calculated_period) &&
+      (iteration_n + 1 != CkpvAccess(adaptive_struct).final_lb_period)) {
     if (imbalance_ratio < tolerate_imb) {
-      adaptive_struct.doCommStrategy = true;
+      CkpvAccess(adaptive_struct).doCommStrategy = true;
       CkPrintf("No load imbalance but idle time\n");
     } else {
-      adaptive_struct.doCommStrategy = false;
+      CkpvAccess(adaptive_struct).doCommStrategy = false;
       CkPrintf("load imbalance \n");
     }
-    adaptive_struct.lb_calculated_period = iteration_n + 1;
-    adaptive_struct.in_progress = true;
+    CkpvAccess(adaptive_struct).lb_calculated_period = iteration_n + 1;
+    CkpvAccess(adaptive_struct).in_progress = true;
     CkPrintf("Informing everyone the lb period is %d\n",
-        adaptive_struct.lb_calculated_period);
-    thisProxy.LoadBalanceDecision(adaptive_struct.lb_msg_send_no++,
-        adaptive_struct.lb_calculated_period);
+        CkpvAccess(adaptive_struct).lb_calculated_period);
+    thisProxy.LoadBalanceDecision(CkpvAccess(adaptive_struct).lb_msg_send_no++,
+        CkpvAccess(adaptive_struct).lb_calculated_period);
   }
 }
 
 bool LBDatabase::generatePlan(int& period, double& ratio_at_t) {
-  if (adaptive_lbdb.history_data.size() <= 4) {
+  if (CkpvAccess(adaptive_lbdb).history_data.size() <= 4) {
     return false;
   }
 
@@ -869,15 +882,15 @@ bool LBDatabase::generatePlan(int& period, double& ratio_at_t) {
   double max = 0.0;
   double avg = 0.0;
   AdaptiveData data;
-  for (int i = 0; i < adaptive_lbdb.history_data.size(); i++) {
-    data = adaptive_lbdb.history_data[i];
+  for (int i = 0; i < CkpvAccess(adaptive_lbdb).history_data.size(); i++) {
+    data = CkpvAccess(adaptive_lbdb).history_data[i];
     max += data.max_load;
     avg += data.avg_load;
     //DEBAD(("max (%d, %lf) avg (%d, %lf)\n", i, data.max_load, i, data.avg_load));
     //CkPrintf("max (%d, %lf) avg (%d, %lf)\n", i, data.max_load, i, data.avg_load);
   }
-//  max /= (adaptive_struct.lb_iteration_no - adaptive_lbdb.history_data[0].iteration);
-//  avg /= (adaptive_struct.lb_iteration_no - adaptive_lbdb.history_data[0].iteration);
+//  max /= (adaptive_struct.lb_iteration_no - CkpvAccess(adaptive_lbdb).history_data[0].iteration);
+//  avg /= (adaptive_struct.lb_iteration_no - CkpvAccess(adaptive_lbdb).history_data[0].iteration);
 
   // If linearly varying load, then find lb_period
   // area between the max and avg curve
@@ -920,20 +933,20 @@ bool LBDatabase::generatePlan(int& period, double& ratio_at_t) {
 
   max = 0.0;
   avg = 0.0;
-  for (int i = 0; i < adaptive_lbdb.history_data.size(); i++) {
-    data = adaptive_lbdb.history_data[i];
+  for (int i = 0; i < CkpvAccess(adaptive_lbdb).history_data.size(); i++) {
+    data = CkpvAccess(adaptive_lbdb).history_data[i];
     max += data.max_load;
     avg += data.avg_load*tolerate_imb;
     //DEBAD(("max (%d, %lf) avg (%d, %lf)\n", i, data.max_load, i, data.avg_load));
     //CkPrintf("max (%d, %lf) avg (%d, %lf)\n", i, data.max_load, i, data.avg_load);
   }
-  max /= adaptive_lbdb.history_data.size();
-  avg /= adaptive_lbdb.history_data.size();
-  double cost = adaptive_struct.lb_strategy_cost + adaptive_struct.lb_migration_cost;
+  max /= CkpvAccess(adaptive_lbdb).history_data.size();
+  avg /= CkpvAccess(adaptive_lbdb).history_data.size();
+  double cost = CkpvAccess(adaptive_struct).lb_strategy_cost + CkpvAccess(adaptive_struct).lb_migration_cost;
   period = cost/(max - avg); 
   CkPrintf("Obtained period %d from constant prediction\n", period);
   if (period < 0) { 
-    period = adaptive_struct.final_lb_period;
+    period = CkpvAccess(adaptive_struct).final_lb_period;
     CkPrintf("Obtained -ve period from constant prediction so changing to prev %d\n", period);
   } 
   ratio_at_t = max / avg;
@@ -948,8 +961,8 @@ bool LBDatabase::getPeriodForStrategy(double new_load_percent,
   CkPrintf("\n max: %fx + %f; avg: %fx + %f\n", mslope, mc, aslope, ac);
   double a = (mslope - aslope)/2;
   double b = (mc - ac);
-  double c = -(adaptive_struct.lb_strategy_cost +
-      adaptive_struct.lb_migration_cost) * overhead_percent;
+  double c = -(CkpvAccess(adaptive_struct).lb_strategy_cost +
+      CkpvAccess(adaptive_struct).lb_migration_cost) * overhead_percent;
   bool got_period = getPeriodForLinear(a, b, c, period);
   if (!got_period) {
     return false;
@@ -1009,9 +1022,9 @@ bool LBDatabase::getPeriodForLinear(double a, double b, double c, int& period) {
 }
 
 bool LBDatabase::getLineEq(double new_load_percent, double& aslope, double& ac, double& mslope, double& mc) {
-  int total = adaptive_lbdb.history_data.size();
-  int iterations = 1 + adaptive_lbdb.history_data[total - 1].iteration -
-      adaptive_lbdb.history_data[0].iteration;
+  int total = CkpvAccess(adaptive_lbdb).history_data.size();
+  int iterations = 1 + CkpvAccess(adaptive_lbdb).history_data[total - 1].iteration -
+      CkpvAccess(adaptive_lbdb).history_data[0].iteration;
   double a1 = 0;
   double m1 = 0;
   double a2 = 0;
@@ -1019,7 +1032,7 @@ bool LBDatabase::getLineEq(double new_load_percent, double& aslope, double& ac,
   AdaptiveData data;
   int i = 0;
   for (i = 0; i < total/2; i++) {
-    data = adaptive_lbdb.history_data[i];
+    data = CkpvAccess(adaptive_lbdb).history_data[i];
     m1 += data.max_load;
     a1 += data.avg_load;
     CkPrintf("max (%d, %lf) avg (%d, %lf) adjusted_avg (%d, %lf)\n", i, data.max_load, i, data.avg_load, i, new_load_percent*data.avg_load);
@@ -1028,7 +1041,7 @@ bool LBDatabase::getLineEq(double new_load_percent, double& aslope, double& ac,
   a1 = (a1 * new_load_percent) / i;
 
   for (i = total/2; i < total; i++) {
-    data = adaptive_lbdb.history_data[i];
+    data = CkpvAccess(adaptive_lbdb).history_data[i];
     m2 += data.max_load;
     a2 += data.avg_load;
     CkPrintf("max (%d, %lf) avg (%d, %lf) adjusted_avg (%d, %lf)\n", i, data.max_load, i, data.avg_load, i, new_load_percent*data.avg_load);
@@ -1038,36 +1051,36 @@ bool LBDatabase::getLineEq(double new_load_percent, double& aslope, double& ac,
 
   aslope = 2 * (a2 - a1) / iterations;
   mslope = 2 * (m2 - m1) / iterations;
-  ac = adaptive_lbdb.history_data[0].avg_load * new_load_percent;
-  mc = adaptive_lbdb.history_data[0].max_load;
+  ac = CkpvAccess(adaptive_lbdb).history_data[0].avg_load * new_load_percent;
+  mc = CkpvAccess(adaptive_lbdb).history_data[0].max_load;
 
   ac = a1 - ((aslope * total)/4);
   mc = m1 - ((mslope * total)/4);
 
-  //ac = (adaptive_lbdb.history_data[1].avg_load * new_load_percent - aslope);
-  //mc = (adaptive_lbdb.history_data[1].max_load - mslope);
+  //ac = (CkpvAccess(adaptive_lbdb).history_data[1].avg_load * new_load_percent - aslope);
+  //mc = (CkpvAccess(adaptive_lbdb).history_data[1].max_load - mslope);
 
   return true;
 }
 
 void LBDatabase::LoadBalanceDecision(int req_no, int period) {
-  if (req_no < adaptive_struct.lb_msg_recv_no) {
+  if (req_no < CkpvAccess(adaptive_struct).lb_msg_recv_no) {
     CkPrintf("Error!!! Received a request which was already sent or old\n");
     return;
   }
-  //CkPrintf("[%d] Load balance decision made cur iteration: %d period:%d state: %d\n",CkMyPe(), adaptive_struct.lb_iteration_no, period, local_state);
-  adaptive_struct.tentative_period = period;
-  adaptive_struct.lb_msg_recv_no = req_no;
-  thisProxy[0].ReceiveIterationNo(req_no, adaptive_struct.lb_iteration_no);
+  CkPrintf("[%d] Load balance decision made cur iteration: %d period:%d\n",CkMyPe(), CkpvAccess(adaptive_struct).lb_iteration_no, period);
+  CkpvAccess(adaptive_struct).tentative_period = period;
+  CkpvAccess(adaptive_struct).lb_msg_recv_no = req_no;
+  thisProxy[0].ReceiveIterationNo(req_no, CkpvAccess(adaptive_struct).lb_iteration_no);
 }
 
 void LBDatabase::LoadBalanceDecisionFinal(int req_no, int period) {
-  if (req_no < adaptive_struct.lb_msg_recv_no) {
+  if (req_no < CkpvAccess(adaptive_struct).lb_msg_recv_no) {
     return;
   }
-  DEBAD(("[%d] Final Load balance decision made cur iteration: %d period:%d \n",CkMyPe(), adaptive_struct.lb_iteration_no, period));
-  adaptive_struct.tentative_period = period;
-  adaptive_struct.final_lb_period = period;
+  DEBAD(("[%d] Final Load balance decision made cur iteration: %d period:%d \n",CkMyPe(), CkpvAccess(adaptive_struct).lb_iteration_no, period));
+  CkpvAccess(adaptive_struct).tentative_period = period;
+  CkpvAccess(adaptive_struct).final_lb_period = period;
   LDOMAdaptResumeSync(myLDHandle, period);
 }
 
@@ -1075,30 +1088,30 @@ void LBDatabase::LoadBalanceDecisionFinal(int req_no, int period) {
 void LBDatabase::ReceiveIterationNo(int req_no, int local_iter_no) {
   CmiAssert(CkMyPe() == 0);
 
-  adaptive_struct.global_recv_iter_counter++;
-  if (local_iter_no > adaptive_struct.global_max_iter_no) {
-    adaptive_struct.global_max_iter_no = local_iter_no;
+  CkpvAccess(adaptive_struct).global_recv_iter_counter++;
+  if (local_iter_no > CkpvAccess(adaptive_struct).global_max_iter_no) {
+    CkpvAccess(adaptive_struct).global_max_iter_no = local_iter_no;
   }
 
   int period;
-  if (CkNumPes() == adaptive_struct.global_recv_iter_counter) {
+  if (CkNumPes() == CkpvAccess(adaptive_struct).global_recv_iter_counter) {
 
-    if (adaptive_struct.global_max_iter_no > adaptive_struct.tentative_max_iter_no) {
-      adaptive_struct.tentative_max_iter_no = adaptive_struct.global_max_iter_no;
+    if (CkpvAccess(adaptive_struct).global_max_iter_no > CkpvAccess(adaptive_struct).tentative_max_iter_no) {
+      CkpvAccess(adaptive_struct).tentative_max_iter_no = CkpvAccess(adaptive_struct).global_max_iter_no;
     }
-    period = (adaptive_struct.tentative_period > adaptive_struct.global_max_iter_no) ? adaptive_struct.tentative_period : adaptive_struct.global_max_iter_no + 1;
+    period = (CkpvAccess(adaptive_struct).tentative_period > CkpvAccess(adaptive_struct).global_max_iter_no) ? CkpvAccess(adaptive_struct).tentative_period : CkpvAccess(adaptive_struct).global_max_iter_no + 1;
     // If no one has gone into load balancing stage, then we can safely change
     // the period otherwise keep the old period.
-    if (adaptive_struct.global_max_iter_no < adaptive_struct.final_lb_period) {
-      adaptive_struct.tentative_period = period;
-      CkPrintf("Final lb_period CHANGED!%d\n", adaptive_struct.tentative_period);
+    if (CkpvAccess(adaptive_struct).global_max_iter_no < CkpvAccess(adaptive_struct).final_lb_period) {
+      CkpvAccess(adaptive_struct).tentative_period = period;
+      CkPrintf("Final lb_period CHANGED!%d\n", CkpvAccess(adaptive_struct).tentative_period);
     } else {
-      adaptive_struct.tentative_period = adaptive_struct.final_lb_period;
-      CkPrintf("Final lb_period NOT CHANGED!%d\n", adaptive_struct.tentative_period);
+      CkpvAccess(adaptive_struct).tentative_period = CkpvAccess(adaptive_struct).final_lb_period;
+      CkPrintf("Final lb_period NOT CHANGED!%d\n", CkpvAccess(adaptive_struct).tentative_period);
     }
-    thisProxy.LoadBalanceDecisionFinal(req_no, adaptive_struct.tentative_period);
-    adaptive_struct.in_progress = false;
-    adaptive_struct.global_recv_iter_counter = 0;
+    thisProxy.LoadBalanceDecisionFinal(req_no, CkpvAccess(adaptive_struct).tentative_period);
+    CkpvAccess(adaptive_struct).in_progress = false;
+    CkpvAccess(adaptive_struct).global_recv_iter_counter = 0;
   }
 }
 
@@ -1106,28 +1119,28 @@ int LBDatabase::getPredictedLBPeriod(bool& is_tentative) {
   // If tentative and final_lb_period are the same, then the decision has been
   // made but if not, they are in the middle of consensus, hence return the
   // lease of the two
-  if (adaptive_struct.tentative_period != adaptive_struct.final_lb_period) {
+  if (CkpvAccess(adaptive_struct).tentative_period != CkpvAccess(adaptive_struct).final_lb_period) {
     is_tentative = true;
   } else {
     is_tentative = false;
   }
-  if (adaptive_struct.tentative_period < adaptive_struct.final_lb_period) {
-    return adaptive_struct.tentative_period;
+  if (CkpvAccess(adaptive_struct).tentative_period < CkpvAccess(adaptive_struct).final_lb_period) {
+    return CkpvAccess(adaptive_struct).tentative_period;
    } else {
-     return adaptive_struct.final_lb_period;
+     return CkpvAccess(adaptive_struct).final_lb_period;
    }
 }
 
 // Called by CentralLB to indicate that the LB strategy and migration is in
 // progress.
 void LBDatabase::ResetAdaptive() {
-  adaptive_lbdb.lb_iter_no = -1;
+  CkpvAccess(adaptive_lbdb).lb_iter_no = -1;
   lb_in_progress = true;
 }
 
 void LBDatabase::HandleAdaptiveNoObj() {
 #if EXTRA_FEATURE
-  adaptive_struct.lb_iteration_no++;
+  CkpvAccess(adaptive_struct).lb_iteration_no++;
   //CkPrintf("HandleAdaptiveNoObj %d\n", adaptive_struct.lb_iteration_no);
   thisProxy[0].RegisterNoObjCallback(CkMyPe());
   TriggerAdaptiveReduction();
@@ -1146,7 +1159,7 @@ void LBDatabase::RegisterNoObjCallback(int index) {
 
   // If collection has already happened and this is second iteration, then
   // trigger reduction.
-  if (adaptive_lbdb.lb_iter_no != -1) {
+  if (CkpvAccess(adaptive_lbdb).lb_iter_no != -1) {
     //CkPrintf("Collection already started now %d so kick in\n", adaptive_struct.lb_iteration_no);
     thisProxy[index].TriggerAdaptiveReduction();
   }
@@ -1155,10 +1168,10 @@ void LBDatabase::RegisterNoObjCallback(int index) {
 
 void LBDatabase::TriggerAdaptiveReduction() {
 #if EXTRA_FEATURE
-  adaptive_struct.lb_iteration_no++;
-  //CkPrintf("Trigger adaptive for %d\n", adaptive_struct.lb_iteration_no);
+  CkpvAccess(adaptive_struct).lb_iteration_no++;
+  //CkPrintf("Trigger adaptive for %d\n", CkpvAccess(adaptive_struct).lb_iteration_no);
   double lb_data[8];
-  lb_data[0] = adaptive_struct.lb_iteration_no;
+  lb_data[0] = CkpvAccess(adaptive_struct).lb_iteration_no;
   lb_data[1] = 1;
   lb_data[2] = 0.0;
   lb_data[3] = 0.0;
@@ -1178,47 +1191,47 @@ void LBDatabase::TriggerAdaptiveReduction() {
 
 
 bool LBDatabase::isStrategyComm() {
-  return adaptive_struct.doCommStrategy;
+  return CkpvAccess(adaptive_struct).doCommStrategy;
 }
 
 void LBDatabase::SetMigrationCost(double lb_migration_cost) {
-  adaptive_struct.lb_migration_cost = lb_migration_cost;
+  CkpvAccess(adaptive_struct).lb_migration_cost = lb_migration_cost;
 }
 
 void LBDatabase::SetStrategyCost(double lb_strategy_cost) {
-  adaptive_struct.lb_strategy_cost = lb_strategy_cost;
+  CkpvAccess(adaptive_struct).lb_strategy_cost = lb_strategy_cost;
 }
 
 void LBDatabase::UpdateAfterLBData(int lb, double lb_max, double lb_avg, double
     local_comm, double remote_comm) {
-  adaptive_struct.last_lb_type = lb;
+  CkpvAccess(adaptive_struct).last_lb_type = lb;
   if (lb == 0) {
-    adaptive_struct.greedy_info.max_avg_ratio = lb_max/lb_avg;
+    CkpvAccess(adaptive_struct).greedy_info.max_avg_ratio = lb_max/lb_avg;
   } else if (lb == 1) {
-    adaptive_struct.refine_info.max_avg_ratio = lb_max/lb_avg;
+    CkpvAccess(adaptive_struct).refine_info.max_avg_ratio = lb_max/lb_avg;
   } else if (lb == 2) {
-    adaptive_struct.comm_info.remote_local_ratio = remote_comm/local_comm;
+    CkpvAccess(adaptive_struct).comm_info.remote_local_ratio = remote_comm/local_comm;
   } else if (lb == 3) {
-    adaptive_struct.comm_refine_info.remote_local_ratio =
+    CkpvAccess(adaptive_struct).comm_refine_info.remote_local_ratio =
     remote_comm/local_comm;
   }
 }
 
 void LBDatabase::UpdateAfterLBData(double max_load, double max_cpu, double
 avg_load) {
-  if (adaptive_struct.last_lb_type == -1) {
-    adaptive_struct.last_lb_type = 0;
+  if (CkpvAccess(adaptive_struct).last_lb_type == -1) {
+    CkpvAccess(adaptive_struct).last_lb_type = 0;
   }
-  int lb = adaptive_struct.last_lb_type;
+  int lb = CkpvAccess(adaptive_struct).last_lb_type;
   //CkPrintf("Storing data after lb ratio %lf for lb %d\n", max_load/avg_load, lb);
   if (lb == 0) {
-    adaptive_struct.greedy_info.max_avg_ratio = max_load/avg_load;
+    CkpvAccess(adaptive_struct).greedy_info.max_avg_ratio = max_load/avg_load;
   } else if (lb == 1) {
-    adaptive_struct.refine_info.max_avg_ratio = max_load/avg_load;
+    CkpvAccess(adaptive_struct).refine_info.max_avg_ratio = max_load/avg_load;
   } else if (lb == 2) {
-    adaptive_struct.comm_info.max_avg_ratio = max_load/avg_load;
+    CkpvAccess(adaptive_struct).comm_info.max_avg_ratio = max_load/avg_load;
   } else if (lb == 3) {
-    adaptive_struct.comm_refine_info.max_avg_ratio = max_load/avg_load;
+    CkpvAccess(adaptive_struct).comm_refine_info.max_avg_ratio = max_load/avg_load;
   }
 }
 
@@ -1230,7 +1243,7 @@ void LBDatabase::UpdateAfterLBComm(double alpha_beta_to_load) {
 
 void LBDatabase::GetPrevLBData(int& lb_type, double& lb_max_avg_ratio, double&
     remote_local_comm_ratio) {
-  lb_type = adaptive_struct.last_lb_type;
+  lb_type = CkpvAccess(adaptive_struct).last_lb_type;
   lb_max_avg_ratio = 1;
   remote_local_comm_ratio = 1;
   GetLBDataForLB(lb_type, lb_max_avg_ratio, remote_local_comm_ratio);
@@ -1239,14 +1252,14 @@ void LBDatabase::GetPrevLBData(int& lb_type, double& lb_max_avg_ratio, double&
 void LBDatabase::GetLBDataForLB(int lb_type, double& lb_max_avg_ratio, double&
     remote_local_comm_ratio) {
   if (lb_type == 0) {
-    lb_max_avg_ratio = adaptive_struct.greedy_info.max_avg_ratio;
+    lb_max_avg_ratio = CkpvAccess(adaptive_struct).greedy_info.max_avg_ratio;
   } else if (lb_type == 1) {
-    lb_max_avg_ratio = adaptive_struct.refine_info.max_avg_ratio;
+    lb_max_avg_ratio = CkpvAccess(adaptive_struct).refine_info.max_avg_ratio;
   } else if (lb_type == 2) {
-    remote_local_comm_ratio = adaptive_struct.comm_info.remote_local_ratio;
+    remote_local_comm_ratio = CkpvAccess(adaptive_struct).comm_info.remote_local_ratio;
   } else if (lb_type == 3) {
     remote_local_comm_ratio =
-       adaptive_struct.comm_refine_info.remote_local_ratio;
+       CkpvAccess(adaptive_struct).comm_refine_info.remote_local_ratio;
   }
 }
 
index f1b14a009bbd96b620a6e22960d36a4cebdc1dc6..98c3d921a4d76ff84808506d1b9d306ecbe7f202 100644 (file)
@@ -359,6 +359,7 @@ public:
   inline double GetLBPeriod() { return LDGetLBPeriod(myLDHandle);}
 
   void ResetAdaptive();
+  int get_iteration();
   bool AddLoad(int iteration, double load);
   void ReceiveMinStats(CkReductionMsg *);
   void TriggerSoon(int iteration_no, double imbalance_ratio, double tolerate_imb);