int main(int argc, char **argv)
{
	if(argc < 2){
		printf("No input file given");
		exit(0);
	}
	K = 5;
    readBinary(argv[1]);
    //readFile("uniform_data_16_1000.csv");
    
    initVars();
    threshold = 0.001;
    //printf("Centroids at start:\n");
    //printCentroids();
    //printf("Starting k-Means\n");
    //printDatapoints();
    //time_t start = time(NULL);
    double startTime = get_wall_time();
    kMeans();
    double endTime = get_wall_time();
    printf("%.2f\n", endTime-startTime);
    
    printDatapointClusters();
    
    return 0;
    
}
Esempio n. 2
0
DWORD WINAPI ExtractAndSendThreadEntry(LPVOID lpParam) 
{
	TThreadData* pTDat = (TThreadData*)lpParam;
	//uint8_T* TSinglePart = pTDat->TSinglePart;
	uint8_T* Tvec = pTDat->Tvec;
	uint32_T* BoundBox = pTDat->BoundBox;
	const uint32_T d = pTDat->d;
	//uint8_T* RSinglePart = pTDat->RSinglePart;
	uint8_T* Rvec = pTDat->Rvec;
	uint32_T* b_DSPResponsibilityBox = pTDat->b_DSPResponsibilityBox;
	uint32_T b_i = pTDat->b_i;
	CHPRPCRequestStoreImg* pRequest = pTDat->pRequest;

	//Extract partial image (places the extracted lines into the HPRPC command buffer. In case of a PCIe transfer directly to the buffers of the non-paged kernel memory used for DMA.)
	CBufferedWriter& BufferedWriter=pRequest->GetHPRPCConnection().GetBufferedWriter();
	extract(Tvec, BoundBox, d, BufferedWriter);
	//Note: We could initiate the sending and start the pyramid generation here allready.
	extract(Rvec, b_DSPResponsibilityBox, d, BufferedWriter);

	//record duration
	pTDat->ExtractFinishedWCTime = get_wall_time();
	pTDat->ExtractFinishedCPUTime = get_cpu_time();
	g_lastImageExtractor = pTDat;	//last thread wins

    //Start sending the data buffer to the target DSP (async, header and image data)
	matlab_c_sendToTarget(b_i, pRequest);

	//Remember completion time (for performance analysis)
	pTDat->SndStartdWCTime = get_wall_time();
	pTDat->SndStartdCPUTime = get_cpu_time();
	g_lastPCIeSender = pTDat;	//last thread wins
	
	return 0;
}
Esempio n. 3
0
PhysicsEngine::PhysicsEngine(int ballsPerSecond, float minimumY, float ballRadius) {
	kMinimumY = minimumY;
	kMsBetweenBalls = 1.f / ballsPerSecond * 1000.f;
	kLastUpdate = get_wall_time();
	kLastBall = get_wall_time();
	kBallRadius = ballRadius;
}
void get_properties(const std::string &filename,
                    std::map<int, std::vector<double> > &properties)
{
  std::cout << "Getting properties..." << std::endl;
  double t_begin = get_wall_time();

  std::ifstream in(filename.c_str());
  require(in, "File " + filename + " can't be opened");

  int materialID;
  std::vector<double> values;
  int n_values = 0; // default value

  std::string line;

  while (getline(in, line)) // read the file line-by-line
  {
    // if the line is empty or starts with '#' (a comment), we skip it
    if (line.empty() || line[0] == '#') continue;

    values.clear();
    if (n_values == 0) // first run
      values.reserve(10); // we don't expect more than 10 parameters by default
    else
      values.reserve(n_values);

    std::istringstream instr(line);
    instr >> materialID;
    double val;
    while (instr >> val)
      values.push_back(val);

    if (n_values == 0)
      n_values = values.size();
    else
      require(n_values == (int)values.size(), "The number of parameters in the "
              "first appearance was " + d2s(n_values) + ", but in some line "
              "there are " + d2s(values.size()) + " of them");

    // insert the vector into the map
    std::pair<std::map<int, std::vector<double> >::const_iterator, bool> res =
        properties.insert(std::pair<int, std::vector<double> >(materialID, values));

    // check that the insertion was successfull
    require(res.second, "Insertion of the values for the material with ID =" +
            d2s(materialID) + " failed. Check the data (file = " + filename +
            ")");
  }

  in.close();

  std::cout << "Getting properties is done. Time = "
            << get_wall_time() - t_begin << std::endl;
}
Esempio n. 5
0
void Run(std::string iArgument1, std::string iArgument2)
{
  if (iArgument2=="GeneralStats")
    GeneralStats(iArgument1);
  else if (iArgument2=="")
  {
    std::string Instance = iArgument1;
    int PopSize = 16;
    int MaxHamming = 3;
    int RCLLength = 3;
    double MutationRate = 0.1;
    double TransmitionRate = 0.2;
    int MaxNbGenerations = 200;
    double InfMeanDiff = 0.002;
    Traces ExecTraces;
    ExecTraces.Initialize(PopSize, MaxNbGenerations);
  
    GRASP myGRASP(Instance, PopSize, MaxHamming, RCLLength, MutationRate, TransmitionRate, MaxNbGenerations, InfMeanDiff, &ExecTraces);
    ExecTraces._BeginPopBuilt_UserTime = get_wall_time();
    ExecTraces._BeginPopBuilt_CPUTime = get_cpu_time();
    myGRASP.Construction();
    ExecTraces._EndPopBuilt_CPUTime = get_cpu_time();
    ExecTraces._EndPopBuilt_UserTime = get_wall_time();

    Localisation * TmpBestLoc = myGRASP.GetBestLocalisation();
    if (TmpBestLoc)
      ExecTraces._GRASPBestCost = TmpBestLoc->GetLocalisationCost();

    ExecTraces._BeginGenetic_UserTime = get_wall_time();
    ExecTraces._BeginGenetic_CPUTime = get_cpu_time();
    myGRASP.GeneticAlgorithm();
    ExecTraces._EndGenetic_CPUTime = get_cpu_time();
    ExecTraces._EndGenetic_UserTime = get_wall_time();

    TmpBestLoc = myGRASP.GetBestLocalisation();
    if (TmpBestLoc)
      ExecTraces._GeneticBestCost = TmpBestLoc->GetLocalisationCost();

    std::cout << "===== Parameters\n";
    std::cout << "Size of the population: " << PopSize << "\n";
    std::cout << "Maximal Hamming Distance: " << MaxHamming << "\n";
    std::cout << "Length of RCl (restricted candidates list): " << RCLLength << "\n";
    std::cout << "Mutation rate: " << MutationRate << "\n";
    std::cout << "Transmition rate: " << TransmitionRate << "\n";
    std::cout << "Maximal number of generation in genetic algorithm: " << MaxNbGenerations << "\n";
    std::cout << "Mean difference of the costs of the population from which stop: " << InfMeanDiff << "\n";
    std::cout << "\n";
    std::cout << "===== Result of the metaheuristic\n";
    myGRASP.PrintBestLocalisation();
    ExecTraces.PostTreatment();

    TmpBestLoc = 0;
  }
}
void makeSelectionTrees_small(void)
{

  // TChain *tth_chain = loadFiles("ttH");  
  // run_it(tth_chain,"ttH_lepTopBDTResults.root");

  double totStart = get_wall_time();
  TString output_file = "skimSelection.root";
  TChain *chain = new TChain("OSTwoLepAna/summaryTree");
  //chain->Add("/tmpscratch/users/mlink2/rootFiles/charlie_tree_11503.root");
/*
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/tth_nonbb/charlie_tree_11503.root");
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/tth_nonbb/charlie_tree_21176.root");

  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/tth_nonbb/charlie_tree_30640.root");
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/ttjets_semilep/charlie_tree_10640.root");
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/ttjets_semilep/charlie_tree_11504.root");
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/ttjets_semilep/charlie_tree_12183.root");
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/ttjets_semilep/charlie_tree_13130.root");
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/ttjets_semilep/charlie_tree_13381.root");
*/

  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/ttjets_semilep/charlie_tree_10640.root");
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/ttjets_semilep/charlie_tree_11504.root");
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/ttjets_semilep/charlie_tree_12183.root");
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/ttjets_semilep/charlie_tree_13130.root");
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/ttjets_semilep/charlie_tree_13381.root");
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/ttjets_semilep/charlie_tree_14553.root");
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/ttjets_semilep/charlie_tree_15205.root");
  chain->Add("/hadoop/store/user/lannon/bdtreco_v0/ttjets_semilep/charlie_tree_16058.root");

/*
  std::ifstream infile("files_forSelection_ttjet.txt");
  TString line;
  while (infile >> line ){
     chain->Add(line );
     cout << line << endl;
  }
*/
  double chainTime = get_wall_time() - totStart;
  run_it(chain,output_file);
  double totEnd = get_wall_time();
  double totalTime = totEnd - totStart;

  cout << "total time: " << totalTime << endl;
  cout << "chain time: " << chainTime << endl; 



  // TChain *ttw_chain = loadFiles("ttW");
  // TChain *ttbar_chain = loadFiles("ttbar");

}
Esempio n. 7
0
int main(int argc, char *argv[])
{
	int size, rank;
	int i, j;

	MPI_Init(&argc, &argv);
	MPI_Comm_size(MPI_COMM_WORLD, &size);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);

	double start=get_wall_time();

	int N=5;
	int hist_size=25;

	int **global_image=allocate_2d_matrix(N,N);
	int *local_histogram=calloc(hist_size,sizeof(int));
	int *histogram=calloc(hist_size,sizeof(int));

	int counter=0;

	for(i=rank; i<N; i=i+size)
		for(j=0; j<N; j++)
			global_image[i][j]=i*N+j;

	MPI_Barrier(MPI_COMM_WORLD);

	for(i=rank; i<N; i=i+size)
		for(j=0; j<N; j++)
			local_histogram[global_image[i][j]]++;

	MPI_Barrier(MPI_COMM_WORLD);

    	MPI_Reduce(local_histogram, histogram, hist_size, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);

	MPI_Barrier(MPI_COMM_WORLD);

	if(rank==0)
		for(i=0;i<hist_size;i++)
			printf("%d. %d\n",i+1,histogram[i]);

        free(global_image);
	free(local_histogram);
	free(histogram);

	double end=get_wall_time();

	//printf("\nElapsed time: %f\n",(end-start));

	MPI_Finalize();
	return 0;
}
void RectangularMesh::
write_binary_files_in_cells(const std::string &prop_filename,
                            std::vector<std::string> &filenames_out) const
{
  std::cout << "Writing binary files in cells..." << std::endl;
  double t_begin = get_wall_time();

  // Create the map between the material IDs and the media properties. The
  // material IDs must exactly the same as in the given triangular mesh.
  std::map<int, std::vector<double> > properties;

  get_properties(prop_filename, properties);

  const int n_properties = properties.begin()->second.size();

  filenames_out.resize(n_properties);

  std::ofstream *out = new std::ofstream[n_properties];
  for (int i = 0; i < n_properties; ++i)
  {
    filenames_out[i] = "property" + d2s(i) + "_cells.bin";
    out[i].open(filenames_out[i].c_str(), std::ios::binary);
    require(out[i], "File '" + filenames_out[i] + "' can't be opened");
  }

  for (int i = 0; i < _n_elements_x*_n_elements_z; ++i)
  {
    const int matID = _cells_ID[i];
    std::map<int, std::vector<double> >::const_iterator iter =
        properties.find(matID);
    require(iter != properties.end(), "The material ID " + d2s(matID) +
            " wasn't found in the properties file");
    const std::vector<double> values = iter->second;

    for (int p = 0; p < n_properties; ++p)
    {
      OUT_FLOAT_TYPE val = values[p];
      out[p].write(reinterpret_cast<char*>(&val), sizeof(OUT_FLOAT_TYPE));
    }
  }

  for (int i = 0; i < n_properties; ++i)
    out[i].close();

  delete[] out;

  std::cout << "Writing binary files in cells is done. Time = "
            << get_wall_time() - t_begin << std::endl;
}
void RectangularMesh::
assign_material_id_at_nodes(const TriangularMesh &tri_mesh)
{
  double t0 = get_wall_time();
  std::cout << "Assigning material IDs at nodes..." << std::endl;

  _verts_ID = new int[(_n_elements_x+1)*(_n_elements_z+1)];

  const double x0 = _min_coord.x(); // limits in x-direction
  const double x1 = _max_coord.x();
  const double z0 = _min_coord.z(); // limits in z-direction
  const double z1 = _max_coord.z();
  const double hx = (x1 - x0) / _n_elements_x; // step in x-direction
  const double hz = (z1 - z0) / _n_elements_z; // step in z-direction

  const bool throw_exception = false;

  for (int iz = 0; iz < _n_elements_z+1; ++iz)
  {
    const double z = (iz == _n_elements_z ? z1 : z0 + iz*hz);
    int triangle_index = 0; // reset the index from the previous search
    for (int ix = 0; ix < _n_elements_x+1; ++ix)
    {
      const double x = (ix == _n_elements_x ? x1 : x0 + ix*hx);
      Point2 vertex(x, z);
      require(tri_mesh.contains_point(vertex), "The triangular mesh doesn't "
              "contain the point: " + d2s(vertex));

      // every search along the x-line at the same z-coordinate starts with the
      // previously found triangle
      triangle_index = tri_mesh.find_element(vertex,
                                             triangle_index,
                                             throw_exception);

      if (triangle_index < 0) // if it wasn't found
      {
        std::cout << "  full search for point " << vertex << std::endl;
        triangle_index = tri_mesh.full_search(vertex);
      }

      const int mat_ID = tri_mesh.element(triangle_index).material_id();
      _verts_ID[iz*(_n_elements_x+1)+ix] = mat_ID;
    }
  }

  std::cout << "Assigning material IDs at nodes is done. Time = "
            << get_wall_time() - t0 << std::endl;
}
Esempio n. 10
0
void RectangularMesh::
assign_material_id_in_cells(const TriangularMesh &tri_mesh)
{
  double t0 = get_wall_time();
  std::cout << "Assigning material IDs in cells..." << std::endl;

  _cells_ID = new int[_n_elements_x*_n_elements_z];

  const double x0 = _min_coord.x(); // limits in x-direction
  const double x1 = _max_coord.x();
  const double z0 = _min_coord.z(); // limits in z-direction
  const double z1 = _max_coord.z();
  const double hx = (x1 - x0) / _n_elements_x; // step in x-direction
  const double hz = (z1 - z0) / _n_elements_z; // step in z-direction

  const bool throw_exception = false;

  for (int iz = 0; iz < _n_elements_z; ++iz)
  {
    const double zcen = z0 + (iz+0.5)*hz; // z-coord of a cell center
    int triangle_index = 0; // reset the index from the previous search
    for (int ix = 0; ix < _n_elements_x; ++ix)
    {
      const double xcen = x0 + (ix+0.5)*hx; // x-coord of a cell center
      Point2 cell_center(xcen, zcen);
      require(tri_mesh.contains_point(cell_center), "The triangular mesh "
              "doesn't contain the point: " + d2s(cell_center));

      // every search along the x-line at the same z-coordinate starts with the
      // previously found triangle
      triangle_index = tri_mesh.find_element(cell_center,
                                             triangle_index,
                                             throw_exception);

      if (triangle_index < 0) // if it wasn't found
      {
        std::cout << "  full search for point " << cell_center << std::endl;
        triangle_index = tri_mesh.full_search(cell_center);
      }

      const int mat_ID = tri_mesh.element(triangle_index).material_id();
      _cells_ID[iz*_n_elements_x + ix] = mat_ID;
    }
  }

  std::cout << "Assigning material IDs in cells is done. Time = "
            << get_wall_time() - t0 << std::endl;
}
Esempio n. 11
0
void start_server_discovery()
{
	if(server_discovery_started)
		return;
	
	selected_server = -1;
	top_server_visible = 0;
	
	num_servers_unqueried = 0;
	num_servers_queried = 0;
	num_servers_found = 0;
	num_servers_new_proto = 0;
	
	struct server_t *cserver = rumoured_servers;
	
	while(cserver)
	{
		num_servers_unqueried++;
		LL_ADD_TAIL(struct server_t, &unqueried_servers, cserver);
		LL_NEXT(cserver);
	}
	
	pipe(servers_info_pipe);

	output_server_query();
	servers_first_output = get_wall_time();
	servers_next_output = 1.0 / SERVER_QUERY_OUTPUT_RATE + servers_first_output;

	pipe(servers_kill_pipe);
	pthread_create(&servers_thread_id, NULL, servers_thread, NULL);

	server_discovery_started = 1;
}
Esempio n. 12
0
double Clock::timeElapsed() {
	if (_started)
		return _elapsed + get_wall_time() - _last;
	else
		return _elapsed;

}
Esempio n. 13
0
void process_server_info(struct sockaddr_in *sockaddr, struct buffer_t *buffer)
{
	struct queried_server_t *cserver = queried_servers;
	struct found_server_t new_server_info;
	uint16_t servers;
	struct sockaddr_in s;
	time_t t;
	int proto_ver;
		
	while(cserver)
	{
		if(cserver->ip == sockaddr->sin_addr.s_addr && 
			cserver->port == sockaddr->sin_port)
		{
			proto_ver = buffer_read_uint8(buffer);
			if(proto_ver != EM_PROTO_VER)
			{
				if(proto_ver > EM_PROTO_VER)
					num_servers_new_proto++;
				
				break;
			}
			
			new_server_info.ip = sockaddr->sin_addr.s_addr;
			new_server_info.port = sockaddr->sin_port;
			new_server_info.ping = get_wall_time() - cserver->stamp;

			new_server_info.host_name = buffer_read_string(buffer);
			new_server_info.map_name = buffer_read_string(buffer);
			new_server_info.num_players = buffer_read_uint8(buffer);
			new_server_info.max_players = buffer_read_uint8(buffer);
			new_server_info.authenticating = buffer_read_uint8(buffer);
		
			add_new_found_server(&new_server_info);
				
			
			add_new_server(&rumoured_servers, sockaddr, time(NULL));
				
			
			servers = buffer_read_uint16(buffer);
			
			while(servers--)
			{
				s.sin_addr.s_addr = buffer_read_uint32(buffer);
				s.sin_port = buffer_read_uint16(buffer);
				t = buffer_read_uint32(buffer);
				
				if(!find_queried_server(s.sin_addr.s_addr, s.sin_port))
				{
					if(add_new_server(&unqueried_servers, &s, t))
						num_servers_unqueried++;
				}
			}
			
			break;
		}
			
		LL_NEXT(cserver);
	}			
}
Esempio n. 14
0
std::vector<PhysicsBall> PhysicsEngine::update(glm::vec3 desiredDropOrigin, std::vector<PhysicsInteractor> hands) {
	std::vector<PhysicsBall> balls;
	float secElapsed = get_wall_time() - kLastUpdate;
	kLastUpdate = get_wall_time();

	//create balls if its been too long
	if (((get_wall_time() - kLastBall) * 1000.f) > kMsBetweenBalls) {
		kLastBall = get_wall_time();
		kBalls.push(PhysicsBall(desiredDropOrigin, glm::vec3(0, -0.01, 0), kBallRadius));
	}

	//run physics for all balls
	for (unsigned int i = 0; i < kBalls.size(); i++) {
		PhysicsBall curBall = kBalls.front();
		bool keepBall = true;
		kBalls.pop();

		//Don't calculate ball if it has dropped out of frame
		if (curBall.position.y < kMinimumY)
			continue;

		//Calc ball movement
		curBall.position += curBall.velocity * secElapsed;
		curBall.velocity += glm::vec3(0, -9.8 * secElapsed, 0);

		//Handle hand interaction
		for (unsigned int j = 0; j < hands.size(); j++) {
			if (glm::distance(curBall.position, hands[j].position) < curBall.radius + hands[j].radius) {
				if (hands[j].bounce) {
					//ball is bounced, recalc velocity and add
					glm::vec3 newDirection = glm::normalize(curBall.position - hands[j].position);
					curBall.velocity = newDirection * glm::length(curBall.velocity);
				} else {
					keepBall = false;
					break;
				}
			}
		}
		if (keepBall) {
			kBalls.push(curBall);
			balls.push_back(curBall);
		}
	}

	return balls;
}
Esempio n. 15
0
void RectangularMesh::
write_ASCII_files_at_nodes(const std::string &prop_filename) const
{
  std::cout << "Writing ASCII files at nodes..." << std::endl;
  double t_begin = get_wall_time();

  // Create the map between the material IDs and the media properties. The
  // material IDs must exactly the same as in the given triangular mesh.
  std::map<int, std::vector<double> > properties;

  get_properties(prop_filename, properties);

  const int n_properties = properties.begin()->second.size();

  std::vector<std::string> filenames_out(n_properties);

  std::ofstream *out = new std::ofstream[n_properties];
  for (int i = 0; i < n_properties; ++i)
  {
    filenames_out[i] = "property" + d2s(i) + "_nodes.txt";
    out[i].open(filenames_out[i].c_str(), std::ios::binary);
    require(out[i], "File '" + filenames_out[i] + "' can't be opened");
  }

  for (int i = 0; i < (_n_elements_x+1)*(_n_elements_z+1); ++i)
  {
    const int matID = _verts_ID[i];
    std::map<int, std::vector<double> >::const_iterator iter =
        properties.find(matID);
    require(iter != properties.end(), "The material ID " + d2s(matID) +
            " wasn't found in the properties file");
    const std::vector<double> values = iter->second;

    for (int p = 0; p < n_properties; ++p)
      out[p] << values[p] << "\n";
  }

  for (int i = 0; i < n_properties; ++i)
    out[i].close();

  delete[] out;

  std::cout << "Writing ASCII files at nodes is done. Time = "
            << get_wall_time() - t_begin << std::endl;
}
Esempio n. 16
0
void init_control()
{
	double time = get_wall_time();
	next_control_tick = ((int)(time / CONTROL_TICK_INTERVAL) + 1) * (double)CONTROL_TICK_INTERVAL;
	
	create_alarm_listener(process_control_alarm);
	pipe(control_kill_pipe);
	pthread_create(&control_thread_id, NULL, control_thread, NULL);
}
Esempio n. 17
0
void test_performance(bvgraph g, int test_num)
{
    //randomly generate test case
    int64_t i = 0;
    uint64_t d;
    srand(time(NULL));
    double start, end;
    bvgraph_random_iterator ri;
    int rval = bvgraph_random_access_iterator(&g, &ri);

    if (rval){
        printf ("Random access iterator allocation failed. Stop.\n");
        return;
    }

    int64_t node = 0;
    int64_t *links = NULL;
    int64_t edge_count = 0;
 
    start = get_wall_time();
    for (i = 0; i < test_num; i++) {
        node = rand() % g.n;
        bvgraph_random_outdegree(&ri, node, &d);
        bvgraph_random_successors(&ri, node, &links, &d);
        int64_t j = 0;
        int64_t link;
        for (j=0; j<d; j++){
            link = links[j];
        }
        edge_count += d;

        //printf ("node %d has degree %d\n", node, d);
    }
    end = get_wall_time();
    double dif = ((double)end - (double)start);
    double edge_per_sec = edge_count / dif;

    printf("Used %.2lf secs. Edges = %"PRId64". Edges per second = %.2lf\n", dif, edge_count, edge_per_sec);

    bvgraph_random_free(&ri);

}
Esempio n. 18
0
int main(void) {

  double pi = 0.0f;
  long long i;
  double time_begin=get_wall_time();
  
  double t = 0;
  #pragma acc parallel loop private(t)
  for (i=0; i<N; i++) {
    t= (double)((i+0.5)/N);
    pi +=4.0/(1.0+t*t);
  }

  double time_end=get_wall_time();
  printf("pi=%11.10f\n",pi/N);
  printf("Total elapsed time is: %.4lf\n", (time_end - time_begin));

  return 0;

}
Esempio n. 19
0
void servers_alarm()
{
	if(!server_discovery_started)
		return;
	
	float time = get_wall_time();
	
	if(time >= servers_next_output)
	{
		pthread_mutex_lock(&servers_mutex);
		output_server_query();
		pthread_mutex_unlock(&servers_mutex);
	
		servers_next_output = (floor((time - servers_first_output) * 
			SERVER_QUERY_OUTPUT_RATE) + 1.0) / SERVER_QUERY_OUTPUT_RATE + servers_first_output;
	}
}
Esempio n. 20
0
void process_control_alarm()
{
	double time = get_wall_time();
		
	if(time > next_control_tick)
	{
		pthread_mutex_lock(&control_mutex);
		
		if(game_state == GAMESTATE_PLAYING)
		{
			pthread_mutex_lock(&control_mutex);
			
			if(roll_changed)
			{
				net_emit_uint8(game_conn, EMMSG_ROLL);
				net_emit_float(game_conn, roll);
				net_emit_end_of_stream(game_conn);
				roll_changed = 0;
				roll = 0.0;
			}
		
			if(rolling_left)
			{
				net_emit_uint8(game_conn, EMMSG_ROLL);
				net_emit_float(game_conn, -0.2);
				net_emit_end_of_stream(game_conn);
			}
			
			if(rolling_right)
			{
				net_emit_uint8(game_conn, EMMSG_ROLL);
				net_emit_float(game_conn, 0.2);
				net_emit_end_of_stream(game_conn);
			}
			
			pthread_mutex_unlock(&control_mutex);
		}
		
		next_control_tick = ((int)(time / CONTROL_TICK_INTERVAL) + 1) * 
			(double)CONTROL_TICK_INTERVAL;
		
		pthread_mutex_unlock(&control_mutex);
	}
}
Esempio n. 21
0
void output_server_query()
{
	struct sockaddr_in sockaddr;
	struct queried_server_t queried_server;	
	
	if(unqueried_servers)
	{
		sockaddr.sin_family = AF_INET;
		sockaddr.sin_addr.s_addr = unqueried_servers->ip;
		sockaddr.sin_port = unqueried_servers->port;
			
		net_emit_server_info(&sockaddr, NULL, 0);
		
		queried_server.ip = unqueried_servers->ip;
		queried_server.port = unqueried_servers->port;
		queried_server.stamp = get_wall_time();
		
		LL_ADD(struct queried_server_t, &queried_servers, &queried_server);
		LL_REMOVE(struct server_t, &unqueried_servers, unqueried_servers);
		
		num_servers_unqueried--;
		num_servers_queried++;
	}
}
void TypicalTimeOfLocalisationBuilt(std::string iInstance)
{
  // Creation of the instance
  Testio Instance(iInstance);

  // Time needed to build the localisation
  double ConstructionUserTime =  0;
  double ConstructionCPUTime = 0;
  // Time to explore a neighbourhood for Hamming distance equal to 1
  double Exploration1UserTime = 0;
  double Exploration1CPUTime = 0;
  // Time to explore a neighbourhood for Hamming distance equal to 2
  double Exploration2UserTime = 0;
  double Exploration2CPUTime = 0;
  // Time to explore a neighbourhood for Hamming distance equal to 3
  double Exploration3UserTime = 0;
  double Exploration3CPUTime = 0;
  // Time to execute a complete local search
  double LocalSearchUserTime = 0;
  double LocalSearchCPUTime = 0;


  int NbIter = 10;
  int i;
  for (i = 0; i < NbIter; i++)
  {
    Localisation myLoc(Instance, 0, 0);

    // Construction of the localisation
    double BeginUserTime =  get_wall_time();
    double BeginCPUTime = get_cpu_time();
    myLoc.Construction(3);
    double EndCPUTime = get_cpu_time();
    double EndUserTime =  get_wall_time();
    ConstructionUserTime = ConstructionUserTime + EndUserTime - BeginUserTime;
    ConstructionCPUTime = ConstructionCPUTime + EndCPUTime - BeginCPUTime;

    // Exploration of a neighbourhood for Hamming distance equal to 1
    BeginUserTime =  get_wall_time();
    BeginCPUTime = get_cpu_time();
    myLoc.NeighbourhoodSearch(1);
    EndCPUTime = get_cpu_time();
    EndUserTime =  get_wall_time();
    Exploration1UserTime = Exploration1UserTime + EndUserTime - BeginUserTime;
    Exploration1CPUTime = Exploration1CPUTime + EndCPUTime - BeginCPUTime;

    // Exploration of a neighbourhood for Hamming distance equal to 1
    BeginUserTime =  get_wall_time();
    BeginCPUTime = get_cpu_time();
    myLoc.NeighbourhoodSearch(2);
    EndCPUTime = get_cpu_time();
    EndUserTime =  get_wall_time();
    Exploration2UserTime = Exploration2UserTime + EndUserTime - BeginUserTime;
    Exploration2CPUTime = Exploration2CPUTime + EndCPUTime - BeginCPUTime;

    // Exploration of a neighbourhood for Hamming distance equal to 1
    BeginUserTime =  get_wall_time();
    BeginCPUTime = get_cpu_time();
    myLoc.NeighbourhoodSearch(3);
    EndCPUTime = get_cpu_time();
    EndUserTime =  get_wall_time();
    Exploration3UserTime = Exploration3UserTime + EndUserTime - BeginUserTime;
    Exploration3CPUTime = Exploration3CPUTime + EndCPUTime - BeginCPUTime;
  }
  int NbLocalSearch = 5;
  for (i = 0; i < NbLocalSearch; i++)
  {
    Localisation myLoc(Instance, 0, 0);

    // Construction of the localisation
    myLoc.Construction(3);

    // Computation of a complete local search
    double BeginUserTime =  get_wall_time();
    double BeginCPUTime = get_cpu_time();
    myLoc.LocalSearchAlgorithm(3);
    double EndCPUTime = get_cpu_time();
    double EndUserTime =  get_wall_time();
    LocalSearchUserTime = LocalSearchUserTime + EndUserTime - BeginUserTime;
    LocalSearchCPUTime = LocalSearchCPUTime + EndCPUTime - BeginCPUTime;
  }

  std::cout.precision(4);
  std::cout << "Time needed to build the localisation\n";
  std::cout << "  CPU time : " << ConstructionCPUTime/NbIter << "s\n";
  std::cout << "  User time: " << ConstructionUserTime/NbIter << "s\n";
  std::cout << "Time to explore a neighbourhood for Hamming distance equal to 1\n";
  std::cout << "  CPU time : " << Exploration1CPUTime/NbIter << "s\n";
  std::cout << "  User time: " << Exploration1UserTime/NbIter << "s\n";
  std::cout << "Time to explore a neighbourhood for Hamming distance equal to 2\n";
  std::cout << "  CPU time : " << Exploration2CPUTime/NbIter << "s\n";
  std::cout << "  User time: " << Exploration2UserTime/NbIter << "s\n";
  std::cout << "Time to explore a neighbourhood for Hamming distance equal to 3\n";
  std::cout << "  CPU time : " << Exploration3CPUTime/NbIter << "s\n";
  std::cout << "  User time: " << Exploration3UserTime/NbIter << "s\n";
  std::cout << "Time to execute a complete local search\n";
  std::cout << "  CPU time : " << LocalSearchCPUTime/NbLocalSearch << "s\n";
  std::cout << "  User time: " << LocalSearchUserTime/NbLocalSearch << "s\n";
  std::cout << "\n";
}
void NonOptimalSolutions(std::string iInstance)
{
  // Optimal values of the instances
  static struct {
    const std::string _TestName;
    double _OptimalValue;
  } aInstance[] = {
    // Test name                    Optimal value
    {"TestCases/Input/cap71.txt",    932615.75   },
    {"TestCases/Input/cap72.txt",    977799.4    },
    {"TestCases/Input/cap73.txt",   1010641.45   },
    {"TestCases/Input/cap74.txt",   1034976.975  },
    {"TestCases/Input/cap101.txt",   796648.4375 },
    {"TestCases/Input/cap102.txt",   854704.2    },
    {"TestCases/Input/cap103.txt",   893782.1125 },
    {"TestCases/Input/cap104.txt",   928941.75   },
    {"TestCases/Input/cap131.txt",   793439.5625 },
    {"TestCases/Input/cap132.txt",   851495.325  },
    {"TestCases/Input/cap133.txt",   893076.7125 },
    {"TestCases/Input/cap134.txt",   928941.75   },
    {"TestCases/Input/capa.txt",   17156454.4783 },
    {"TestCases/Input/capb.txt",   12979071.58143},
    {"TestCases/Input/capc.txt",   11505594.32878}
  };
  int IdxTest;
  for (IdxTest = 0; IdxTest < 15; IdxTest++) {
    if (aInstance[IdxTest]._TestName == iInstance)
      break;
  }
  if (IdxTest==15) {
    std::cout << "The optimal value of the problem is unknown. Fill code with it!\n";
    return;
  }

  int NbTest = 100;
  // Array of the found optimal costs
  double * aOptimalCosts = new double[NbTest];
  memset(aOptimalCosts, 0, NbTest*sizeof(double));

  // Time to perform algorithm
  double UserTime = 0;
  double CPUTime = 0;


  // Parameters of the algorithm
  std::string Instance = iInstance;
  int PopSize = 16;
  int MaxHamming = 3;
  int RCLLength = 3;
  double MutationRate = 0.1;
  double TransmitionRate = 0.2;
  int MaxNbGenerations = 200;
  double InfMeanDiff = 0.002;

  int i;
  for (i = 0; i < NbTest; i++)
  {
    GRASP myGRASP(Instance, PopSize, MaxHamming, RCLLength, MutationRate, TransmitionRate, MaxNbGenerations, InfMeanDiff, 0);
    double BeginUserTime =  get_wall_time();
    double BeginCPUTime = get_cpu_time();
    myGRASP.Construction();
    myGRASP.GeneticAlgorithm();
    double EndCPUTime = get_cpu_time();
    double EndUserTime =  get_wall_time();
    Localisation * BestLoc = myGRASP.GetBestLocalisation();
    if (BestLoc)
      aOptimalCosts[i] = BestLoc->GetLocalisationCost();

    UserTime = UserTime + EndUserTime - BeginUserTime;
    CPUTime = CPUTime + EndCPUTime - BeginCPUTime;
  }

  int NbNonOptimal = 0;
  double MeanDiff = 0;
  for (i = 0; i < NbTest; i++) {
    double diff = fabs(aOptimalCosts[i]-aInstance[IdxTest]._OptimalValue);
    if ( diff > EPSILON )
    {
      NbNonOptimal++;
      MeanDiff+=diff;
    }
  }

  std::cout.precision(3);
  std::cout << "Percentage of returned non-optimal solutions: " << NbNonOptimal*100./NbTest << "%\n";
  std::cout.precision(4);
  if (NbNonOptimal > 0)
    MeanDiff = 100 * MeanDiff / (NbNonOptimal*aInstance[IdxTest]._OptimalValue);
  std::cout << "Averge mean difference of non-optimal solutions with optimum: " << MeanDiff << "%\n";
  std::cout << "\n";

  std::cout.precision(4);
  std::cout << "Average time to perform GRASP algorithm:\n";
  std::cout << "  CPU time : " << CPUTime/NbTest << "s\n";
  std::cout << "  User time: " << UserTime/NbTest << "s\n";
  std::cout << "\n";

  if (aOptimalCosts)
    delete [] aOptimalCosts; aOptimalCosts = 0;
}
int main(int argc, char *argv[])

{

   int i,j,ii,jj,i_tile,j_tile;

   const int N=100000;
   double sumC_n, sumC_t;

   double *A = malloc(sizeof(double)*N*N); 
   double *b = malloc(sizeof(double)*N);
   double *c_naive = malloc(sizeof(double)*N);
   double *c_tile=malloc(sizeof(double)*N);

   sumC_n = 0.0;
   sumC_t = 0.0;

   j_tile = 10000;
   i_tile = 10000;

   for (i=0; i<N; i++){
     for (j=0; j<N; j++){
        A[i*N+j] = (i+1)*N+j+1;
     }
   }

   for (i=0; i<N; i++){
       b[i]       = (i+1)^2;
       c_naive[i] = 0.0;
       c_tile[i]  = 0.0;
   }


   double start_n=get_wall_time();
   for(i=0; i<N; i++){
     for(j=0; j<N; j++){
        c_naive[i] += A[i*N+j]*b[j];
     }
   }   
   double finish_n=get_wall_time();

   double start=get_wall_time();  
   //#pragma omp for private(i,j,ii,jj) shared(A,b,c,i_tile,j_tile) num_threads(4)
     for(jj=0; jj<N; jj+=j_tile){
       for(i=0; i<N; i++){
        for(j=jj; j<jj+j_tile; j++){
               c_tile[i] += A[i*N+j]*b[j];
        }
      }
     }
   double finish=get_wall_time();

  for(i=0;i<N;i++){
 
     sumC_n = sumC_n + c_naive[i];
     sumC_t = sumC_t + c_tile[i];

  }

  free(A);
  free(b);
  free(c_naive);
  free(c_tile);

  printf("Naive Time: %f seconds and SUM: %f\n",finish_n-start_n,sumC_n);
  printf("Tiled Time: %f seconds and SUM: %f\n",finish-start,sumC_t);
  
  return 0;

}
Esempio n. 25
0
void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, image *labels, int classes, int frame_skip)
{
	detection_layer l;
    //skip = frame_skip;
    int delay = frame_skip;
    demo_names = names;
    demo_labels = labels;
    demo_classes = classes;
    demo_thresh = thresh;
    printf("Demo\n");
    net = parse_network_cfg(cfgfile);
    if(weightfile){
        load_weights(&net, weightfile);
    }
    set_batch_network(&net, 1);

    srand(2222222);

    if(filename){
        cap = cvCaptureFromFile(filename);
    }else{
        cap = cvCaptureFromCAM(cam_index);
    }

    if(!cap) error("Couldn't connect to webcam.\n");

    l = net.layers[net.n-1];
    int j;

    avg = (float *) calloc(l.outputs, sizeof(float));
    for(j = 0; j < FRAMES; ++j) predictions[j] = (float *) calloc(l.outputs, sizeof(float));
    for(j = 0; j < FRAMES; ++j) images[j] = make_image(1,1,3);

    boxes = (box *)calloc(l.side*l.side*l.n, sizeof(box));
    probs = (float **)calloc(l.side*l.side*l.n, sizeof(float *));
    for(j = 0; j < l.side*l.side*l.n; ++j) probs[j] = (float *)calloc(l.classes, sizeof(float *));

    pthread_t fetch_thread;
    pthread_t detect_thread;

    fetch_in_thread(0);
    det = in;
    det_s = in_s;

    fetch_in_thread(0);
    detect_in_thread(0);
    disp = det;
    det = in;
    det_s = in_s;

    for(j = 0; j < FRAMES/2; ++j){
        fetch_in_thread(0);
        detect_in_thread(0);
        disp = det;
        det = in;
        det_s = in_s;
    }

    int count = 0;
    cvNamedWindow("Demo", CV_WINDOW_AUTOSIZE); 
    cvMoveWindow("Demo", 0, 0);
    cvResizeWindow("Demo", 1352, 1013);

    double before = get_wall_time();

    while(1){
        ++count;
        if(1){
            if(pthread_create(&fetch_thread, 0, fetch_in_thread, 0)) error("Thread creation failed");
            if(pthread_create(&detect_thread, 0, detect_in_thread, 0)) error("Thread creation failed");

            show_image(disp, "Demo");
            int c = cvWaitKey(1);
            if (c == 10){
                if(frame_skip == 0) frame_skip = 60;
                else if(frame_skip == 4) frame_skip = 0;
                else if(frame_skip == 60) frame_skip = 4;   
                else frame_skip = 0;
            }

            pthread_join(fetch_thread, 0);
            pthread_join(detect_thread, 0);

            if(delay == 0){
                free_image(disp);
                disp  = det;
            }
            det   = in;
            det_s = in_s;
        }else {
            fetch_in_thread(0);
            det   = in;
            det_s = in_s;
            detect_in_thread(0);
            if(delay == 0) {
                free_image(disp);
                disp = det;
            }
            show_image(disp, "Demo");
            cvWaitKey(1);
        }
        --delay;
        if(delay < 0){
            delay = frame_skip;

            double after = get_wall_time();
            float curr = 1./(after - before);
            fps = curr;
            before = after;
        }
    }
}
Esempio n. 26
0
bool
prb_stopwatch_start(prb_stopwatch_t* sw, int op)
{
    sw->start_times[op] = get_wall_time();
}
Esempio n. 27
0
bool
prb_stopwatch_stop(prb_stopwatch_t* sw, int op)
{
    sw->stop_times[op] = get_wall_time();
    sw->durations[op] = sw->stop_times[op] - sw->start_times[op];
}
Esempio n. 28
0
int timer_timedOut(void){
    return (timerActive  &&  get_wall_time() > timerEndTime);
}
Esempio n. 29
0
void timer_start(double duration){
    timerEndTime    = get_wall_time() + duration;
    timerActive     = 1;
}
Esempio n. 30
0
/* Function Definitions */
void c_transmitImageData(uint32_T DSPCount, real32_T w[3], real32_T da, real32_T
  dtr, const emxArray_uint8_T *Tvec, const emxArray_uint8_T *Rvec, uint32_T d, uint32_T levels, CImgTransTimestamps& Timestamps)
{
  real32_T y;
  real32_T dmax;
  real32_T b_y;
  real32_T s;
  uint32_T aHeight;
  uint32_T aWidth;
  real32_T rr;
  real32_T angles[6];
  int32_T i;
  uint32_T b_i;
  real32_T rl;
  int32_T angle_size;
  int32_T c_y;
  int32_T Box_size_idx_0;
  int32_T ixstart;
  real32_T Box_data[48];
  real32_T uBox[8];
  int32_T x;
  //uint8_t *TSinglePart;
  //uint8_t *RSinglePart;
  real32_T rt;
  real32_T rb;
  real32_T DSPResponsibilityBox[4];
  int32_T ix;
  boolean_T exitg4;
  uint32_T marginL;
  boolean_T exitg3;
  uint32_T marginR;
  boolean_T exitg2;
  uint32_T marginO;
  boolean_T exitg1;
  uint32_T marginU;
  uint32_T BoundBox[4];
  uint32_T b_DSPResponsibilityBox[4];
  uint32_T MarginAddon[3];

  Timestamps.BeginXtrct.measureWallAndCPUTime();

  /* Global definition has only effect in matlab simulation (coder.extrinsic forbids global use here in matlab coder) */
  /* coder.extrinsic('global');  %this line unfortunately doesn't work */
  /* global GlobTParts GlobTPartsPtrs GlobRParts GlobRPartsPtrs GlobDSPResponsibilityBox GlobBoundBox GlobImgDimension; */
  y = (real32_T)d / 2.0F;
  dmax = (real32_T)d / 2.0F - 0.5F;
  b_y = (real32_T)d / 2.0F;
  s = (real32_T)d / 2.0F + 0.5F;

  /* Shifting, um negative Koordinaten in Matrixbereich zu bringen */
  /* ======================================================================== */
  /* = Relevante Bildteile berechnen, Bilder �bertragen */
  /* ======================================================================== */
  /* Calc layout of DSP grid regarding the Reference image */
  calcDSPLayout(DSPCount, &aWidth, &aHeight);

  /* Winkelst�tzstellen berechnen. */
  /* Einerseits die erlaubten Maximalwinkel w-da, w+da */
  /* Ferner alle Extrema zwischen den St�tzstelen ((x-45) mod 90 = 0) */
  rr = w[0] / 6.28318548F;
  rr = (rr - (real32_T)floor(rr)) * 6.28318548F;
  w[0] = rr;

  /* ensure angle to be in range 0 ... 360 deg */
  for (i = 0; i < 6; i++) {
    angles[i] = 0.0F;
  }

  angles[0] = w[0] - da;
  angles[1] = w[0] + da;
  b_i = 2U;

  /* Maximum diagonal extend is at 45deg, (90+45)deg, (190+45)deg etc. */
  /* wMax=single(0); */
  for (i = 0; i < 12; i++) {
    rl = -5.497787F + (real32_T)i * 1.57079637F;

    /* because dt is allowed to be 0 ... 360 deg */
    if ((angles[0] < rl) && (angles[1] > rl)) {
      angles[(int32_T)b_i] = rl;
      b_i++;
    }
  }

  angle_size = (int32_T)b_i;

  /* DSPResponsibilityBox=zeros(4,'single'); */
  /* BoundBox=zeros(4,'uint32'); */
  c_y = (int32_T)(((uint32_T)(int32_T)b_i - 1U) << 2);
  Box_size_idx_0 = (int32_T)((uint32_T)c_y + 4U);
  i = ((int32_T)((uint32_T)c_y + 4U) << 1) - 1;
  for (ixstart = 0; ixstart <= i; ixstart++) {
    Box_data[ixstart] = 0.0F;
  }

  for (ixstart = 0; ixstart < 8; ixstart++) {
    uBox[ixstart] = 0.0F;
  }

  b_i = 1U;
  x = 0;
  while (x <= (int32_T)(real32_T)aWidth - 1) {
    for (c_y = 0; c_y <= (int32_T)(real32_T)aHeight - 1; c_y++) {

      /*  Untransformed x,y edges per DSP ------------------- */
      rl = (((1.0F + (real32_T)x) - 1.0F) / (real32_T)aWidth * (real32_T)d -
            (real32_T)d / 2.0F) + 0.5F;

      /* -s for matching coordinate system to registration algorithm */
      rr = ((1.0F + (real32_T)x) / (real32_T)aWidth * (real32_T)d - (real32_T)d /
            2.0F) - 0.5F;
      rt = (((1.0F + (real32_T)c_y) - 1.0F) / (real32_T)aHeight * (real32_T)d -
            (real32_T)d / 2.0F) + 0.5F;
      rb = ((1.0F + (real32_T)c_y) / (real32_T)aHeight * (real32_T)d - (real32_T)
            d / 2.0F) - 0.5F;
      DSPResponsibilityBox[0] = rl;
      DSPResponsibilityBox[1] = rr;
      DSPResponsibilityBox[2] = rt;
      DSPResponsibilityBox[3] = rb;
      uBox[0] = rl;

      /* -s for matching coordinate system to registration algorithm */
      uBox[4] = rt;
      uBox[1] = rr;
      uBox[5] = rt;
      uBox[2] = rl;
      uBox[6] = rb;
      uBox[3] = rr;
      uBox[7] = rb;

      /*  Transform edge coordinates -------------------------- */
      for (i = 1; (uint32_T)i <= (uint32_T)angle_size; i = (int32_T)((uint32_T)i
            + 1U)) {
        for (ixstart = 0; ixstart < 4; ixstart++) {
          Box_data[(int32_T)(((uint32_T)i - 1U) << 2) + ixstart] = ((real32_T)
            cos(angles[i - 1]) * uBox[ixstart] - (real32_T)sin(angles[i - 1]) *
            uBox[4 + ixstart]) + w[1];
          Box_data[((int32_T)(((uint32_T)i - 1U) << 2) + ixstart) +
            Box_size_idx_0] = ((real32_T)sin(angles[i - 1]) * uBox[ixstart] +
                               (real32_T)cos(angles[i - 1]) * uBox[4 + ixstart])
            + w[2];
        }
      }

      /*  X Bounding Box ------------------------------- */
      i = (int32_T)((uint32_T)angle_size << 2);
      ixstart = 1;
      rl = Box_data[0];
      if (rtIsNaNF(Box_data[0])) {
        ix = 2;
        exitg4 = FALSE;
        while ((exitg4 == 0U) && (ix <= i)) {
          ixstart = ix;
          if (!rtIsNaNF(Box_data[ix - 1])) {
            rl = Box_data[ix - 1];
            exitg4 = TRUE;
          } else {
            ix++;
          }
        }
      }

      if (ixstart < i) {
        while (ixstart + 1 <= i) {
          if (Box_data[ixstart] < rl) {
            rl = Box_data[ixstart];
          }

          ixstart++;
        }
      }

      rt = (rl - 1.0F) - dtr;

      /* 1 more pixel for bilinear filtering             */
      marginL = 0U;
      if (rt < -dmax) {
        /* clipping */
        marginL = (uint32_T)rt_roundf_snf((-dmax - rt) + 1.0F);

        /* +1 = ceil */
        rt = -dmax;
      }

      ixstart = 1;
      rl = Box_data[0];
      if (rtIsNaNF(Box_data[0])) {
        ix = 2;
        exitg3 = FALSE;
        while ((exitg3 == 0U) && (ix <= i)) {
          ixstart = ix;
          if (!rtIsNaNF(Box_data[ix - 1])) {
            rl = Box_data[ix - 1];
            exitg3 = TRUE;
          } else {
            ix++;
          }
        }
      }

      if (ixstart < i) {
        while (ixstart + 1 <= i) {
          if (Box_data[ixstart] > rl) {
            rl = Box_data[ixstart];
          }

          ixstart++;
        }
      }

      rr = (rl + 1.0F) + dtr;

      /* 1 more pixel for bilinear filtering */
      marginR = 0U;
      if (rr > y - 0.5F) {
        /* clipping */
        marginR = (uint32_T)rt_roundf_snf((rr - (y - 0.5F)) + 1.0F);

        /* +1 = ceil */
        rr = y - 0.5F;
      }

      /*  Y Bounding Box ------------------------------- */
      i = (int32_T)((uint32_T)angle_size << 2);
      ixstart = 1;
      rl = Box_data[Box_size_idx_0];
      if (rtIsNaNF(Box_data[Box_size_idx_0])) {
        ix = 2;
        exitg2 = FALSE;
        while ((exitg2 == 0U) && (ix <= i)) {
          ixstart = ix;
          if (!rtIsNaNF(Box_data[(ix + Box_size_idx_0) - 1])) {
            rl = Box_data[(ix + Box_size_idx_0) - 1];
            exitg2 = TRUE;
          } else {
            ix++;
          }
        }
      }

      if (ixstart < i) {
        while (ixstart + 1 <= i) {
          if (Box_data[ixstart + Box_size_idx_0] < rl) {
            rl = Box_data[ixstart + Box_size_idx_0];
          }

          ixstart++;
        }
      }

      rb = (rl - 1.0F) - dtr;

      /* 1 more pixel for bilinear filtering; */
      marginO = 0U;
      if (rb < -dmax) {
        /* clipping */
        marginO = (uint32_T)rt_roundf_snf((-dmax - rb) + 1.0F);

        /* +1 = ceil */
        rb = -dmax;
      }

      ixstart = 1;
      rl = Box_data[Box_size_idx_0];
      if (rtIsNaNF(Box_data[Box_size_idx_0])) {
        ix = 2;
        exitg1 = FALSE;
        while ((exitg1 == 0U) && (ix <= i)) {
          ixstart = ix;
          if (!rtIsNaNF(Box_data[(ix + Box_size_idx_0) - 1])) {
            rl = Box_data[(ix + Box_size_idx_0) - 1];
            exitg1 = TRUE;
          } else {
            ix++;
          }
        }
      }

      if (ixstart < i) {
        while (ixstart + 1 <= i) {
          if (Box_data[ixstart + Box_size_idx_0] > rl) {
            rl = Box_data[ixstart + Box_size_idx_0];
          }

          ixstart++;
        }
      }

      rl = (rl + 1.0F) + dtr;

      /* 1 more pixel for bilinear interpolation; */
      marginU = 0U;
      if (rl > y - 0.5F) {
        /* clipping */
        marginU = (uint32_T)rt_roundf_snf((rl - (y - 0.5F)) + 1.0F);

        /* +1 = ceil */
        rl = y - 0.5F;
      }

      /*  Extract img -------------------------------              */
      BoundBox[0] = (uint32_T)rt_roundf_snf((real32_T)floor(rt + (b_y + 0.5F)));
      BoundBox[1] = (uint32_T)rt_roundf_snf((real32_T)ceil(rr + (b_y + 0.5F)));
      BoundBox[2] = (uint32_T)rt_roundf_snf((real32_T)floor(rb + (b_y + 0.5F)));
      BoundBox[3] = (uint32_T)rt_roundf_snf((real32_T)ceil(rl + (b_y + 0.5F)));

      /* Keep only the biggest margin of left and right. (We share both */
      /* margins on the right with one exception, we add one times the left */
      /* margin to the space between the top margin and the data start.) */
      if (marginL > marginR) {
        marginR = marginL;
      }

      /* Return R */
      for (ixstart = 0; ixstart < 4; ixstart++) {
        b_DSPResponsibilityBox[ixstart] = (uint32_T)rt_roundf_snf
          (DSPResponsibilityBox[ixstart] + s);
      }

	  /* Keep only the biggest margin of left and right. (We share both */
	  /* margins on the right with one exception, we add one times the left */
	  /* margin to the space between the top margin and the data start.) */
	  if (marginL > marginR) {
		marginR = marginL;
	  }

	  MarginAddon[0] = marginR;
	  MarginAddon[1] = marginO + 1U;
	  MarginAddon[2] = marginU;

	  /* We add 1 to the upper margin because of the reusal of the right and */
	  /* left margin. It would be sufficient to add marginL padding bytes to */
	  /* the top, however adding a whole row is more convenient as the */
	  /* resulting data buffer remains a square picture and the loss of a few */
	  /* KB ram (in a cache-uninteresting area) is neglectible. */

	  /* Matlab coder compilation: Start sendingall data to target needed */
      /* for being able to call function 'jacobian' on the target. */
      /* (Sending will be done async/nonblocking in the background). */

	  //Prepare HPRPC store image command header.
	  uint32_T TSinglePartLen = getImagePartSize(BoundBox);
	  uint32_T RSinglePartLen = getImagePartSize(b_DSPResponsibilityBox);

	  CHPRPCRequestStoreImg *pRequest = matlab_c_prepareSendToTarget(
					 b_i, BoundBox, MarginAddon, DSPResponsibilityBox,
					 /*TSinglePart,*/ TSinglePartLen, /*RSinglePart,*/
					 RSinglePartLen, d, levels
					 );

	  double dBeforeExtraction = get_wall_time();

	  //Start 1 thread per DSP for image extraction (directly into the send buffers which might allready be in non-paged kernel memory)
	  TThreadData* pThreadData = &g_ThreadData[b_i-1];
	  //pThreadData->TSinglePart = TSinglePart;
	  pThreadData->Tvec = &Tvec->data[0];
	  memcpy(pThreadData->BoundBox, BoundBox, 4*sizeof(uint32_T));
	  pThreadData->d = d;
	  //pThreadData->RSinglePart = RSinglePart;
	  pThreadData->Rvec = &Rvec->data[0];
	  memcpy(pThreadData->b_DSPResponsibilityBox, b_DSPResponsibilityBox, 4*sizeof(uint32_T));
	  pThreadData->b_i = b_i;
	  pThreadData->pRequest = pRequest;

	  SpawnExtractAndSendThread(pThreadData, (b_i-1));
	
      b_i++;
    }

    x++;
  }

  double TimeForAddMarginsTotal=0;
  double TimeForPyramidTotal=0;
  b_i = 1U;
  for (x = 0; x <= (int32_T)(real32_T)aWidth - 1; x++) {
    for (c_y = 0; c_y <= (int32_T)(real32_T)aHeight - 1; c_y++) {
      /* Matlab coder compilation: Wait until every DSP confirmed data */
      /* transmission. */
	  double TimeForAddMargins, TimeForPyramid;
      waitUntilTargetReady(b_i, TimeForAddMargins, TimeForPyramid);
	  TimeForAddMarginsTotal+=TimeForAddMargins;
	  TimeForPyramidTotal+=TimeForPyramid;

	  b_i++;
    }
  }

  //Performance measurement:

  //Time when the DSPs responded about having received (and processed) the image data and are ready for calculation
  Timestamps.FinishedXtrct.measureWallAndCPUTime();

  //Time when the CPU finished extracting the partial image data
  Timestamps.XtrctPartFinished.setWallClockTime(g_lastImageExtractor->ExtractFinishedWCTime);
  Timestamps.XtrctPartFinished.setCPUTime(g_lastImageExtractor->ExtractFinishedCPUTime);

  //Time when the CPU finished regarding the data sending (below the latest value is determined)
  Timestamps.SendingStartedSystemNowIdle.setWallClockTime(g_lastPCIeSender->SndStartdWCTime);
  Timestamps.SendingStartedSystemNowIdle.setCPUTime(g_lastPCIeSender->SndStartdCPUTime);	

  //Average times from target
  Timestamps.TimeForAddMargins = TimeForAddMarginsTotal / DSPCount;
  Timestamps.TimeForPyramidTotal = TimeForPyramidTotal / DSPCount;

  /* Datenreduktion etwa auf folgenden Wert (ist / max) */
  /* dbgSizDat_Transmitted_Data = dbgSizDat / (d*d*4) */
}