Ejemplo n.º 1
0
void parallel_partial_sum(Iterator first,Iterator last)
{
    typedef typename Iterator::value_type value_type;

    struct process_element
    {
        void operator()(Iterator first,Iterator last,
                        std::vector<value_type>& buffer,
                        unsigned i,barrier& b)
        {
            value_type& ith_element=*(first+i);
            bool update_source=false;
            for(unsigned step=0,stride=1;stride<=i;++step,stride*=2)
            {
                value_type const& source=(step%2)?
                    buffer[i]:ith_element;
                value_type& dest=(step%2)?
                    ith_element:buffer[i];
                value_type const& addend=(step%2)?
                    buffer[i-stride]:*(first+i-stride);
                dest=source+addend;
                update_source=!(step%2);
                b.wait();
            }
            if(update_source)
            {
                ith_element=buffer[i];
            }
            b.done_waiting();
        }
    };

    unsigned long const length=std::distance(first,last);

    if(length<=1)
        return;

    std::vector<value_type> buffer(length);
    barrier b(length);
    std::vector<std::thread> threads(length-1);
    join_threads joiner(threads);

    Iterator block_start=first;
    for(unsigned long i=0;i<(length-1);++i)
    {
        threads[i]=std::thread(process_element(),first,last,
                               std::ref(buffer),i,std::ref(b));
    }
    process_element()(first,last,buffer,length-1,b);
}
Ejemplo n.º 2
0
int process_element(

  xmlNode                  *node)

  {
  char *str;
  int   rc = PBSE_NONE;

  if (node == NULL)
    return(PBSE_NONE);

  if (!strcmp((const char *)node->name, response_data))
    {
    str = (char *)xmlGetProp(node, (const xmlChar *)"status");
    if (strcmp(str, success))
      {
      free(str);
      return(ALPS_QUERY_FAILURE);
      }
    else
      rc = process_element(node->children);

    free(str);
    }
  else if (!strcmp((const char *)node->name, node_array))
    {
    rc = process_nodes(node->children);
    rc = process_element(node->next);
    }
  else if (!strcmp((const char *)node->name, reservation_array))
    {
    rc = process_reservations(node->children);
    }
  else if (!strcmp((const char *)node->name, text_name))
    {
    rc = process_element(node->next);
    }
  else if (!strcmp((const char *)node->name, system_tag))
    {
    rc = process_system(node);
    }
  else
    {
    /* move on to the next child */
    rc = process_element(node->children);
    }

  return(rc);
  } /* END process_element() */
Ejemplo n.º 3
0
int parse_alps_output(

  std::string              &alps_output)

  {
  xmlDocPtr  doc;
  xmlNode   *child;

  if ((doc = xmlReadMemory(alps_output.c_str(), alps_output.length(), "apbasil", NULL, 0)) == NULL)
    {
    char buf[MAXLINE * 4];
    xmlErrorPtr pErr = xmlGetLastError();
    snprintf(buf, sizeof(buf), "Failed to parse the output of alps - %s", pErr->message);
    log_err(-1, __func__, buf);
    return(ALPS_PARSING_ERROR);
    }

  if (process_element(xmlDocGetRootElement(doc)) == ALPS_QUERY_FAILURE)
    {
    xmlNode   *root = xmlDocGetRootElement(doc);
	  // Verbose debug output for ALPS_QUERY_FAILURE node error message
	  for (child = root->children; child != NULL; child = child->next)
	    {
	    if (!strcmp((const char *)child->name, response_data))
	      {
        for (xmlNode *gchild = child->children; gchild != NULL; gchild = gchild->next)
          {
          if (!strcmp((const char *)gchild->name, "Message"))
            {
            snprintf(log_buffer, sizeof(log_buffer),
              "Failed to query ALPS: %s", (const char *)xmlNodeGetContent(gchild));
            log_record(PBSEVENT_SYSTEM, 0, __func__, log_buffer);
            }
          }
	      }
	    }

  	return(ALPS_QUERY_FAILURE);
    }


  xmlFreeDoc(doc);
  xmlMemoryDump();

  return(PBSE_NONE);
  } /* END parse_alps_output() */
Ejemplo n.º 4
0
void TopologyController::process(const GstDebugger::TopologyInfo& topology)
{
	lock_topology();

	switch (topology.topology_type_case())
	{
	case GstDebugger::TopologyInfo::kElement:
		process_element(topology.element(), topology.action());
		break;
	case GstDebugger::TopologyInfo::kPad:
		process_pad(topology.pad(), topology.action());
		break;
	case GstDebugger::TopologyInfo::kLink:
		process_link(topology.link(), topology.action());
		break;
	default:
		break;
	}

	unlock_topology();
}
int parse_alps_output(

  dynamic_string *alps_output,
  dynamic_string *status)

  {
  xmlDocPtr  doc;

  if ((doc = xmlReadMemory(alps_output->str, strlen(alps_output->str), "apbasil", NULL, 0)) == NULL)
    {
    char buf[MAXLINE * 4];
    xmlErrorPtr pErr = xmlGetLastError();
    snprintf(buf, sizeof(buf), "Failed to parse the output of alps - %s", pErr->message);
    log_err(-1, __func__, buf);
    return(ALPS_PARSING_ERROR);
    }

  process_element(status, xmlDocGetRootElement(doc));

  xmlFreeDoc(doc);
  xmlMemoryDump();

  return(PBSE_NONE);
  } /* END parse_alps_output() */
Ejemplo n.º 6
0
/*
 * Performs one complete dominant pass. Dominant-pass-codes are sent to the
 * output stream and the subordinate list is updated.
 */
void dominant_pass(matrix_2d *m, element_type threshold)
{
	ezw_element s;
	int min_x, max_x, min_y, max_y;
	//将当前扫描位置移至example[0][0]处,并进行判断、量化
	s.x = 0;
	s.y = 0;
	//将该系数与当前阈值进行比较,符号化
	process_element(m,threshold,&s);
	//将上一步的结果进行输出编码
	output_code(s.code);
	//对example[1][0],example[0][1],example[1][1]进行判断、量化
	s.x = 1;
	s.y = 0;
	//将该系数与当前阈值进行比较,符号化
	process_element(m,threshold,&s);
	//将上一步的结果放到扫描序列中
	put_in_fifo(s);
	s.x = 0;
	s.y = 1;
	//将该系数与当前阈值进行比较,符号化
	process_element(m,threshold,&s);
	//将上一步的结果放到扫描序列中
	put_in_fifo(s);
	s.x = 1;
	s.y = 1;
	//将该系数与当前阈值进行比较,符号化
	process_element(m,threshold,&s);
	//将上一步的结果放到扫描序列中
	put_in_fifo(s);
	//从扫描序列中取出一个系数
	s = get_from_fifo();
	//假如序列为空,直接将其送输出编码
	if (fifo_empty==0) 
		output_code(s.code);
	while (fifo_empty==0) 
	{
		//如果当前编码不为ZTR,则将当前扫描移至下一频段
		if (s.code!=ZTR) 
		{
			//横坐标最小值左移1位,即加倍
			min_x = s.x << 1;
			//横坐标最大值为最小值加1
			max_x = min_x+1;
			//纵坐标最小值左移1位,即加倍
			min_y = s.y << 1;
			//纵坐标最大值为最小值加1
			max_y = min_y+1;
			if ((max_x<=m->col) && (max_y<=m->row)) 
			{
				for (s.y=min_y; s.y<max_y+1; s.y++) 
				{
					for (s.x=min_x; s.x<max_x+1; s.x++) 
					{
						process_element(m,threshold,&s);
						put_in_fifo(s);
					}
				}
			}
		}
		s = get_from_fifo();
		if (fifo_empty==0) output_code(s.code);
	}
}