Exemplo n.º 1
0
		void ping(int callee) { 
			//CkPrintf("[chare=%d,pe=%d]: %d: ping called by %d\n", 
			//		getuChareSet()->getId(), getuChareSet()->getPe(), getId(), callee);
			if (++counter == N_uChares) {
				//CkPrintf("[chare=%d,pe=%d]: %d: alltoall done\n", 
				//		getuChareSet()->getId(), getuChareSet()->getPe(), getId());
				mainProxy.done();
			}
		}
Exemplo n.º 2
0
 void SayHi(int hiNo)
 {
   CkPrintf("Hi[%d] from element %d\n",hiNo,thisIndex);
   if (thisIndex < nElements-1)
     //Pass the hello on:
     thisProxy[thisIndex+1].SayHi(hiNo+1);
   else 
     //We've been around once-- we're done.
     mainProxy.done();
 }
Exemplo n.º 3
0
 void SayHi(int hiNo)
 {
   CkPrintf("Hi[%d] from element %d\n",hiNo,thisIndex);
   CProxy_Hello delArr=arr;
   delArr.ckDelegate(delMgr.ckLocalBranch());
   if (thisIndex < nElements-1)
     //Pass the hello on:
     delArr[thisIndex+1].SayHi(hiNo+1);
   else 
     //We've been around once-- we're done.
     mainProxy.done();
 }
Exemplo n.º 4
0
  void SayHi2(int hiNo)
  {
    CkPrintf("Hi 2 [%d] from element (%d,%d,%d)\n",hiNo,
	thisIndex.x,thisIndex.y,thisIndex.z);
    int y=thisIndex.y+1;
    if (y < nElements) {
      //Pass the hello on:
      thisProxy(37,y,2*y+1).SayHi2(hiNo+1);
    }
    else 
      //We've been around once-- we're done.
      mainProxy.done();
  }
Exemplo n.º 5
0
bool mySolver::seq_solve(par_SolverState* state_msg)
{
    /* Which variable get assigned  */
    par_Lit lit = state_msg->assigned_lit;
       
#ifdef DEBUG
    CkPrintf("\n\n Computes=%d Sequential SAT New chare: literal = %d,  level=%d, unsolved clauses=%d\n", computes++, toInt(assigned_var), state_msg->level, state_msg->clauses.size());
    //CkPrintf("\n\n Computes=%d Sequential SAT New chare: literal = %d, occurrence size=%d, level=%d \n", computes++, toInt(assigned_var), state_msg->occurrence.size(), state_msg->level);
#endif
    par_SolverState *next_state = copy_solverstate(state_msg);
    
    //Unit clauses
    /* use this value to propagate the clauses */
#ifdef DEBUG
    CkPrintf(" remainning clause size is %d\n", (state_msg->clauses).size());
#endif

    int _unit_ = -1;
    while(1){
    int pp_ = 1;
    int pp_i_ = 2;
    int pp_j_ = 1;

    if(toInt(lit) < 0)
    {
        pp_ = -1;
        pp_i_ = 1;
        pp_j_ = 2;
    }

    next_state->occurrence[pp_*toInt(lit)-1] = -pp_i_;
    
    map_int_int &inClauses = next_state->whichClauses[pp_*2*toInt(lit)-pp_i_];
    map_int_int &inClauses_opposite = next_state->whichClauses[pp_*2*toInt(lit)-pp_j_];

    // literal with same sign, remove all these clauses
    
    for( map_int_int::iterator iter = inClauses.begin(); iter!=inClauses.end(); iter++)
    {
        int cl_index = (*iter).first;
        par_Clause& cl_ = next_state->clauses[cl_index];
        //for all the literals in this clauses, the occurrence decreases by 1
        for(int k=0; k< cl_.size(); k++)
        {
            par_Lit lit_ = cl_[k];
            if(toInt(lit_) == toInt(lit))
                continue;
            next_state->occurrence[abs(toInt(lit_)) - 1]--;
            if(toInt(lit_) > 0)
            {
                next_state->positive_occurrence[toInt(lit_)-1]--;
                map_int_int::iterator one_it = next_state->whichClauses[2*toInt(lit_)-2].find(cl_index);
                next_state->whichClauses[2*toInt(lit_)-2].erase(one_it);
            }else
            {
                map_int_int::iterator one_it = next_state->whichClauses[-2*toInt(lit_)-1].find(cl_index);
                next_state->whichClauses[-2*toInt(lit_)-1].erase(one_it);
            }

        }
        next_state->clauses[cl_index].resize(0);
    }
   
    for(map_int_int::iterator iter= inClauses_opposite.begin(); iter!=inClauses_opposite.end(); iter++)
    {
        int cl_index_ = (*iter).first;
        par_Clause& cl_neg = next_state->clauses[cl_index_];
        cl_neg.remove(-toInt(lit));
            //becomes a unit clause
         if(cl_neg.size() == 1)
         {
             next_state->unit_clause_index.push_back(cl_index_);
         }else if (cl_neg.size() == 0)
         {
                return false;
         }
    }
   
    _unit_++;
    if(_unit_ == next_state->unit_clause_index.size())
        break;
    par_Clause cl = next_state->clauses[next_state->unit_clause_index[_unit_]];
    
    while(cl.size() == 0){
        _unit_++;
        if(_unit_ == next_state->unit_clause_index.size())
            break;
        cl = next_state->clauses[next_state->unit_clause_index[_unit_]];
        
    };

    if(_unit_ == next_state->unit_clause_index.size())
        break;
    
    lit = cl[0];
    }
   
    int unsolved = next_state->unsolvedClauses();
    if(unsolved == 0)
    {
        CkPrintf("One solution found in sequential processing, check the output file for assignment\n");
        mainProxy.done(next_state->occurrence);
        return true;
    }
    
    /**********************/
    
        /* it would be better to insert the unit literal in order of their occurrence */
        /* make a decision and then fire new tasks */
        /* if there is unit clause, should choose these first??? TODO */
        /* TODO which variable to pick up */
        /*unit clause literal and also which occurrs most times */
        int max_index =  get_max_element(next_state->occurrence);
#ifdef DEBUG
        CkPrintf("max index = %d\n", max_index);
#endif
        next_state->level = state_msg->level+1;

        par_SolverState *new_msg2 = copy_solverstate(next_state);;
        
        int positive_max = next_state->positive_occurrence[max_index];
        if(positive_max >= next_state->occurrence[max_index] - positive_max)
        {
            next_state->occurrence[max_index] = -2;
            next_state->assigned_lit = par_Lit(max_index+1);
        }
        else
        {
            next_state->occurrence[max_index] = -1;
            next_state->assigned_lit = par_Lit(-max_index-1);
        } 

        bool   satisfiable_1 = seq_solve(next_state);
        if(satisfiable_1)
        {
            return true;
        }
        
        new_msg2->level = state_msg->level+1;
       
        if(positive_max >= next_state->occurrence[max_index] - positive_max)
        {
            new_msg2->occurrence[max_index] = -1;
            new_msg2->assigned_lit = par_Lit(-max_index-1);
        }
        else
        {
            new_msg2->occurrence[max_index] = -2;
            new_msg2->assigned_lit = par_Lit(max_index+1);
        } 
            
        bool satisfiable_0 = seq_solve(new_msg2);
        if(satisfiable_0)
        {
            return true;
        }

        //CkPrintf("Unsatisfiable through sequential\n");
        return false;

}
Exemplo n.º 6
0
mySolver::mySolver(par_SolverState* state_msg)
{

    /* Which variable get assigned  */
    par_Lit lit = state_msg->assigned_lit;
#ifdef DEBUG    
    CkPrintf("\n\nNew chare: literal = %d, occurrence size=%d, level=%d \n", toInt(lit), state_msg->occurrence.size(), state_msg->level);
#endif    
    par_SolverState *next_state = copy_solverstate(state_msg);

    //Unit clauses
    /* use this value to propagate the clauses */
    // deal with the clauses where this literal is
    int _unit_ = -1;
    while(1){
        int pp_ = 1;
        int pp_i_ = 2;
        int pp_j_ = 1;

        if(toInt(lit) < 0)
        {
            pp_ = -1;
            pp_i_ = 1;
            pp_j_ = 2;
        }

        next_state->occurrence[pp_*toInt(lit)-1] = -pp_i_;
    

        map_int_int &inClauses = next_state->whichClauses[pp_*2*toInt(lit)-pp_i_];
        map_int_int  &inClauses_opposite = next_state->whichClauses[pp_*2*toInt(lit)-pp_j_];

    // literal with same sign, remove all these clauses
       for( map_int_int::iterator iter = inClauses.begin(); iter!=inClauses.end(); iter++)
       {
           int cl_index = (*iter).first;

           par_Clause& cl_ = next_state->clauses[cl_index];
           //for all the literals in this clauses, the occurrence decreases by 1
           for(int k=0; k< cl_.size(); k++)
           {
               par_Lit lit_ = cl_[k];
               if(toInt(lit_) == toInt(lit))
                   continue;
               next_state->occurrence[abs(toInt(lit_)) - 1]--;
               if(toInt(lit_) > 0)
               {
                   next_state->positive_occurrence[toInt(lit_)-1]--;
                   map_int_int::iterator one_it = next_state->whichClauses[2*toInt(lit_)-2].find(cl_index);
                   next_state->whichClauses[2*toInt(lit_)-2].erase(one_it);
               }else
               {
                   map_int_int::iterator one_it = next_state->whichClauses[-2*toInt(lit_)-1].find(cl_index);
                   next_state->whichClauses[-2*toInt(lit_)-1].erase(one_it);
               }
               
           } //finish dealing with all literal in the clause
           next_state->clauses[cl_index].resize(0);
       } //finish dealing with clauses where the literal occur the same
       /* opposite to the literal */
       for(map_int_int::iterator iter= inClauses_opposite.begin(); iter!=inClauses_opposite.end(); iter++)
       {
           int cl_index_ = (*iter).first;
           par_Clause& cl_neg = next_state->clauses[cl_index_];
           cl_neg.remove(-toInt(lit));

           /*becomes a unit clause */
           if(cl_neg.size() == 1)
           {
               next_state->unit_clause_index.push_back(cl_index_);
           }else if (cl_neg.size() == 0)
           {
               return;
           }
       }

       _unit_++;
       if(_unit_ == next_state->unit_clause_index.size())
           break;
       par_Clause cl = next_state->clauses[next_state->unit_clause_index[_unit_]];

       while(cl.size() == 0){
           _unit_++;
           if(_unit_ == next_state->unit_clause_index.size())
               break;
           cl = next_state->clauses[next_state->unit_clause_index[_unit_]];
       };

       if(_unit_ == next_state->unit_clause_index.size())
           break;
       lit = cl[0];


    }
    /***************/

    int unsolved = next_state->unsolvedClauses();
    if(unsolved == 0)
    {
        CkPrintf("One solution found in parallel processing \n");
        //next_state->printSolution();
        mainProxy.done(next_state->occurrence);
        return;
    }
    int max_index = get_max_element(next_state->occurrence);
#ifdef DEBUG
    CkPrintf("max index = %d\n", max_index);
#endif
    //if() left literal unassigned is larger than a grain size, parallel 
    ///* When we start sequential 3SAT Grainsize problem*/
   
    /* the other branch */
    par_SolverState *new_msg2 = copy_solverstate(next_state);;

    next_state->level = state_msg->level+1;

    int lower = state_msg->lower;
    int higher = state_msg->higher;
    int middle = (lower+higher)/2;
    int positive_max = next_state->positive_occurrence[max_index];
    if(positive_max >= next_state->occurrence[max_index] - positive_max)
    {
        next_state->assigned_lit = par_Lit(max_index+1);
        next_state->occurrence[max_index] = -2;
    }
    else
    {
        next_state->assigned_lit = par_Lit(-max_index-1);
        next_state->occurrence[max_index] = -1;
    }
    bool satisfiable_1 = true;

    if(unsolved > grainsize)
    {
        next_state->lower = lower + 1;
        next_state->higher = middle;
        *((int *)CkPriorityPtr(next_state)) = lower+1;
        CkSetQueueing(next_state, CK_QUEUEING_IFIFO);
        CProxy_mySolver::ckNew(next_state);
    }
    else //sequential
    {
        /* This code is urgly. Need to revise it later. Convert par data structure to sequential 
         */
        vector< vector<int> > seq_clauses;
        //seq_clauses.resize(next_state->clauses.size());
        for(int _i_=0; _i_<next_state->clauses.size(); _i_++)
        {
            if(next_state->clauses[_i_].size() > 0)
            {
                vector<int> unsolvedclaus;
                par_Clause& cl = next_state->clauses[_i_];
                unsolvedclaus.resize(cl.size());
                for(int _j_=0; _j_<cl.size(); _j_++)
                {
                    unsolvedclaus[_j_] = toInt(cl[_j_]);
                }
                seq_clauses.push_back(unsolvedclaus);
            }
        }
        satisfiable_1 = seq_processing(next_state->var_size, seq_clauses);//seq_solve(next_state);
        if(satisfiable_1)
        {
            CkPrintf("One solution found by sequential processing \n");
            mainProxy.done(next_state->occurrence);
            return;
        }
    }

    new_msg2->level = state_msg->level+1;
    if(positive_max >= new_msg2->occurrence[max_index] - positive_max)
    {
        new_msg2->assigned_lit = par_Lit(-max_index-1);
        new_msg2->occurrence[max_index] = -1;
    }
    else
    {
        new_msg2->assigned_lit = par_Lit(max_index+1);
        new_msg2->occurrence[max_index] = -2;
    }
    unsolved = new_msg2->unsolvedClauses();
    if(unsolved > grainsize)
    {
        new_msg2->lower = middle + 1;
        new_msg2->higher = higher-1;
        *((int *)CkPriorityPtr(new_msg2)) = middle+1;
        CkSetQueueing(new_msg2, CK_QUEUEING_IFIFO);
        CProxy_mySolver::ckNew(new_msg2);
    }
    else
    {
       
        vector< vector<int> > seq_clauses;
        for(int _i_=0; _i_<new_msg2->clauses.size(); _i_++)
        {
            par_Clause& cl = new_msg2->clauses[_i_];
            if(cl.size() > 0)
            {
                vector<int> unsolvedclaus;
                unsolvedclaus.resize(cl.size());
                for(int _j_=0; _j_<cl.size(); _j_++)
                {
                    unsolvedclaus[_j_] = toInt(cl[_j_]);
                }
                seq_clauses.push_back(unsolvedclaus);
            }
        }

        bool ret = seq_processing(new_msg2->var_size,  seq_clauses);//seq_solve(next_state);
        //bool ret = Solver::seq_processing(new_msg2->clauses);//seq_solve(new_msg2);
        if(ret)
        {
            CkPrintf("One solution found by sequential processing \n");
            mainProxy.done(new_msg2->occurrence);
        }
        return;
    }

}
Exemplo n.º 7
0
 void SayHi(int hiNo)
 {
   CkPrintf("Hi [%d] from element %d %d %d\n", hiNo, thisIndex.x, thisIndex.y, thisIndex.z);
   mainProxy.done();
 }