// {{{ elapsedTime stat_t elapsedTime (int n, int m, int c, int nb_iter) { int i=0; stat_t result; GTimer *timer = g_timer_new(); memset(&result, 0, sizeof(stat_t)); for (i=0; i< nb_iter; i++) { // Graph Initialization Graph * lcLab = allocListGraph(n); Graph * lcFIFO = allocListGraph(n); randFill(lcLab,m,c,1,lcFIFO); Graph *lcDinic = copyGraph(lcLab); int f,g,h; // FIFO Algorithm Graph * lfFIFO = allocGraph(lcFIFO); Graph * ldFIFO = copyGraph(lcFIFO); // printf ("Entrée FIFO\n"); g_timer_start(timer); h=algoFIFO (lcFIFO,ldFIFO,lfFIFO,0,1); g_timer_stop(timer); // printf ("Sortie FIFO\n"); freeGraph(ldFIFO); freeGraph(lfFIFO); if (h) { result._st1 += (double) g_timer_elapsed(timer, NULL); g_timer_reset(timer); // High Label Algorithm Graph * lfLab = allocGraph(lcLab); Graph * ldLab = copyGraph(lcLab); // printf ("Entrée High Label\n"); g_timer_start(timer); g=algoLabel (lcLab,ldLab,lfLab,0,1); g_timer_stop(timer); result._st2 += (double) g_timer_elapsed(timer, NULL); g_timer_reset(timer); // printf ("Sortie High Label\n"); freeGraph(lfLab); freeGraph(ldLab); // Dinic Algorithm Graph * lfDinic = allocGraph(lcLab); // printf("Entrée Dinic\n"); g_timer_start(timer); f=algoDinic (lcDinic,lfDinic,0,1); g_timer_stop(timer); result._st3 += (double) g_timer_elapsed(timer, NULL); g_timer_reset(timer); // printf("Sortie Dinic\n"); freeGraph (lfDinic); } else { printf ("Flot nul.\n"); g_timer_reset(timer); i --; } freeGraph (lcFIFO); freeGraph (lcLab); freeGraph (lcDinic); } result._st1 /= nb_iter; result._st2 /= nb_iter; result._st3 /= nb_iter; result._st4 /= nb_iter; g_timer_destroy(timer); return result; }
t_cflow_Graph * createFlowGraph(t_list *instructions) { t_cflow_Graph *result; t_basic_block *bblock; t_list *current_element; t_cflow_Node *current_node; t_axe_instruction *current_instr; int startingNode; int endingNode; /* initialize the global variable `cflow_errorcode' */ cflow_errorcode = CFLOW_OK; /* preconditions */ if (instructions == NULL){ cflow_errorcode = CFLOW_INVALID_PROGRAM_INFO; return NULL; } /* alloc memory for a new control flow graph */ result = allocGraph(); if (result == NULL) return NULL; /* set the starting basic block */ bblock = NULL; /* initialize the current element */ current_element = instructions; while(current_element != NULL) { /* retrieve the current instruction */ current_instr = (t_axe_instruction *) LDATA(current_element); assert(current_instr != NULL); if (isLoadInstruction(current_instr)) { current_element = LNEXT(current_element); continue; } /* create a new node for the current basic block */ current_node = allocNode(result, current_instr); if (current_node == NULL){ finalizeGraph(result); return NULL; } /* test if the current instruction will start or end a block */ startingNode = isStartingNode(current_instr); endingNode = isEndingNode(current_instr); if (startingNode || bblock == NULL) { /* alloc a new basic block */ bblock = allocBasicBlock(); if (bblock == NULL) { finalizeGraph(result); finalizeNode(current_node); return NULL; } /* add the current instruction to the newly created * basic block */ insertNode(bblock, current_node); if (cflow_errorcode != CFLOW_OK) { finalizeGraph(result); finalizeNode(current_node); finalizeBasicBlock(bblock); return NULL; } /* add the new basic block to the control flow graph */ insertBlock(result, bblock); if (cflow_errorcode != CFLOW_OK) { finalizeGraph(result); finalizeNode(current_node); finalizeBasicBlock(bblock); return NULL; } } else { /* add the current instruction to the current * basic block */ insertNode(bblock, current_node); if (cflow_errorcode != CFLOW_OK) { finalizeGraph(result); finalizeNode(current_node); return NULL; } } if (endingNode) bblock = NULL; /* retrieve the next element */ current_element = LNEXT(current_element); } /* update the basic blocks chain */ updateFlowGraph(result); if (cflow_errorcode != CFLOW_OK) { finalizeGraph(result); return NULL; } /*return the graph */ return result; }
int main(int argc, char *argv[]){ int nbedge = 13; Edge** edges = malloc((nbedge+1)*(sizeof (Edge*))); Edge* A = malloc(sizeof(Edge)); A->origin = 1; A->dest = 2; A->couleur = -1; A->oriente = 0; edges[0] = A; Edge* B = malloc(sizeof(Edge)); B->origin = 2; B->dest = 6; B->couleur = -1; B->oriente = 0; edges[1] = B; Edge* C = malloc(sizeof(Edge)); C->origin = 1; C->dest = 6; C->couleur = -1; C->oriente = 0; edges[2] = C; Edge* D = malloc(sizeof(Edge)); D->origin = 2; D->dest = 4; D->couleur = -1; D->oriente = 0; edges[3] = D; Edge* E = malloc(sizeof(Edge)); E->origin = 4; E->dest = 6; E->couleur = -1; E->oriente = 0; edges[4] = E; Edge* F = malloc(sizeof(Edge)); F->origin = 6; F->dest = 8; F->couleur = -1; F->oriente = 0; edges[5] = F; Edge* G = malloc(sizeof(Edge)); G->origin = 1; G->dest = 8; G->couleur = -1; G->oriente = 0; edges[6] = G; Edge* H = malloc(sizeof(Edge)); H->origin = 2; H->dest = 3; H->couleur = -1; H->oriente = 0; edges[7] = H; Edge* I = malloc(sizeof(Edge)); I->origin = 3; I->dest = 4; I->couleur = -1; I->oriente = 0; edges[8] = I; Edge* J = malloc(sizeof(Edge)); J->origin = 4; J->dest = 5; J->couleur = -1; J->oriente = 0; edges[9] = J; Edge* K = malloc(sizeof(Edge)); K->origin = 6; K->dest = 5; K->couleur = -1; K->oriente = 0; edges[10] = K; Edge* L = malloc(sizeof(Edge)); L->origin = 6; L->dest = 7; L->couleur = -1; L->oriente = 0; edges[11] = L; Edge* M = malloc(sizeof(Edge)); M->origin = 7; M->dest = 8; M->couleur = -1; M->oriente = 0; edges[12] = M; edges[13] = NULL; Graph* T = malloc(sizeof(Graph)); allocGraph(edges, T, 8); Graph** tabT = enumTriang(8); FILE* desc = fopen(name,"w"); beginDocument(desc); enumGraph(desc, tabT); endDocument(desc); }