Exemplo n.º 1
0
//Output: the energy cost of attacking G
// Parameter R: core memory ratio
// Parameter rootd: rootd^2 = d >= depth(G-S). We have rootd layers, and each segment in a layer has size rootd.
double attackBH(struct bnode* G, int* S, int sizeOfLayer, int segSize, int n, int g, int w, double R)
{
	if (n <= 0) return -1000; /* Should only call with n > 0*/
	int i;
    resetGraph(G,n);
	//int sizeOfLayer = (int)ceil(n*1.0 / (rootd*1.0));

	/*total memory used keeping pebbles on S in pebbling*/
	double costOnS = 0;
	double costOnP = 0;
	/* number RO queries */

	int lightPhaseEnd = g;
	/*current number of pebbles on S at step i*/
	int pebblesOnSRightNow = 0;
	int numberPebblesonParentsRightNow = 0;

	double costOfBalloonPhases = 0.0;
	int totalBalloonPhaseRound = 0;

	for (i = 1; i < n; i++)
	{
		pebblesOnSRightNow = pebblesOnSRightNow + S[i];
		costOnS = costOnS + pebblesOnSRightNow;

		costOnP = costOnP + numberPebblesonParentsRightNow;

		if (i % g == 0 && i > 0 )
		{
			numberPebblesonParentsRightNow = bparents(G, S, i, i + g, n);
			lightPhaseEnd += g;
		}
		else // if (i >= g)
		{
			numberPebblesonParentsRightNow = updatebParents(G, S, numberPebblesonParentsRightNow, i, lightPhaseEnd);

		}
	}

	for (i =g; i < n; i+=g)
	{
		int currentLayer = nodeLayer(i, sizeOfLayer);  // (int)floor(i * 1.0 / (1.0 * sizeOfLayer));
		int timeBalloonPhaseWouldTake = currentLayer*segSize + nodePlaceInGap(i,sizeOfLayer,segSize);
		costOfBalloonPhases +=  balloonbPhaseCost(G, S, sizeOfLayer, segSize, n, w, R, i - timeBalloonPhaseWouldTake);
		totalBalloonPhaseRound += timeBalloonPhaseWouldTake;
	}

	double cost = costOnS + costOnP + (n - totalBalloonPhaseRound)*R + costOfBalloonPhases;

	// DEBUG CODE
	printf("g = %d\t cost = %0.0f\t costOnP = %0.1f\t costOfBalloonPhases = %0.0f\t totalBalloonPhaseRound = %d\n",  \
	         g, cost, costOnP, costOfBalloonPhases, totalBalloonPhaseRound);

	resetGraph(G, n);
	return cost;
}
Exemplo n.º 2
0
void resetGraph(Node * node)
{
  if(node == NULL)
    return;
  resetGraph(node->next);
  node->weight = PSEUDOINF;
  node->prev = -1;
  node->ingraph = 1;
}
Exemplo n.º 3
0
std::vector<int> QAMDecoder::decode(std::vector<double> phase,
		std::vector<double> quad, double n0) {
	if (phase.size() != quad.size() || phase.size() != s) {
		std::stringstream str;
		str << "Invalid input size";
		throw std::invalid_argument(str.str());
	}

	//LLR symbol node initialization
	for (int i = 0; i < s; i++) {
		//TODO fix initialization
		received.at(i)->setValue(phase.at(i), quad.at(i));
		if (DEBUG) {
			std::cout << phase.at(i) << " " << quad.at(i) << " ";
		}
	}
	if (DEBUG) {
		std::cout << " received\n";
	}

	//Message passing (stops when Hc=0 or after a max number of cycles)
	int pass = 0;
	bool check = parityCheck();
	while (!check && pass < passes) {
		forwardPassing();
		if (DEBUG) {
			for (int i = 0; i < k; i++) {
				std::cout << parity.at(i)->getValue() << " ";
			}
			std::cout << "LLR (check)\n";
		}
		check = parityCheck();
		if (check) {
			break;
		}
		backwardPassing();
		if (DEBUG) {
			for (int i = 0; i < n; i++) {
				std::cout << encoded.at(i)->getValue() << " ";
			}
			std::cout << "LLR (var)\n";
		}
		check = parityCheck();
		pass += 2;
	}

	//Decoded vector
	std::vector<int> decoded;
	for (int i = 0; i < n; i++) {
		double in = encoded.at(i)->getValue();
		decoded.push_back(encoded.at(i)->llr2val(in));
	}
	resetGraph();

	return decoded;
}
Exemplo n.º 4
0
int hopcroftTest(int N, int d, char *file_name) {
/*
    hopcroft_steps, hopcroft_time, quickmatchHopcroft_steps, quickmatchHopcroft_time, quickmatchHopcroft_unmatched
*/
    FILE *file; 
    file = fopen(file_name,"a+"); // append file (add text to a file or 
                                  // create a file if it does not exist.
    assert(file != NULL);

    srandom(SEED);
    int hopcroft_steps=0;
    int quickmatchHopcroft_steps=0;

    float hopcroft_time=0.0;
    float quickmatchHopcroft_time=0.0;
    int i;
    while (true) {
        int *right_sides;
        int *matching1, *matching2;
        int unmatched = 0;
        struct Graph *graph;

        right_sides = createRightSides(N,d);
        graph = createRandomRegBipartite(N,d,1,right_sides);
    

        START_TIMER
        hopcroft_steps = hopcroft(graph, &matching1); 
        STOP_TIMER
        hopcroft_time = seconds;

        resetGraph(graph);

        START_TIMER
        quickmatchHopcroft_steps = quickmatch_hopcroft(graph, &matching2); 
        STOP_TIMER
        quickmatchHopcroft_time = seconds;


        // Validate
        assert(0 == validateMatching(matching1, graph));
        int quickmatchHopcroft_unmatched = validateMatching(matching2, graph);

        
        printf("printing to file\n");
        fprintf(file,"%i,%f,%i,%f,%i\n", hopcroft_steps, hopcroft_time, quickmatchHopcroft_steps, quickmatchHopcroft_time, quickmatchHopcroft_unmatched);        // Free
        fflush(file);
        freeGraph(graph);
        free(right_sides);
        free(matching1);
        free(matching2);
        //free(visited);
        //free(targets);
    }
    fclose(file); 
}
Exemplo n.º 5
0
void testScheduler(int nThreads, graph* G, char debug)
{
	double runtime;

	//Set max nThreads
	omp_set_num_threads(nThreads);

	if(mpi_id == 0) printf("Scheduler (Static, %d)", G->N/100 );
	resetGraph(G);
	omp_set_schedule(omp_sched_static, G->N/100);
	if(mpi_id == 0) tick();
		dijkstra(G, 0, debug);
	if(mpi_id == 0){
		runtime = tack();
		printf("working for [%f] sec.\n",runtime);
	}


	if(mpi_id == 0) printf("Scheduler (dynamic, %d)", G->N/100 );
	resetGraph(G);
	omp_set_schedule(omp_sched_dynamic, G->N/100);
	if(mpi_id == 0) tick();
		dijkstra(G, 0, debug);
	if(mpi_id == 0){
		runtime = tack();
		printf("working for [%f] sec.\n",runtime);
	}

	if(mpi_id == 0) printf("Scheduler (guided, %d)", G->N/100 );
	resetGraph(G);
	omp_set_schedule(omp_sched_guided, G->N/100);
	if(mpi_id == 0) tick();
		dijkstra(G, 0, debug);
	if(mpi_id == 0){
		runtime = tack();
		printf("working for [%f] sec.\n",runtime);
	}
}
Exemplo n.º 6
0
std::vector<int> LDPCDecoder::decode(std::vector<double> llr) {
	if (n != llr.size()) {
		std::stringstream str;
		str << "Invalid input size";
		throw std::invalid_argument(str.str());
	}

	//LLR variable node initialization
	for (int i = 0; i < n; i++) {
		received.at(i)->setValue(llr.at(i));
		if (DEBUG) {
			std::cout << llr.at(i) << " ";
		}
	}
	if (DEBUG) {
		std::cout << " LLR\n";
	}

	//Message passing (stops when Hc=0 or after a max number of cycles)
	int pass = 0;
	bool check = parityCheck();
	while (!check && pass < passes) {
		forwardPassing();
		if (DEBUG) {
			for (int i = 0; i < k; i++) {
				std::cout << parity.at(i)->getValue() << " ";
			}
			std::cout << "LLR (check)\n";
		}
		backwardPassing();
		if (DEBUG) {
			for (int i = 0; i < n; i++) {
				std::cout << received.at(i)->getValue() << " ";
			}
			std::cout << "LLR (var)\n";
		}
		check = parityCheck();
		pass += 2;
	}

	//Decoded vector
	std::vector<int> decoded;
	for (int i = 0; i < n; i++) {
		double in = received.at(i)->getValue();
		decoded.push_back(received.at(i)->llr2val(in));
	}
	resetGraph();

	return decoded;
}
Exemplo n.º 7
0
/* makeMultiSpline:
 * FIX: we don't really use the shortest path provided by ED_path,
 * so avoid in neato spline code.
 * Return 0 on success.
 */
int makeMultiSpline(graph_t* g,  edge_t* e, router_t * rtr, int doPolyline)
{
    Ppolyline_t line = ED_path(e);
    node_t *t = agtail(e);
    node_t *h = aghead(e);
    pointf t_p = line.ps[0];
    pointf h_p = line.ps[line.pn - 1];
    tripoly_t *poly;
    int idx;
    int *sp;
    int t_id = rtr->tn;
    int h_id = rtr->tn + 1;
    int ecnt = rtr->tg->nedges;
    PPQ pq;
    PQTYPE *idxs;
    PQVTYPE *vals;
    int ret;

	/* Add endpoints to triangle graph */
    addEndpoint(rtr, t_p, t, t_id, ED_tail_port(e).side);
    addEndpoint(rtr, h_p, h, h_id, ED_head_port(e).side);

	/* Initialize priority queue */
    PQgen(&pq.pq, rtr->tn + 2, -1);
    idxs = N_GNEW(pq.pq.PQsize + 1, PQTYPE);
    vals = N_GNEW(pq.pq.PQsize + 1, PQVTYPE);
    vals[0] = 0;
    pq.vals = vals + 1;
    pq.idxs = idxs + 1;

	/* Find shortest path of triangles */
    sp = triPath(rtr->tg, rtr->tn+2, h_id, t_id, (PQ *) & pq);

    free(vals);
    free(idxs);
    PQfree(&(pq.pq), 0);

	/* Use path of triangles to generate guiding polygon */
    poly = mkPoly(rtr, sp, h_id, t_id, h_p, t_p, &idx);

    free(sp);

	/* Generate multiple splines using polygon */
    ret = genroute(g, poly, 0, idx, e, doPolyline);
    freeTripoly (poly);

    resetGraph(rtr->tg, rtr->tn, ecnt);
    return ret;
}
Exemplo n.º 8
0
int main(int argc, char * * argv)
{
  //Verify that the correct number of arguments is given
  if(argc != 3)
    FATAL("Invalid number of command line arguments!");
  //Open the map file for reading
  FILE * map = fopen(argv[1], "r");
  //Read the number of vertices in the file
  int numVertices = readNumberFromFile(map);
  //Read the number of edges in the file
  int numEdges = readNumberFromFile(map);
  //Read vertice data and assign it to nodal linked list "vertex"
  int nodenum = readNumberFromFile(map);
  int nodexcoord = readNumberFromFile(map);
  int nodeycoord = readNumberFromFile(map);
  Node * vertex = nodeConstructor(nodenum, nodexcoord, nodeycoord);
  int i;
  Node * tmpitr = vertex;
  for(i = 1; i < numVertices; ++i) {
    nodenum = readNumberFromFile(map);
    nodexcoord = readNumberFromFile(map);
    nodeycoord = readNumberFromFile(map);
    tmpitr->next = nodeConstructor(nodenum, nodexcoord, nodeycoord);
    tmpitr = tmpitr->next;
  }
  //Read edge data from the file and assign it to respective lists
  for(i = 0; i < numEdges; ++i) {
    int firstnode = readNumberFromFile(map);
    int secondnode = readNumberFromFile(map);
    insertConnection(vertex, firstnode, secondnode);
  }
  fclose(map);
  //NOTE: At this point, the graph is complete, so begin algorithm
  //Open the query file for reading
  FILE * query = fopen(argv[2], "r");
  //Read the number of queries
  int numQueries = readNumberFromFile(query);
  //Read query data and store it for reference
  int * queryArr = readQueries(query, numQueries);
  //Store origin node in list
  Node * origin = vertex;
  //Loop through the queries
  for(i = 0; i < (numQueries * 2); i += 2) {
    //Find the starting point of the query
    int startVal = queryArr[i];
    int endVal = queryArr[i+1];
    //If they're the same, avoid trying to do anything else
    if(startVal == endVal) {
      printf("0\n");
      printf("%d %d\n", startVal, endVal);
    }
    else {
      Node * start = findVertexByValue(startVal, origin);
      Node * end = findVertexByValue(endVal, origin);
      start->weight = 0;
      while(areAllNotRemoved(origin)) {
	//Set the weight check to find minimum node
	Node * itrNode = findLowestNode(origin);
	//Make sure we're not done
	if(itrNode->value == endVal)
	  break;
	//Update weights for adjacent nodes
	updateAdjacentWeights(itrNode, origin);
      }
      if(end->weight == PSEUDOINF)
	FATAL("Final node weight was not updated... possibly unconnected?");
      //Produce the result list
      ResultList * results = reslistConstructor(end->value, end->weight);
      Node * before = findVertexByValue(end->prev, origin);
      while(before->value != startVal) {
	ResultList * pinonfront = reslistConstructor(before->value, before->weight);
	pinonfront->next = results;
	results = pinonfront;
	before = findVertexByValue(before->prev, origin);
      }
      //Make sure the first number in the list is origin
      if(results->value != startVal) {
	ResultList * pinonfront2 = reslistConstructor(startVal, start->weight);
	pinonfront2->next = results;
	results = pinonfront2;
      }
      //Verify weights and assign the end weight
      //end->weight = verifyWeightsAndAssign(results, origin);
      //Print the final results
      printf("%ld\n", end->weight);
      ResultList * printitr = results;
      while(printitr != NULL) {
	printf("%d ", printitr->value);
	printitr = printitr->next;
      }
      printf("\n");
      reslistDestroy(results);
      resetGraph(origin);
    }
  }

  //Free used memory
  fclose(query);
  free(queryArr);
  nodeDestroy(origin);

  return EXIT_SUCCESS;
}
Exemplo n.º 9
0
double attackParallelLanes(struct bnode* G, int* S, int sizeOfLayer, int gapInLayer, int nOverP, int g, int w, double R, int parallelism)
{
	if (nOverP <= 0 || parallelism <= 0) return -1000; /* Should only call with n > 0*/
	int i,iL, lane;
    resetGraph(G,nOverP*parallelism);
	//int sizeOfLayer = (int)ceil(n*1.0 / (rootd*1.0));

	/*total memory used keeping pebbles on S in pebbling*/
	double costOnS = 0;
	double costOnP = 0;
	/* number RO queries */

	int lightPhaseEnd = g;
	/*current number of pebbles on S at step i*/
	int pebblesOnSRightNow = 0;
	int numberPebblesonParentsRightNow = 0;

	double costOfBalloonPhases = 0.0;
	int totalBalloonPhaseRound = 0;

	for (iL = 1; iL < nOverP; iL++)
	{
		if (iL % g == 0 && iL > 0 )
		{
			numberPebblesonParentsRightNow = bparents(G, S, iL*parallelism, iL*parallelism + g*parallelism, nOverP*parallelism);
			lightPhaseEnd += g;
		}
		else // if (i >= g)
		{
			for(lane = 0; lane < parallelism; lane++)
			{
			numberPebblesonParentsRightNow = updatebParents(G, S, numberPebblesonParentsRightNow, iL*parallelism+lane, lightPhaseEnd*parallelism);
			}

		}
        for(lane = 0; lane < parallelism; lane++)
        {
			i = iL*parallelism+lane;
		    pebblesOnSRightNow = pebblesOnSRightNow + S[i];
		}
	    costOnS = costOnS + pebblesOnSRightNow;

	    costOnP = costOnP + numberPebblesonParentsRightNow;
	}

	for (iL =g; iL < nOverP; iL+=g)
	{
		int currentLayer = nodeLayer(iL, sizeOfLayer);  // (int)floor(i * 1.0 / (1.0 * sizeOfLayer));
		int timeBalloonPhaseWouldTake = currentLayer*gapInLayer + nodePlaceInGap(iL,sizeOfLayer,gapInLayer);

		costOfBalloonPhases +=  balloonPhaseCostParallel(G,  S, sizeOfLayer, gapInLayer, nOverP, w, R, iL - timeBalloonPhaseWouldTake,parallelism);
		totalBalloonPhaseRound += timeBalloonPhaseWouldTake;
	}

	double cost = costOnS + costOnP + (nOverP - totalBalloonPhaseRound)*parallelism*R + costOfBalloonPhases;

	// DEBUG CODE
	printf("g = %d\t cost = %0.0f\t costOnP = %0.1f\t costOfBalloonPhases = %0.0f\t totalBalloonPhaseRound = %d\n",  \
	         g, cost, costOnP, costOfBalloonPhases, totalBalloonPhaseRound);

	resetGraph(G, nOverP*parallelism);
	return cost;
}
Exemplo n.º 10
0
int altTest(int N, int d, char *file_name) {
/*

N, d, unmatched, bfs_steps, dfs_steps, bfs2bfs_steps, dfs2bfs_steps, dfs2dfs_steps, hopcroft_steps, bfs_time, dfs_time, bfs2bfs_time, dfs2bfs_time, dfs2dfs_time, hopcroft_time

*/
    long last_flush = 0;
    long cur_time = 0;
    FILE *file; 
    file = fopen(file_name,"a+"); // append file (add text to a file or 
                                  // create a file if it does not exist.
    assert(file != NULL);

    //srandom(time(NULL));
    srandom(SEED);
    int quickmatch_steps;
    int bfs_steps;
    int dfs_steps;
    int bfs2bfs_steps;
    int dfs2bfs_steps;
    int dfs2dfs_steps;
    int hopcroft_steps;
    float quickmatch_time;
    float bfs_time;
    float dfs_time;
    float bfs2bfs_time;
    float dfs2bfs_time;
    float dfs2dfs_time;
    float hopcroft_time;
    int bfs_path_length;
    int hopcroft_phases;
    int orig_unmatched;
    
    int i;
    while (true) {
        int *right_sides;
        int *matching;
        int unmatched = 0;
        struct Graph *graph;

        right_sides = createRightSides(N,d);
        graph = createRandomRegBipartite(N,d,0,right_sides);
          START_TIMER
          quickmatch_steps = quickmatch(graph,&matching,&unmatched);
          STOP_TIMER
        quickmatch_time = seconds;

        orig_unmatched = unmatched;
    

        // Copy a matching for each process
        int* matching1 = copyMatching(matching, N);
        int* matching2 = copyMatching(matching, N);
        int* matching3 = copyMatching(matching, N);
        int* matching4 = copyMatching(matching, N);
        int* matching5 = copyMatching(matching, N);
        int* matching6 = copyMatching(matching, N);


        // Perform
        resetGraph(graph);
      
        bfs_steps=0;
        dfs_steps=0;
        bfs2bfs_steps=0;
        dfs2bfs_steps=0;
        dfs2dfs_steps=0;
        hopcroft_steps=0;
        bfs_time=0;
        dfs_time=0;
        bfs2bfs_time=0;
        dfs2bfs_time=0;
        dfs2dfs_time=0;
        hopcroft_steps=0;
        hopcroft_phases=0;

        int hopcroft_unmatched = unmatched;
        int temp, num_inserted;
        for (unmatched=unmatched; unmatched>0; unmatched--) {
            START_TIMER             
            bfs_steps = bfs(graph,matching1,&bfs_path_length);
            STOP_TIMER
            bfs_time = seconds;

            START_TIMER
            dfs_steps = dfs(graph,matching5);
            STOP_TIMER
            dfs_time = seconds;

            START_TIMER
            bfs2bfs_steps = bfs2bfs(graph,matching2);
            STOP_TIMER
            bfs2bfs_time = seconds;

            START_TIMER
            dfs2bfs_steps = dfs2bfs(graph,matching3);
            STOP_TIMER
            dfs2bfs_time = seconds;

            START_TIMER
            dfs2dfs_steps = dfs2dfs(graph,matching4);
            STOP_TIMER
            dfs2dfs_time = seconds;

            // this logic accounts for the fact that sometimes hopcroftPhase inserts more than one edge into matching 
            if (hopcroft_unmatched == unmatched) {
                hopcroft_phases++;
                hopcroft_steps = 0;
                temp = hopcroft_unmatched;
                  START_TIMER
                  hopcroftPhase(graph, matching6, &hopcroft_unmatched, &hopcroft_steps);
                  STOP_TIMER
                num_inserted = temp - hopcroft_unmatched;
                //assert(hopcroft_unmatched == validateMatching(matching6, graph));
                //assert(temp>hopcroft_unmatched);
                hopcroft_steps = hopcroft_steps/num_inserted;
                hopcroft_time = seconds/num_inserted;
            }

            fprintf(file,"%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%f,%f,%f,%f,%i\n", N, d, unmatched, bfs_steps, dfs_steps, bfs2bfs_steps, dfs2bfs_steps, dfs2dfs_steps, hopcroft_steps, bfs_time, dfs_time, bfs2bfs_time, dfs2bfs_time, dfs2dfs_time, hopcroft_time, bfs_path_length);

        }

        printf("%f,", orig_unmatched / (float) hopcroft_phases);

        // Validate
        validateMatching(matching1, graph);
        validateMatching(matching2, graph);
        validateMatching(matching3, graph);
        validateMatching(matching4, graph);
        validateMatching(matching5, graph);
        validateMatching(matching6, graph);

        assert(isMatchingComplete(graph, matching1));
        assert(isMatchingComplete(graph, matching2));
        assert(isMatchingComplete(graph, matching3));
        assert(isMatchingComplete(graph, matching4));
        assert(isMatchingComplete(graph, matching5));
        assert(isMatchingComplete(graph, matching6));
    
        float unmatchedFloat = (float) unmatched;
        
    
        cur_time = (long) time(NULL);
        if (time(NULL) >= last_flush + FLUSH_TIME) {
            fflush(file);
            fflush(stdout);
            last_flush = cur_time;
        }

        // Free
        freeGraph(graph);
        free(matching);
        free(matching1);
        free(matching2);
        free(matching3);
        free(matching4);
        free(matching5);
        free(matching6);
        free(right_sides);
        //free(visited);
        //free(targets);
    }
    fclose(file); 
}
Exemplo n.º 11
0
NodeGraph::~NodeGraph()
{
	resetGraph();
}
Exemplo n.º 12
0
int main(){
	int nbSlaves = 1;

	static Architecture 		arch;
	static ExecutionStat 		execStat;
	static PiSDFGraph 			pisdfGraphs[MAX_NB_PiSDF_GRAPHS];
	static PiSDFGraph 			*topPisdf;

	static int time[20];

	printf("Starting with %d slaves max\n", nbSlaves);

	/* Create the architecture */
	arch.reset();
	arch.addSlave(0, "Master", 0.9267, 435, 0.9252, 430);
	char tempStr[MAX_SLAVE_NAME_SIZE];

	for(int i=1; i<nbSlaves; i++){
		UINT32 len = snprintf(tempStr, MAX_SLAVE_NAME_SIZE, "PE%02d", i);
		if(len > MAX_SLAVE_NAME_SIZE){
			exitWithCode(1073);
		}
		arch.addSlave(1, tempStr, 0.9267, 435, 0.9252, 430);
	}
	arch.setNbActiveSlaves(nbSlaves);

	setFctPtr(0, mixInput);
	setFctPtr(1, display);
	setFctPtr(2, rgb2Gray);
	setFctPtr(3, census);
	setFctPtr(4, genDelta);
	setFctPtr(5, compWeight);
	setFctPtr(6, disp);
	setFctPtr(7, costConst);
	setFctPtr(8, aggregate);
	setFctPtr(9, select);
	setFctPtr(10, genDisp);
	setFctPtr(11, split);
	setFctPtr(12, medianSlice);
	setFctPtr(13, null);
//	setFctPtr(6, disp);
//	setFctPtr(7, dispGen);
//	setFctPtr(8, compWeight);
//	setFctPtr(9, costConstr);
//	setFctPtr(10, aggregateCost);
//	setFctPtr(11, dispSelect);
	setFctPtr(16, stereoMono);
	setFctPtr(15, config);

	setFctPtr(RB_FUNCT_IX, RB);
	setFctPtr(BROADCAST_FUNCT_IX, broadcast);
	setFctPtr(SWICTH_FUNCT_IX, switchFct);
	setFctPtr(XPLODE_FUNCT_IX, Xplode);
	setFctPtr(INIT_FUNCT_IX, InitVx);
	setFctPtr(END_FUNCT_IX, EndVx);

	/*
	 * These objects should be obtained from the PREESM generator :
	 * Architecture, Scheduling policy.
	 */

	netDisplay_Init();

	SPIDER_init(&arch);

	while(1){int iter= 0;
//	for(int iter=0; iter<=100; iter++){
		printf("N=%d\n", iter);

		resetGraph();
		topPisdf = initPisdf_stereo(pisdfGraphs);

		SPIDER_reset();

		SPIDER_launch(&arch, topPisdf);

		SPIDER_report(&arch, topPisdf, &execStat, iter);

		printf("SRDAG Graph %d vertices %d edges\n", execStat.SRDAGVertices, execStat.SRDAGEdges);

 		printf("GraphTime:   %d\n", execStat.graphTransfoTime);
 		printf("MappingTime: %d\n", execStat.mappingTime);
 		printf("TaskOrdTime: %d\n", execStat.taskOrderingTime);

 		for(int i=0; i<execStat.nbActor; i++){
 			printf("%15s : %u x %d (%.2f%%)\n",
 					execStat.actors[i]->getName(),
 					execStat.actorTimes[i]/execStat.actorIterations[i],
 					execStat.actorIterations[i],
 					100.0*execStat.actorTimes[i]/execStat.globalEndTime);
 		}

 		printf("\nEndTime: %u\n", execStat.globalEndTime);

 		time[iter-1] = execStat.globalEndTime;

// 		printf("Executed\n");
	}

	printf("finished\n");
}
Exemplo n.º 13
0
int main(){
	int nbSlaves = 9;

	static Architecture 		arch;
	static ExecutionStat 		execStat;
	static PiSDFGraph 			pisdfGraphs[MAX_NB_PiSDF_GRAPHS];
	static PiSDFGraph 			*topPisdf;

	static int time[20];

	printf("Starting with %d slaves max\n", nbSlaves);

	/* Create the architecture */
	arch.reset();
	arch.addSlave(0, "Master", 0.9267, 435, 0.9252, 430);
	char tempStr[MAX_SLAVE_NAME_SIZE];

	for(int i=1; i<nbSlaves; i++){
		UINT32 len = snprintf(tempStr, MAX_SLAVE_NAME_SIZE, "PE%02d", i);
		if(len > MAX_SLAVE_NAME_SIZE){
			exitWithCode(1073);
		}
		arch.addSlave(0, tempStr, 0.9267, 435, 0.9252, 430);
	}
	arch.setNbActiveSlaves(nbSlaves);

	setFctPtr(0, config);
	setFctPtr(1, mFilter);
	setFctPtr(2, src);
	setFctPtr(3, snk);
	setFctPtr(4, setM);
	setFctPtr(5, initSwitch);
	setFctPtr(7, FIR);

	/*
	 * These objects should be obtained from the PREESM generator :
	 * Architecture, Scheduling policy.
	 */

	SPIDER_init(&arch);

	for(int iter=9; iter<=9; iter++){
		printf("N=%d\n", iter);

		resetGraph();
#ifdef DSP
		topPisdf = initPisdf_mpSched(pisdfGraphs, 20, 4000, iter, 0);
#else
		topPisdf = initPisdf_mpSched(pisdfGraphs, 20, 4000, iter, 1);
#endif
		SPIDER_reset();

		SPIDER_launch(&arch, topPisdf);

		SPIDER_report(&arch, topPisdf, &execStat, iter);

 		printf("GraphTime:   %d\n", execStat.graphTransfoTime);
 		printf("MappingTime: %d\n", execStat.mappingTime);
 		printf("TaskOrdTime: %d\n", execStat.taskOrderingTime);

 		printf("\nEndTime: %d\n", execStat.globalEndTime);

 		time[iter-1] = execStat.globalEndTime;
	}

	char file[100];
	printf("time\n");
	sprintf(file,"spider_cache_nvar.csv");
	FILE *f = fopen(file,"w+");
	fprintf(f, "iter, latency\n");
	for(int iter=1; iter<=18; iter++){
		fprintf(f,"%d,%d\n",iter, time[iter-1]);
		printf("%d: %d\n",iter, time[iter-1]);
	}
	fclose(f);

	printf("finished\n");
}
Exemplo n.º 14
0
int bigTest(int N, int d, char *file_name) {
/*

unmatched, quickmatch_steps, quickmatch_time, bfs_steps/unmatchedFloat, bfs2bfs_steps/unmatchedFloat, dfs2bfs_steps/unmatchedFloat, dfs2dfs_steps/unmatchedFloat, dfs_steps/unmatchedFloat, bfs_time, bfs_time, dfs_time, bfs2bfs_time, dfs2bfs_time, dfs2dfs_time

*/
    long last_flush = 0;
    long cur_time = 0;
    FILE *file; 
    file = fopen(file_name,"a+"); // append file (add text to a file or 
                                  // create a file if it does not exist.
    assert(file != NULL);

    //srandom(time(NULL));
    srandom(SEED);
    int quickmatch_steps;
    int bfs_steps;
    int dfs_steps;
    int bfs2bfs_steps;
    int dfs2bfs_steps;
    int dfs2dfs_steps;
    int hopcroft_steps;
    float quickmatch_time;
    float bfs_time;
    float dfs_time;
    float bfs2bfs_time;
    float dfs2bfs_time;
    float dfs2dfs_time;
    float hopcroft_time;
    int bfs_path_length;
    int i;
    while (true) {
        int *right_sides;
        int *matching;
        int unmatched = 0;
        struct Graph *graph;

        right_sides = createRightSides(N,d);
        graph = createRandomRegBipartite(N,d,0,right_sides);
          START_TIMER
          quickmatch_steps = quickmatch(graph,&matching,&unmatched);
          STOP_TIMER
        quickmatch_time = seconds;
    

        // Copy a matching for each process
        int* matching1 = copyMatching(matching, N);
        int* matching2 = copyMatching(matching, N);
        int* matching3 = copyMatching(matching, N);
        int* matching4 = copyMatching(matching, N);
        int* matching5 = copyMatching(matching, N);
        int* matching6 = copyMatching(matching, N);


        // Perform
        resetGraph(graph);
      
        bfs_steps=0;
        dfs_steps=0;
        bfs2bfs_steps=0;
        dfs2bfs_steps=0;
        dfs2dfs_steps=0;
        hopcroft_steps=0;
        bfs_time=0;
        dfs_time=0;
        bfs2bfs_time=0;
        dfs2bfs_time=0;
        dfs2dfs_time=0;
        hopcroft_steps=0;

        for (i=0; i<unmatched; i++) {
            START_TIMER             
            bfs_steps += bfs(graph,matching1,&bfs_path_length);
            STOP_TIMER
            bfs_time += seconds;

            START_TIMER
            dfs_steps += dfs(graph,matching5);
            STOP_TIMER
            dfs_time += seconds;

            START_TIMER
            bfs2bfs_steps += bfs2bfs(graph,matching2);
            STOP_TIMER
            bfs2bfs_time += seconds;

            START_TIMER
            dfs2bfs_steps += dfs2bfs(graph,matching3);
            STOP_TIMER
            dfs2bfs_time += seconds;

            START_TIMER
            dfs2dfs_steps += dfs2dfs(graph,matching4);
            STOP_TIMER
            dfs2dfs_time += seconds;

            START_TIMER
            hopcroft_steps += hopcroftPartial(graph,matching6);
            STOP_TIMER
            hopcroft_time += seconds;
        }

        // Validate
        validateMatching(matching1, graph);
        validateMatching(matching2, graph);
        validateMatching(matching3, graph);
        validateMatching(matching4, graph);
        validateMatching(matching5, graph);
        validateMatching(matching6, graph);

        assert(isMatchingComplete(graph, matching1));
        assert(isMatchingComplete(graph, matching2));
        assert(isMatchingComplete(graph, matching3));
        assert(isMatchingComplete(graph, matching4));
        assert(isMatchingComplete(graph, matching5));
        assert(isMatchingComplete(graph, matching6));
    
        float unmatchedFloat = (float) unmatched;
        
        fprintf(file,"%i,%i,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f\n", unmatched, quickmatch_steps, quickmatch_time, bfs_steps/unmatchedFloat, bfs2bfs_steps/unmatchedFloat, dfs2bfs_steps/unmatchedFloat, dfs2dfs_steps/unmatchedFloat, dfs_steps/unmatchedFloat, hopcroft_steps/unmatchedFloat, bfs_time, dfs_time, bfs2bfs_time, dfs2bfs_time, dfs2dfs_time, hopcroft_time);
    
        cur_time = (long) time(NULL);
        if (time(NULL) >= last_flush + FLUSH_TIME) {
            fflush(file);
            last_flush = cur_time;
        }

        // Free
        freeGraph(graph);
        free(matching);
        free(matching1);
        free(matching2);
        free(matching3);
        free(matching4);
        free(matching5);
        free(matching6);
        free(right_sides);
        //free(visited);
        //free(targets);
    }
    fclose(file); 
}
Exemplo n.º 15
0
void NodeGraph::setPreset(NodeGraphPreset preset, int sample_rate)
{
	AStatus status;

	StaticMidiBufferNode	*mainMidiBuf;
	InstrumentNode			*instrument1,
							*instrument2;
	RenderNode				*mainRender;
	DynamicAudioBufferNode	*mainAudioBuf,
							*audioBuf2;
	SpeakerNode				*mainSpeaker;
	MicrophoneNode			*mainMic;

	MidiDeviceNode			*mainDevice;

	RenderNode				*render2;

	std::unique_ptr<Node>					mainMidiBuf_ptr,
											instrument1_ptr,
											instrument2_ptr,
											mainRender_ptr,
											mainAudioBuf_ptr,
											audioBuf2_ptr,
											mainSpeaker_ptr,
											mainMic_ptr,
											mainDevice_ptr,
											render2_ptr;

	MidiData notes;	//For testing

	
	resetGraph();
	//initialPos = &presetPositions[toIndex(preset)];


	switch(preset)
	{
	//Empty graph (do nothing)
	case NodeGraphPreset::EMPTY:
		break;

	//Initial NodeGraph for a new sandbox
	case NodeGraphPreset::SANDBOX:

		//Preset Nodes
		instrument1 = new InstrumentNode(this);
		mainRender = new RenderNode(this, sample_rate);
		mainSpeaker = new SpeakerNode(this, 0, sample_rate, SPEAKER_BUFFER_SIZE, nullptr);
		mainMic = new MicrophoneNode(this, 4, sample_rate, MIC_BUFFER_SIZE);
		mainDevice = new MidiDeviceNode(this, midi_port);	//TODO: Choose port with gui
		
		//Add nodes to list
		addNode(mainDevice, Point2f(-200.0f, -25.0f));
		addNode(mainRender, Point2f(-50.0f, -25.0f));
		addNode(instrument1, Point2f(-50.0f, -175.0f));
		addNode(mainSpeaker, Point2f(100.0f, -25.0f));
		addNode(mainMic,	Point2f(-100.0f, 75.0f));

		//Preset Connections
		//Node::connect(mainDevice->OUTPUTS.MIDI_ID, mainRender->INPUTS.MIDI_ID);
		//Node::connect(instrument1->OUTPUTS.INSTRUMENT_ID, mainRender->INPUTS.INSTRUMENT_ID);
		//Node::connect(mainRender->OUTPUTS.AUDIO_ID, mainSpeaker->INPUTS.AUDIO_ID);

		makeNewConnection(mainDevice->OUTPUTS.MIDI_ID, mainRender->INPUTS.MIDI_ID);
		makeNewConnection(instrument1->OUTPUTS.INSTRUMENT_ID, mainRender->INPUTS.INSTRUMENT_ID);
		makeNewConnection(mainRender->OUTPUTS.AUDIO_ID, mainSpeaker->INPUTS.AUDIO_ID);
		
		break;

	//Initial NodeGraph for a new project
	case NodeGraphPreset::PROJECT:
		//Preset Nodes
		mainMidiBuf = new StaticMidiBufferNode(this);
		instrument1 = new InstrumentNode(this);
		mainRender = new RenderNode(this, sample_rate);
		mainAudioBuf = new DynamicAudioBufferNode(this, sample_rate, 1000);
		mainSpeaker = new SpeakerNode(this, 0, sample_rate, SPEAKER_BUFFER_SIZE, nullptr);
		mainMic = new MicrophoneNode(this, 3, sample_rate, MIC_BUFFER_SIZE);

		//timeMap = new TimeMapNode(sample_rate);

		mainDevice = new MidiDeviceNode(this, midi_port);
		instrument2 = new InstrumentNode(this);
		render2 = new RenderNode(this, sample_rate);
		//audioBuf2 = new AudioTrackNode(sample_rate);
		
		//Add nodes to list
		addNode(mainMidiBuf, Point2f(-300.0f, -25.0f));
		addNode(instrument1, Point2f(-137.5f, -175.0f));
		addNode(mainRender, Point2f(-150.0f, -75.0f));
		addNode(mainAudioBuf, Point2f(-25.0f, -75.0f));
		addNode(mainSpeaker, Point2f(250.0f, -25.0f));
		addNode(mainMic,	Point2f(-100.0f, 75.0f));

		//addNode(timeMap, Point2f(100.0f, -25.0f));

		addNode(mainDevice, Point2f(-300.0f, 150.0f));
		addNode(instrument2, Point2f(-137.5f, 25.0f));
		addNode(render2, Point2f(-150.0f, 150.0f));
		//addNode(audioBuf2, Point2f(-25.0f, 150.0f));


		//Preset Connections
		makeNewConnection(mainMidiBuf->OUTPUTS.MIDI_ID, mainRender->INPUTS.MIDI_ID);
		makeNewConnection(instrument1->OUTPUTS.INSTRUMENT_ID, mainRender->INPUTS.INSTRUMENT_ID);
		makeNewConnection(mainRender->OUTPUTS.AUDIO_ID, mainAudioBuf->INPUTS.AUDIO_ID);
		makeNewConnection(mainAudioBuf->OUTPUTS.AUDIO_ID, mainSpeaker->INPUTS.AUDIO_ID);
		//timeMap->connect(timeMap->OUTPUTS.AUDIO_ID, mainSpeaker->INPUTS.AUDIO_ID);
		
		makeNewConnection(mainDevice->OUTPUTS.MIDI_ID, render2->INPUTS.MIDI_ID);
		makeNewConnection(instrument2->OUTPUTS.INSTRUMENT_ID, render2->INPUTS.INSTRUMENT_ID);
		makeNewConnection(render2->OUTPUTS.AUDIO_ID, mainSpeaker->INPUTS.AUDIO_ID);


		////ADD TEST NOTES (Legend of Zelda Main Theme)////
		//legendOfZeldaTheme1.interpret(notes, 0.0, 30);
		//legendOfZeldaTheme2.interpret(notes, 0.0, 30, 100);
		//notes.addNote(MidiNote(-1, 0, 0.0, 100.0));	//100-second long rest (empty)
		//mainMidiBuf->setBuffer(notes);

		mainMidiBuf->setLength(360.0);
		mainAudioBuf->setLength((c_time)(mainMidiBuf->getLength()*(Time)((double)sample_rate/(double)AUDIO_CHUNK_SIZE)));

		break;

	default:	//NODEGRAPH_PRESET_INVALID
		//Error
		break;
	}
}
Exemplo n.º 16
0
std::vector<int> LDPCDecoder::decode(std::vector<double> llr,
		boost::numeric::ublas::matrix<double> &errors, int counter,
		std::vector<int> uncoded) {
	if (n != llr.size()) {
		std::stringstream str;
		str << "Invalid input size";
		throw std::invalid_argument(str.str());
	}

	//LLR variable node initialization
	for (int i = 0; i < n; i++) {
		received.at(i)->setValue(llr.at(i));
		if (DEBUG) {
			std::cout << llr.at(i) << " ";
		}
	}
	if (DEBUG) {
		std::cout << " LLR\n";
	}

	//Message passing (stops when Hc=0 or after a max number of cycles)
	int pass = 0;
	bool check = false; //parityCheck();
	while (!check && pass < passes) {
		forwardPassing();
		if (DEBUG) {
			for (int i = 0; i < k; i++) {
				std::cout << parity.at(i)->getValue() << " ";
			}
			std::cout << "LLR (check)\n";
		}
		backwardPassing();
		if (DEBUG) {
			for (int i = 0; i < n; i++) {
				std::cout << received.at(i)->getValue() << " ";
			}
			std::cout << "LLR (var)\n";
		}
		//check = parityCheck();
		pass += 2;

		if (!parityCheck()) {
			errors(counter, pass / 2)++;

			}
		else {
			for (int i = 0; i < k; i++) {
				double in = received.at(i)->getValue();
				if (received.at(i)->llr2val(in) != uncoded.at(i)) {
					errors(counter, pass / 2)++;break
;				}
			}
		}
		errors(0, 0)++;}

		//Decoded vector
	std::vector<int> decoded;
	for (int i = 0; i < n; i++) {
		double in = received.at(i)->getValue();
		decoded.push_back(received.at(i)->llr2val(in));
	}
	resetGraph();

	return decoded;
}
Exemplo n.º 17
0
void main(void) 
{
    int an3now;
    int an3max = 0;
    char key;
    char eepromloc = 0;
    int eepromval;
    int eeprommax;
    char graphclear = 1;

    Glcd_Init();
    
    Sm_Glcd_Out2(57, 67, "H.S.B V1.0");
    Sm_Glcd_Out2(51, 1, "AN3:");
    Sm_Glcd_Out2(37, 1, "ROM:");
    Sm_Glcd_Out2(0, 1, "MIN");
    Sm_Glcd_Out2(10, 1, "MAX");
    Sm_Glcd_Out2(20, 1, "MEAN");
    
    //Lines for graph
    Glcd_H_Line(62, 126, 32, 1);
    Glcd_V_Line(0,32,62,1);
    
    ADCON1 = 0;
    
    eepromval = getAn3(eepromloc);
    showEepromval(eepromval,eeprommax);
    an3now = ADC_Read(3);
    intOut(26, 51, an3now);

    while(1)
    {
        an3max = an3now;
        eeprommax = eepromval;
        an3now = ADC_Read(3);

        key = scanKeypad();

        if(key == 1) //store an3 value
        {
            storeAn3(eepromloc, an3now);
            eepromval = an3now;
        }
        if(key == 2) //switch eeprom bank and return value
        {
            if(eepromloc == 0) eepromloc = 16;
            else if(eepromloc == 16) eepromloc = 32;
            else if(eepromloc == 32) eepromloc = 0;
            eepromval = getan3(eepromloc);
        }
        if(key == 4 && graphclear == 1) //run graph if it is clear
        {
            graphclear = 0;
            runGraph();
        }
        if(key == 5 && graphclear == 0) //clear graph if it has been run
        {
            graphclear = 1;
            resetGraph();
        }
        key = 0;
        
        if(an3now != an3max)
        {
            intOut(26, 51, an3now);
            printBar(0, 59, an3now, an3max);
        }
        
        showEepromval(eepromval, eeprommax);
    }
}