bool NameParser::match (const std::string& file_name, std::vector<int>& indices) const
    {
      int current = 0;
      size_t num = 0;
      indices.resize (seq_index.size());

      for (size_t i = 0; i < array.size(); i++) {
        if (array[i].is_string()) {
          if (file_name.substr (current, array[i].string().size()) != array[i].string()) 
            return false;
          current += array[i].string().size();
        }
        else {
          int x = current;
          while (isdigit (file_name[current]))
            current++;
          if (x == current) 
            return false;
          x = to<int> (file_name.substr (x, current-x));
          if (!in_seq (array[i].sequence(), x)) 
            return false;
          indices[num] = x;
          num++;
        }
      }
      return true;
    }
Exemple #2
0
int main(int argc, char *argv[])
{
	int x=-1;
	srand(0);
	
	if(argc<2){
		fprintf(stderr, "Specify log2 of transform size.");
		exit(1);
	}

	if(argc>2)
		x=atoi(argv[2]);

	tbb::task_scheduler_init init(x);
	
	int log2n=atoi(argv[1]);
	int n=1<<log2n;

	std::vector<std::complex<double> > in(n, 0.0), in_tbb(n, 0.0), in_opt(n, 0.0), in_seq(n, 0.0), out(n), out_tbb(n), out_opt(n), out_seq(n);
	for(int j=0;j<n;j++){
		in[j]=std::complex<double>(rand()/(double)(RAND_MAX) - 0.5, rand()/(double)(RAND_MAX) - 0.5);
	}

	fft(n, &in[0], &out[0]); //warmup run	
	tbb::tick_count serial_start = tbb::tick_count::now();
	for (int i = 0; i < ITER; ++i)
		fft(n, &in[0], &out[0]);
	tbb::tick_count serial_end = tbb::tick_count::now();
	std::cout << (serial_end - serial_start).seconds()/ITER << std::endl;
	if (!(check(n, &out[0] ,&out[0]))) //check against original results for correct result
		std::cout << "Error in original code!" << std::endl;


	fft_tbb(n, &in[0], &out_tbb[0]); //warmup run
	tbb::tick_count tbb_start = tbb::tick_count::now();
	for (int i = 0; i < ITER; ++i)
		fft_tbb(n, &in[0], &out_tbb[0]);
	tbb::tick_count tbb_end = tbb::tick_count::now();
	std::cout << (tbb_end - tbb_start).seconds()/ITER << std::endl;
	if (!(check(n, &out[0] ,&out_tbb[0]))) //check against original results for correct result
		std::cout << "Error in original code!" << std::endl;


	fft_opt(n, &in[0], &out_opt[0]); //warmup run
	tbb::tick_count opt_start = tbb::tick_count::now();
	for (int i = 0; i < ITER; ++i)
		fft_opt(n, &in[0], &out_opt[0]);
	tbb::tick_count opt_end = tbb::tick_count::now();
	std::cout << (opt_end - opt_start).seconds()/ITER << std::endl;
	if (!(check(n, &out[0] ,&out_opt[0]))) //check against original results for correct result
		std::cout << "Error in original code!" << std::endl;


	fft_seq(n, &in[0], &out_seq[0]); //warmup run
	tbb::tick_count seq_start = tbb::tick_count::now();
	for (int i = 0; i < ITER; ++i)
		fft_seq(n, &in[0], &out_seq[0]);
	tbb::tick_count seq_end = tbb::tick_count::now();
	std::cout << (seq_end - seq_start).seconds()/ITER << std::endl;
	if (!(check(n, &out[0] ,&out_seq[0]))) //check against original results for correct result
		std::cout << "Error in original code!" << std::endl;

		
	/* To test this, you can try loading the output into matlab. Load
		the output as a four column matrix x. Then the input is:
			in=x(:,1)+x(:,2)*i
		and the output is:
			out=x(:,3)+x(:,4)*i
		You can then do fft(in) to check what matlab thinks it should be.
		Note that this fft and matlab fft produce outputs in different
		orders. How could you "sort" (hint-hing) that out in matlab so that
		you can check you have the same spectrum.
	
		You can also try putting in various types of sine wave, and checking
		whether you get the right frequency peaks in the output. You're
		the signal processing experts, I assume you know what a fourier
		transform does.
	
		Note that this not a very accurate fft, so you should expect
		the error to grow as the transform size grows.
	*/
	
	return 0;
}
void
PersistenceUpdater::requestImage()
{
  if (um_ == NULL) {
    return;
  }

  DImage image;

  // Allocate space to hold the QOS sequences.
  std::vector<ArrDelAdapter<char> > qos_sequences;

  for (ParticipantIndex::ITERATOR iter = participant_index_->begin();
       iter != participant_index_->end(); iter++) {
    const PersistenceUpdater::Participant* participant
    = (*iter).int_id_;

    size_t qos_len = participant->participantQos.second.first;
    char *buf;
    ACE_NEW_NORETURN(buf, char[qos_len]);
    qos_sequences.push_back(ArrDelAdapter<char>(buf));

    if (buf == 0) {
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("PersistenceUpdater::requestImage(): allocation failed.\n")));
      return;
    }

    ACE_OS::memcpy(buf, participant->participantQos.second.second, qos_len);

    BinSeq in_seq(qos_len, buf);
    QosSeq qos(ParticipantQos, in_seq);
    DParticipant dparticipant(participant->domainId
                              , participant->owner
                              , participant->participantId
                              , qos);
    image.participants.push_back(dparticipant);
  }

  for (TopicIndex::ITERATOR iter = topic_index_->begin();
       iter != topic_index_->end(); iter++) {
    const PersistenceUpdater::Topic* topic = (*iter).int_id_;

    size_t qos_len = topic->topicQos.second.first;
    char *buf;
    ACE_NEW_NORETURN(buf, char[qos_len]);
    qos_sequences.push_back(ArrDelAdapter<char>(buf));

    if (buf == 0) {
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("PersistenceUpdater::requestImage(): allocation failed.\n")));
      return;
    }

    ACE_OS::memcpy(buf, topic->topicQos.second.second, qos_len);

    BinSeq in_seq(qos_len, buf);
    QosSeq qos(TopicQos, in_seq);
    DTopic dTopic(topic->domainId, topic->topicId
                  , topic->participantId, topic->name.c_str()
                  , topic->dataType.c_str(), qos);
    image.topics.push_back(dTopic);
  }

  for (ActorIndex::ITERATOR iter = actor_index_->begin();
       iter != actor_index_->end(); iter++) {
    const PersistenceUpdater::RWActor* actor = (*iter).int_id_;

    size_t qos_len = actor->pubsubQos.second.first;
    char *buf;
    ACE_NEW_NORETURN(buf, char[qos_len]);
    qos_sequences.push_back(ArrDelAdapter<char>(buf));

    if (buf == 0) {
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("PersistenceUpdater::requestImage(): allocation failed.\n")));
      return;
    }

    ACE_OS::memcpy(buf, actor->pubsubQos.second.second, qos_len);

    BinSeq in_pubsub_seq(qos_len, buf);
    QosSeq pubsub_qos(actor->pubsubQos.first, in_pubsub_seq);

    qos_len = actor->drdwQos.second.first;
    ACE_NEW_NORETURN(buf, char[qos_len]);
    qos_sequences.push_back(ArrDelAdapter<char>(buf));

    if (buf == 0) {
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("PersistenceUpdater::requestImage(): allocation failed.\n")));
      return;
    }

    ACE_OS::memcpy(buf, actor->drdwQos.second.second, qos_len);

    BinSeq in_drdw_seq(qos_len, buf);
    QosSeq drdw_qos(actor->drdwQos.first, in_drdw_seq);

    qos_len = actor->transportInterfaceInfo.first;
    ACE_NEW_NORETURN(buf, char[qos_len]);
    qos_sequences.push_back(ArrDelAdapter<char>(buf));

    if (buf == 0) {
      ACE_ERROR((LM_ERROR,
                 ACE_TEXT("PersistenceUpdater::requestImage(): allocation failed.\n")));
      return;
    }

    ACE_OS::memcpy(buf, actor->transportInterfaceInfo.second, qos_len);

    BinSeq in_transport_seq(qos_len, buf);

    ContentSubscriptionBin in_csp_bin;
    if (actor->type == DataReader) {
      in_csp_bin.filterClassName = actor->contentSubscriptionProfile.filterClassName;
      in_csp_bin.filterExpr = actor->contentSubscriptionProfile.filterExpr;
      BinSeq& params = in_csp_bin.exprParams;
      ACE_NEW_NORETURN(params.second, char[params.first]);
      if (params.second == 0) {
        ACE_ERROR((LM_ERROR,
                   ACE_TEXT("PersistenceUpdater::requestImage(): allocation ")
                   ACE_TEXT("failed.\n")));
        return;
      }
      qos_sequences.push_back(ArrDelAdapter<char>(params.second));
      ACE_OS::memcpy(params.second,
        actor->contentSubscriptionProfile.exprParams.second, params.first);
    }

    DActor dActor(actor->domainId, actor->actorId, actor->topicId
                  , actor->participantId
                  , actor->type, actor->callback.c_str()
                  , pubsub_qos, drdw_qos, in_transport_seq, in_csp_bin);
    image.actors.push_back(dActor);
  }