Ejemplo n.º 1
0
static int open_TraceWin()
		/*success-> return 0;*/
{
	int		i;

	open_window(&win, kTraceWinID);
	position_window(&win);
	
	mac_ctl_reset_trc();
	for(i = 0; i < 16; i++)
	    init_bitset(channel_program_flags + i, 128);

	return 0;
}
Ejemplo n.º 2
0
int main(void)
{

    int x, i, j;
    scanf("%d", &x);
    void* bitset = init_bitset(x + 1);

    for(i = 2; i * i <= x; i++)
        if(!get_bitset(bitset, i))
            for(j = i * i; j <= x; j += i)
                set_bitset(bitset, j, 1);

    int count = 0;
    for(i = 2; i <= x; i++)
        if(!get_bitset(bitset, i))
            count++;
    printf("%d", count);
    destroy_bitset(bitset);
    return 0;
}
Ejemplo n.º 3
0
/*-------------------------------------------
 * A Node coloring routine which does the following 
 *  - Find the next constrained vertex, vIndex  (variable Ordering)
 *  - Test if the `vIndex` vertex is colorable. Return false if not.
 *  - Find the colors possible for vIndex (Value Ordering of Colors)
 *    - The colors will be found in the priority order   
 *    - If for a particular color option, one of the ngb of
 *      vIndex is reduced to zero available colors, then dont consider that
 *      color. (Impossibility Testing)
 *  - Spawn a new node state in priority order for each possible  color.
 *    - In that Node state, mark the color of vIndex
 *    - Update the coloring info for ngbs of vIndex
 *    - If by coloring vIndex with a particular color
 *      one of its ngbs reduced to one color possibility,
 *      then color that vertex as well recursively. (Forced Move) 
 *   ----------------------------------------*/
void Node::colorRemotely(){

#ifdef DEBUG
  char *id = new char[nodeID_.size()];
  strcpy(id, nodeID_.c_str());
  CkPrintf("Color remotely in node [%s] with uncolored num=%d\n", id, uncolored_num_);
  delete [] id;
#endif

  //-----------------------------------------------
  //Detect Subgraphs
  //If have >=2 subgraphs, make this node and_node
  //and spawn children to color each subgraphs
  //----------------------------------------------
  //only if some vertices are removed, otherwise
  //no new subgraphs will be created
  if(doSubgraph){
  boost::dynamic_bitset<> init_bitset(vertices_);
  init_bitset.set();
  //initialize the bitset by marking all removed vertices as 0
  //and existed vertices as 1
  CkAssert(node_state_.size()==vertices_);
  for(int i=0; i<vertices_; i++){
    //these vertices have been removed from current graph
    if(!node_state_[i].isOperationPermissible())
      init_bitset.reset(i);
  }
  pq_subgraph_type prioritySubgraphs;
  //detect subgraphs and create states correspondingly
  if(detectAndCreateSubgraphs( init_bitset, prioritySubgraphs ) ){

    //#ifdef DEUBG
    char * id = new char[nodeID_.size()+1];
    strcpy(id, nodeID_.c_str());
    CkPrintf("Found %d subgraphs in node[%s]\n", prioritySubgraphs.size(), id);
    delete [] id;
    //#endif

    is_and_node_ = true;

    int numChildrenStates = prioritySubgraphs.size();
    UShort childBits = _log(numChildrenStates);
    while( ! prioritySubgraphs.empty() ){
      boost::dynamic_bitset<> subgraph_bitset = prioritySubgraphs.top();
      prioritySubgraphs.pop();

      std::vector<vertex> new_state = node_state_;
      boost::dynamic_bitset<> remove_bitset = init_bitset ^ subgraph_bitset;
#ifdef DEBUG
      std::string s;
      boost::to_string(subgraph_bitset, s);
      char * bits = new char[s.size()+1];
      strcpy(bits, s.c_str());
      CkPrintf("subgraph bitset: %s\n", bits);
      delete [] bits;
#endif
      for(int i=0; i<remove_bitset.size(); i++){
        if(remove_bitset.test(i)){
          new_state[i].set_out_of_subgraph(true);
        }
      }


      if(doPriority){
        CkEntryOptions* opts = new CkEntryOptions();
        UShort newParentPrioBits; UInt* newParentPrioPtr;
        UInt newParentPrioPtrSize;
        getPriorityInfo(newParentPrioBits, newParentPrioPtr, newParentPrioPtrSize,
            parentBits, parentPtr, childBits, child_num_);
        opts->setPriority(newParentPrioBits, newParentPrioPtr);
        CProxy_Node::ckNew(new_state, false,
            subgraph_bitset.count(), thisProxy,
            nodeID_+std::to_string(child_num_),
            newParentPrioBits, newParentPrioPtr, newParentPrioPtrSize,
            CK_PE_ANY, opts);
        free(newParentPrioPtr);
      } else {
        CProxy_Node::ckNew(new_state, false,
            subgraph_bitset.count(), thisProxy,
            nodeID_+std::to_string(child_num_),
            0, NULL, 0);
      }
      child_num_++;
    }
    return;
  }
  }
  // -----------------------------------------
  // Following code deals with case is_and_node=false
  // -----------------------------------------

  int vIndex = this->getNextConstraintVertex();
  CkAssert(vIndex!=-1);

  boost::dynamic_bitset<> possibleColor = node_state_[vIndex].getPossibleColor();
  if(!possibleColor.any()){
    parent_.finish(false, node_state_);
    return;
  }

  pq_type priorityColors = getValueOrderingOfColors(vIndex);
  int numChildrenStates = priorityColors.size();
  UShort childBits = _log(numChildrenStates);

  while (! priorityColors.empty()) {

    /* priorityColors contains the vertex 
     *   colors (c1 > c2 > c3 ..) in the order governed by the valueOrdering.
     *   If we are not concerned about prioritization while
     *   firing chares, i.e. doPriority == false , we can just spawn a chare for each poped
     *   element of priorityColors. Else if (doPriority == true)
     *   and say priorityColors has elements c1: c2:c3 (such that c1 > c2 > c3)
     *   then we have to fire c1, c2 and c3 with priority Ptr00, Ptr01, Ptr10
     *   respectively, where Ptr is the priority bits for their parent.
     */
    std::pair<int,int> p =  priorityColors.top();
    priorityColors.pop();

    std::vector<vertex> new_state = node_state_;
    CkAssert(p.first < chromaticNum_);
    int verticesColored = updateState(new_state, vIndex, p.first, true);
    CkAssert(verticesColored >= 1);

    if(doPriority) {
      CkEntryOptions* opts = new CkEntryOptions ();
      UShort newParentPrioBits; UInt* newParentPrioPtr;
      UInt newParentPrioPtrSize;
      getPriorityInfo(newParentPrioBits, newParentPrioPtr, newParentPrioPtrSize, parentBits, parentPtr, childBits, child_num_);
      opts->setPriority(newParentPrioBits, newParentPrioPtr);

      CProxy_Node::ckNew(new_state, false, uncolored_num_- verticesColored, 
          thisProxy, nodeID_ + std::to_string(child_num_), newParentPrioBits, newParentPrioPtr, 
          newParentPrioPtrSize, CK_PE_ANY , opts);
      child_num_ ++;
      free(newParentPrioPtr);
    } else {
      CProxy_Node::ckNew(new_state, false, uncolored_num_- verticesColored, 
          thisProxy, nodeID_ + std::to_string(child_num_), 0, NULL, 0);
      child_num_ ++;
    }
  }
}