fixed a bug on multiple processors because variable is not initialized
authorYanhuaSun <sun51@illinois.edu>
Mon, 6 Jun 2011 04:53:58 +0000 (23:53 -0500)
committerYanhuaSun <sun51@illinois.edu>
Mon, 6 Jun 2011 04:53:58 +0000 (23:53 -0500)
examples/charm++/state_space_searchengine/TSP_SE/main.C
examples/charm++/state_space_searchengine/TSP_SE/searchEngineAPI.C
examples/charm++/state_space_searchengine/searchengineLib/searchEngine.h

index 94d1125bb9f3aa80e99133d0873870db547353c2..2e129e3eeec4163cc35f8ab404310fa26eb39572 100644 (file)
@@ -165,6 +165,8 @@ void readinput(char* filename)
 }
  
 
+extern void set_statesize(int);
+
 class Main
 {
 public:
@@ -193,6 +195,8 @@ public:
         }
         initial_grainsize = atoi(m->argv[3]);
 
+        set_statesize(N);
+
         CkPrintf("start\n");
         searchEngineProxy.start();
         delete m;
index e56eca65660a172c9c0b606f055504426b031dd4..add82164c285851fc32e0d251f4c6b16b63ceaea 100644 (file)
@@ -23,7 +23,7 @@ class TspBase: public StateBase
 {
 public:
        int length; // length
-       double cost;
+    double cost;
     double lowerBoundValue;
     int *tour;
     int *intour; //whether a node is in tour or not
@@ -114,7 +114,7 @@ inline double lowerBound( StateBase *s)
 inline void createInitialChildren(Solver *solver)
 {
 
-    se_statesize = sizeof(TspBase)+2*sizeof(int)*N;
+//    se_statesize = sizeof(TspBase)+2*sizeof(int)*N;
     TspBase *state = (TspBase*)solver->registerRootState(sizeof(TspBase)+2*sizeof(int)*N, 0, 1);
     state->initialize();
     state->tour[0]=0;
@@ -126,6 +126,7 @@ inline void createInitialChildren(Solver *solver)
 #ifdef USEINTPRIORITY
     solver->setPriority(state, (int)lowerBound(state));
 #endif
+    CmiAssert(state->length>0);
     solver->process(state);
 }
 
@@ -137,6 +138,8 @@ inline void createChildren( StateBase *_base , Solver* solver, bool parallel)
     ((TspBase*)_base)->initialize();
     s->copy((TspBase*)_base);
     int childIndex = 0;
+    CmiAssert(((TspBase*)_base)->length>0);
+    CmiAssert(s->length>0);
     int last = s->tour[s->length-1];
     int childNum = 0;
     //CkPrintf("lower bound=%f\n", s->getLowerBound());
@@ -172,6 +175,7 @@ inline void createChildren( StateBase *_base , Solver* solver, bool parallel)
 #ifdef USEINTPRIORITY
             solver->setPriority(NewTour, (int)lowerBound(NewTour));
 #endif
+            CmiAssert(NewTour->length>0);
             solver->process(NewTour);
         }
     }
@@ -187,6 +191,11 @@ int searchDepthLimit()
     return 1;
 }
 
+void set_statesize(int N)
+{
+        se_statesize = sizeof(TspBase)+2*sizeof(int)*N;
+}
+
     SE_Register(TspBase, createInitialChildren, createChildren, parallelLevel, searchDepthLimit, lowerBound);
 
 
index 1bb0ffdf3e5e754f5beafb1f27ce7686a3ce5732..611297f16cf7a70dbe931c0651af16aed67822da 100644 (file)
@@ -90,7 +90,7 @@ extern int se_statesize;
       SE_register(f1, f2, f3, f4, f5);   \
     }  \
     void createMultipleChildren(SearchGroup* myGroup, StateBase *parent, SequentialSolver* solver, bool parallel) {  \
-       StateBase *state;  \
+       StateBase *_state;  \
        double avgentrytime = 0;  \
        int processed_nodes = 1; \
        double instrument_start; \
@@ -101,7 +101,7 @@ extern int se_statesize;
         if(lb<minCost)  \
             f2(parent, solver, false);  \
         accumulate_time = avgentrytime  = CkWallTimer() - instrument_start;  \
-        while((state=solver->dequeue()) != NULL) \
+        while((_state=solver->dequeue()) != NULL) \
         {  \
             minCost = myGroup->getCost(); \
             lb = f5(parent); \
@@ -111,7 +111,7 @@ extern int se_statesize;
             {  \
                 avgentrytime  = (CkWallTimer() - instrument_start)/20;  \
             }  \
-            f2(state, solver, parallel); \
+            f2(_state, solver, parallel); \
             accumulate_time += avgentrytime; \
             if(accumulate_time > ENTRYGRAIN)  \
             {  solver-> dequeue_multiple(avgentrytime, processed_nodes);} \