X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=lttv%2Flttv%2Fsync%2Fevent_analysis_eval.c;h=4aa6a7a5ef3b87ad974f693de4da6929daedfdff;hb=b2da0724a95cdb911c07640268b65bd9c5b92010;hp=ff75bc1e65706788e8b9cbdf8e629df1554d9426;hpb=2849af52e33404e75e2a16468e50ff77c95aef0c;p=lttv.git diff --git a/lttv/lttv/sync/event_analysis_eval.c b/lttv/lttv/sync/event_analysis_eval.c index ff75bc1e..4aa6a7a5 100644 --- a/lttv/lttv/sync/event_analysis_eval.c +++ b/lttv/lttv/sync/event_analysis_eval.c @@ -65,7 +65,7 @@ static void analyzeExchangeEval(SyncState* const syncState, Exchange* const exchange); static void analyzeBroadcastEval(SyncState* const syncState, Broadcast* const broadcast); -static GArray* finalizeAnalysisEval(SyncState* const syncState); +static AllFactors* finalizeAnalysisEval(SyncState* const syncState); static void printAnalysisStatsEval(SyncState* const syncState); static void writeAnalysisTraceTimeBackPlotsEval(SyncState* const syncState, const unsigned int i, const unsigned int j); @@ -117,9 +117,13 @@ static glp_prob* lpCreateProblem(GQueue* const lowerHull, GQueue* const upperHull); static void gfLPAddRow(gpointer data, gpointer user_data); static Factors* calculateFactors(glp_prob* const lp, const int direction); -static void calculateCompleteFactors(glp_prob* const lp, FactorsCHull* +static void calculateCompleteFactors(glp_prob* const lp, PairFactors* factors); -static FactorsCHull** createAllFactors(const unsigned int traceNb); +static inline void finalizeAnalysisEvalLP(SyncState* const syncState); +static void gfAddAbsiscaToArray(gpointer data, gpointer user_data); +static gint gcfCompareDouble(gconstpointer a, gconstpointer b); +#else +static void finalizeAnalysisEvalLP(SyncState* const syncState); #endif @@ -553,8 +557,8 @@ static void destroyAnalysisEval(SyncState* const syncState) g_hash_table_destroy(stats->exchangeRtt); #ifdef HAVE_LIBGLPK - freeAllFactors(syncState->traceNb, stats->chFactorsArray); - freeAllFactors(syncState->traceNb, stats->lpFactorsArray); + freeAllFactors(stats->chFactorsArray, syncState->traceNb); + freeAllFactors(stats->lpFactorsArray, syncState->traceNb); #endif free(stats); @@ -592,7 +596,7 @@ static void destroyAnalysisEval(SyncState* const syncState) if (!syncState->stats) { - freeAllFactors(syncState->traceNb, graphs->lpFactorsArray); + freeAllFactors(graphs->lpFactorsArray, syncState->traceNb); } #endif @@ -891,19 +895,17 @@ static void analyzeBroadcastEval(SyncState* const syncState, Broadcast* const /* * Finalize the factor calculations. Since this module does not really - * calculate factors, identity factors are returned. Instead, histograms are + * calculate factors, absent factors are returned. Instead, histograms are * written out and histogram structures are freed. * * Args: * syncState container for synchronization data. * * Returns: - * Factors[traceNb] identity factors for each trace + * AllFactors* synchronization factors for each trace pair */ -static GArray* finalizeAnalysisEval(SyncState* const syncState) +static AllFactors* finalizeAnalysisEval(SyncState* const syncState) { - GArray* factors; - unsigned int i; AnalysisDataEval* analysisData= syncState->analysisData; if (syncState->graphsStream && analysisData->graphs->histograms) @@ -917,19 +919,7 @@ static GArray* finalizeAnalysisEval(SyncState* const syncState) finalizeAnalysisEvalLP(syncState); - factors= g_array_sized_new(FALSE, FALSE, sizeof(Factors), - syncState->traceNb); - g_array_set_size(factors, syncState->traceNb); - for (i= 0; i < syncState->traceNb; i++) - { - Factors* e; - - e= &g_array_index(factors, Factors, i); - e->drift= 1.; - e->offset= 0.; - } - - return factors; + return createAllFactors(syncState->traceNb); } @@ -1043,13 +1033,15 @@ static void printAnalysisStatsEval(SyncState* const syncState) { for (j= 0; j < i; j++) { - FactorsCHull* chFactors= &analysisData->stats->chFactorsArray[i][j]; - FactorsCHull* lpFactors= &analysisData->stats->lpFactorsArray[i][j]; + PairFactors* chFactors= + &analysisData->stats->chFactorsArray->pairFactors[i][j]; + PairFactors* lpFactors= + &analysisData->stats->lpFactorsArray->pairFactors[i][j]; printf("\t\t%3d - %-3d ", i, j); if (lpFactors->type == chFactors->type) { - if (lpFactors->type == MIDDLE) + if (lpFactors->type == ACCURATE) { printf("%-13s %-10.4g %-10.4g %-10.4g %.4g\n", approxNames[lpFactors->type], @@ -1716,18 +1708,18 @@ static Factors* calculateFactors(glp_prob* const lp, const int direction) * initialized. * * Returns: - * Please note that the approximation type may be MIDDLE, INCOMPLETE or + * Please note that the approximation type may be ACCURATE, INCOMPLETE or * ABSENT. Unlike in analysis_chull, ABSENT is also used when the hulls do * not respect assumptions. */ -static void calculateCompleteFactors(glp_prob* const lp, FactorsCHull* factors) +static void calculateCompleteFactors(glp_prob* const lp, PairFactors* factors) { factors->min= calculateFactors(lp, GLP_MIN); factors->max= calculateFactors(lp, GLP_MAX); if (factors->min && factors->max) { - factors->type= MIDDLE; + factors->type= ACCURATE; calculateFactorsMiddle(factors); } else if (factors->min || factors->max) @@ -1744,31 +1736,48 @@ static void calculateCompleteFactors(glp_prob* const lp, FactorsCHull* factors) /* - * Create and initialize an array like AnalysisStatsCHull.allFactors + * A GFunc for g_queue_foreach() + * + * Args: + * data Point*, a convex hull point + * user_data GArray*, an array of convex hull point absisca values, as + * double + */ +static void gfAddAbsiscaToArray(gpointer data, gpointer user_data) +{ + Point* p= data; + GArray* a= user_data; + double v= p->x; + + g_array_append_val(a, v); +} + + +/* + * A GCompareFunc for g_array_sort() * * Args: - * traceNb: number of traces + * a, b double*, absisca values * * Returns: - * A new array, which can be freed with freeAllFactors() + * "returns less than zero for first arg is less than second arg, zero for + * equal, greater zero if first arg is greater than second arg" + * - the great glib documentation */ -static FactorsCHull** createAllFactors(const unsigned int traceNb) +static gint gcfCompareDouble(gconstpointer a, gconstpointer b) { - FactorsCHull** factorsArray; - unsigned int i; - - factorsArray= malloc(traceNb * sizeof(FactorsCHull*)); - for (i= 0; i < traceNb; i++) + if (*(double*) a < *(double*) b) { - factorsArray[i]= calloc((i + 1), sizeof(FactorsCHull)); - - factorsArray[i][i].type= EXACT; - factorsArray[i][i].approx= malloc(sizeof(Factors)); - factorsArray[i][i].approx->drift= 1.; - factorsArray[i][i].approx->offset= 0.; + return -1; + } + else if (*(double*) a > *(double*) b) + { + return 1; + } + else + { + return 0; } - - return factorsArray; } #endif @@ -1790,7 +1799,7 @@ static void finalizeAnalysisEvalLP(SyncState* const syncState) #ifdef HAVE_LIBGLPK unsigned int i, j; AnalysisDataCHull* chAnalysisData= analysisData->chullSS->analysisData; - FactorsCHull** lpFactorsArray; + AllFactors* lpFactorsArray; if (!syncState->stats && !syncState->graphsStream) { @@ -1837,7 +1846,7 @@ static void finalizeAnalysisEvalLP(SyncState* const syncState) // Use the LP problem to find the correction factors for this pair of // traces - calculateCompleteFactors(lp, &lpFactorsArray[i][j]); + calculateCompleteFactors(lp, &lpFactorsArray->pairFactors[i][j]); if (syncState->graphsStream) { @@ -1851,8 +1860,8 @@ static void finalizeAnalysisEvalLP(SyncState* const syncState) } #endif - g_array_free(analysisData->chullSS->analysisModule->finalizeAnalysis(analysisData->chullSS), - TRUE); + freeAllFactors(analysisData->chullSS->analysisModule->finalizeAnalysis(analysisData->chullSS), + analysisData->chullSS->traceNb); } @@ -1878,19 +1887,16 @@ static void writeAnalysisTraceTimeBackPlotsEval(SyncState* const syncState, AnalysisGraphsEval* graphs= analysisData->graphs; GQueue*** hullArray= ((AnalysisDataCHull*) analysisData->chullSS->analysisData)->hullArray; - FactorsCHull* lpFactors= &graphs->lpFactorsArray[j][i]; + PairFactors* lpFactors= &graphs->lpFactorsArray->pairFactors[j][i]; glp_prob* lp= graphs->lps[j][i]; - if (lpFactors->type == MIDDLE) + if (lpFactors->type == ACCURATE) { int retval; char* cwd; char fileName[40]; FILE* fp; - double* xValues; - unsigned int xBegin, xEnd; - double interval; - const unsigned int graphPointNb= 1000; + GArray* xValues; // Open the data file snprintf(fileName, 40, "analysis_eval_accuracy-%03u_and_%03u.data", i, j); @@ -1912,51 +1918,27 @@ static void writeAnalysisTraceTimeBackPlotsEval(SyncState* const syncState, free(cwd); // Build the list of absisca values for the points in the accuracy graph - g_assert_cmpuint(graphPointNb, >=, 4); - xValues= malloc(graphPointNb * sizeof(double)); - xValues[0]= graphs->bounds[j][i].min; - xValues[graphPointNb - 1]= graphs->bounds[j][i].max; - xValues[1]= MIN(((Point*) g_queue_peek_head(hullArray[i][j]))->x, - ((Point*) g_queue_peek_head(hullArray[j][i]))->x); - xValues[graphPointNb - 2]= MAX(((Point*) - g_queue_peek_tail(hullArray[i][j]))->x, ((Point*) - g_queue_peek_tail(hullArray[j][i]))->x); - - if (xValues[0] == xValues[1]) - { - xBegin= 0; - } - else - { - xBegin= 1; - } - if (xValues[graphPointNb - 2] == xValues[graphPointNb - 1]) - { - xEnd= graphPointNb - 1; - } - else - { - xEnd= graphPointNb - 2; - } - interval= (xValues[xEnd] - xValues[xBegin]) / (graphPointNb - 1); + xValues= g_array_sized_new(FALSE, FALSE, sizeof(double), + g_queue_get_length(hullArray[i][j]) + + g_queue_get_length(hullArray[j][i])); - for (it= xBegin; it <= xEnd; it++) - { - xValues[it]= xValues[xBegin] + interval * (it - xBegin); - } + g_queue_foreach(hullArray[i][j], &gfAddAbsiscaToArray, xValues); + g_queue_foreach(hullArray[j][i], &gfAddAbsiscaToArray, xValues); + + g_array_sort(xValues, &gcfCompareDouble); /* For each absisca value and each optimisation direction, solve the LP * and write a line in the data file */ - for (it= 0; it < graphPointNb; it++) + for (it= 0; it < xValues->len; it++) { unsigned int it2; int directions[]= {GLP_MIN, GLP_MAX}; glp_set_obj_coef(lp, 1, 1.); - glp_set_obj_coef(lp, 2, xValues[it]); + glp_set_obj_coef(lp, 2, g_array_index(xValues, double, it)); - fprintf(fp, "%25.9f %25.9f", xValues[it], + fprintf(fp, "%25.9f %25.9f", g_array_index(xValues, double, it), lpFactors->approx->offset + lpFactors->approx->drift * - xValues[it]); + g_array_index(xValues, double, it)); for (it2= 0; it2 < sizeof(directions) / sizeof(*directions); it2++) { int status; @@ -1971,7 +1953,7 @@ static void writeAnalysisTraceTimeBackPlotsEval(SyncState* const syncState, fprintf(fp, "\n"); } - free(xValues); + g_array_free(xValues, TRUE); fclose(fp); fprintf(syncState->graphsStream, @@ -2002,8 +1984,8 @@ static void writeAnalysisTraceTimeForePlotsEval(SyncState* const syncState, { #ifdef HAVE_LIBGLPK if (((AnalysisDataEval*) - syncState->analysisData)->graphs->lpFactorsArray[j][i].type == - MIDDLE) + syncState->analysisData)->graphs->lpFactorsArray->pairFactors[j][i].type + == ACCURATE) { fprintf(syncState->graphsStream, "\t\"analysis_eval_accuracy-%1$03u_and_%2$03u.data\" "