From 95f6f838675326304947cd048c709e3a458cf0cb Mon Sep 17 00:00:00 2001 From: Raphael Boucherie <raphael.boucherie@inria.fr> Date: Thu, 27 Apr 2017 18:38:50 +0200 Subject: [PATCH] updated treewalk and the test --- include/libhqr.h | 9 ++-- src/treewalk.c | 96 ++++++++++++++++++++++++------------- testings/draw_hqr.c | 2 +- testings/draw_systolic.c | 2 +- testings/testing_tileinit.c | 2 +- 5 files changed, 72 insertions(+), 39 deletions(-) diff --git a/include/libhqr.h b/include/libhqr.h index 4f95775..f255fb5 100644 --- a/include/libhqr.h +++ b/include/libhqr.h @@ -226,10 +226,11 @@ void libhqr_matrix_finalize(libhqr_tree_t *qrtree); * function for drawing the tree */ -void libhqr_treewalk(const libhqr_tree_t *qrtree,int k, int *tiles, FILE *file); -void draw_rectangle(int k, int p, int m, int *tiles, FILE *file); -void draw_horizontal_line(int k, int p, int m, int *tiles, FILE *file); -void draw_vertical_line(int k, int p, int m, int *tiles, FILE *file); +void libhqr_treewalk(const libhqr_tree_t *qrtree, int k, int *tiles); +void draw_rectangle(int k, int p, int m, int step_m, FILE *file); +void draw_lines(const libhqr_tree_t *qrtree, int k, int *tiles, int *step, FILE *file); +void draw_horizontal_line(int k, int p, int m, int step_p, int step_m, FILE *file); +void draw_vertical_line(int k, int p, int m, int step_m, FILE *file); void libhqr_print_tree(const libhqr_tree_t *qrtree, libhqr_tiledesc_t *matrix); /* diff --git a/src/treewalk.c b/src/treewalk.c index 4643048..9f741a8 100644 --- a/src/treewalk.c +++ b/src/treewalk.c @@ -23,7 +23,7 @@ #include <string.h> /* - * Common prameters to the 2 following functions: + * Common prameters to the 3 following functions: * k - Factorization step for the color * p - annihilator * m - tile eliminated @@ -31,38 +31,63 @@ * tiles - table stocking the tiles */ -void draw_horizontal_line(int k, int p, int m, int *tiles, FILE *file){ - int y, ordinate1, ordinate2, absciss1, absciss2, absciss3, absciss4; - ordinate1 = SIZE + SIZE * m; - ordinate2 = SIZE + SIZE * p; - absciss1 = (SIZE + (SIZE / 4)) + SIZE * tiles[m]; - absciss3 = (SIZE + (SIZE / 4)) + SIZE * tiles[p]; - /* Increasing the step */ - y = libhqr_imax(tiles[m], tiles[p]) + 1; - tiles[m] = tiles[p] = y; - absciss2 = (SIZE + (SIZE / 4)) + SIZE * tiles[m]; - absciss4 = (SIZE + (SIZE / 4)) + SIZE * tiles[p]; - libhqr_drawline( absciss1, ordinate1, absciss2, ordinate1, k, file); - libhqr_drawline( absciss3, ordinate2, absciss4, ordinate2, k, file); +void draw_horizontal_line(int k, int p, int m, int step_p, int step_m, FILE *file){ + int yp, ym; + int x, xp, xm; + + /* Row of the tiles */ + ym = SIZE + SIZE * m; + yp = SIZE + SIZE * p; + + /* Starting position of the tiles */ + xm = (SIZE + (SIZE / 4)) + SIZE * step_m; + xp = (SIZE + (SIZE / 4)) + SIZE * step_p; + + /* Final position of the tiles */ + x = libhqr_imax(step_m, step_p) + 1; + x = (SIZE + (SIZE / 4)) + SIZE * x; + + libhqr_drawline( xm, ym, x, ym, k, file ); + libhqr_drawline( xp, yp, x, yp, k, file ); } -void draw_vertical_line(int k, int p, int m, int *tiles, FILE *file){ - int absciss, ordinate1, ordinate2; - absciss = SIZE + SIZE * tiles[m]; - ordinate1 = SIZE + SIZE * m; - ordinate2 = SIZE + SIZE * p; - libhqr_drawline(absciss, ordinate1, absciss, ordinate2, k, file); +void draw_vertical_line(int k, int p, int m, int step_m, FILE *file){ + int absciss, ym, yp; + absciss = SIZE + SIZE * step_m; + ym = SIZE + SIZE * m; + yp = SIZE + SIZE * p; + libhqr_drawline(absciss, ym, absciss, yp, k, file); } -void draw_rectangle(int k, int p, int m, int *tiles, FILE *file){ +void draw_rectangle(int k, int p, int m, int step_m, FILE *file){ int absciss, ordinate; - absciss = ((SIZE * 3) /4) + SIZE * tiles[m]; + absciss = ((SIZE * 3) /4) + SIZE * step_m; ordinate = ((SIZE * 3) /4) + SIZE * m; libhqr_drawTS(absciss, ordinate, WIDTH, HEIGHT, k, file); ordinate = ((SIZE * 3) /4) + SIZE * p; libhqr_drawTT(absciss, ordinate, WIDTH, HEIGHT, k, file); } +void draw_lines(const libhqr_tree_t *qrtree, int k, int *tiles, int *step, FILE *file){ + int i, m, p, tmp; + + /* Get order for step k */ + libhqr_treewalk(qrtree, k, tiles); + + /* Draw lines */ + for(i = k; i < (qrtree->mt-1); i++){ + m = tiles[i]; + p = qrtree->currpiv(qrtree, k, m); + + draw_horizontal_line(k, p, m, step[p], step[m], file); + + tmp = libhqr_imax( step[p], step[m] ) + 1; + step[m] = tmp; + step[p] = tmp; + draw_vertical_line(k, p, m, tmp, file); + } +} + /**************************************************** * LIBHQR_TREEWALK ***************************************************/ @@ -77,17 +102,15 @@ void draw_rectangle(int k, int p, int m, int *tiles, FILE *file){ * Factorization step * * @param[in] tiles - * Table stocking the tiles and their step - * - * @param[in] file - * File where the tree is drawn + * Table stocking the tiles and their step in the order they are killed * */ -void libhqr_treewalk(const libhqr_tree_t *qrtree, int k, int *tiles, FILE *file) +void libhqr_treewalk(const libhqr_tree_t *qrtree, int k, int *tiles) { int tsid = -1, ttid = -1; int p = k; int pivot = k; + int m = k; libhqr_queue_tile_t *tt = libhqr_queue_tile_new(); libhqr_queue_tile_t *ts = libhqr_queue_tile_new(); libhqr_queue_tile_push(&tt, k); @@ -121,13 +144,15 @@ void libhqr_treewalk(const libhqr_tree_t *qrtree, int k, int *tiles, FILE *file) /* printf("POP TS: %d\n", tsid); */ /* printf("Call function on (%d, %d)\n", qrtree->currpiv(qrtree, k, tsid), tsid ); */ - draw_horizontal_line(k, qrtree->currpiv(qrtree, k, tsid), tsid, tiles, file); - draw_vertical_line(k, qrtree->currpiv(qrtree, k, tsid), tsid, tiles, file); + assert(m < (qrtree->mt-1)); + tiles[m] = tsid; + m++; tsid = libhqr_queue_tile_head(&ts); } pivot = p = ttid; } + assert(m == (qrtree->mt-1)); assert(ts == NULL); assert(tt == NULL); } @@ -137,21 +162,28 @@ void libhqr_treewalk(const libhqr_tree_t *qrtree, int k, int *tiles, FILE *file) ***************************************************/ void libhqr_print_tree(const libhqr_tree_t *qrtree, libhqr_tiledesc_t *matrix){ - int maxMN, minMN, k, i; + int maxMN, minMN, k, i, step_m; int *tiles; + int *step; FILE *file; + maxMN = libhqr_imax(matrix->mt, matrix->nt ); minMN = libhqr_imin(matrix->mt, matrix->nt ); + tiles = (int*)malloc(maxMN*sizeof(int)); memset( tiles, 0, maxMN*sizeof(int) ); + + step = (int*) malloc( qrtree->mt * sizeof(int) ); + memset( step, 0, qrtree->mt * sizeof(int) ); + file = fopen("tree.svg","w+"); libhqr_writeheader(file); for (k = 0; k < minMN; k++){ /* Drawing the lines */ - libhqr_treewalk(qrtree, k, tiles, file); + draw_lines(qrtree, k, tiles, step, file); /* Drawing the rectangles */ for (i = k + 1; i < maxMN; i++){ - draw_rectangle(k, qrtree->currpiv(qrtree, k, i), i, tiles, file); + draw_rectangle(k, qrtree->currpiv(qrtree, k, i), i, step[i], file); } } libhqr_writeend(file); diff --git a/testings/draw_hqr.c b/testings/draw_hqr.c index 7a515c3..18b1bc9 100644 --- a/testings/draw_hqr.c +++ b/testings/draw_hqr.c @@ -38,7 +38,7 @@ main(int argc, char ** argv) libhqr_hqr_init( &qrtree, LIBHQR_QR, &matrix, llvl, hlvl, qr_a, qr_p, domino, tsrr ); libhqr_print_tree( &qrtree, &matrix ); - libhqr_hqr_finalize( &qrtree ); + libhqr_matrix_finalize( &qrtree ); return 1; } diff --git a/testings/draw_systolic.c b/testings/draw_systolic.c index 08a24aa..31252f8 100644 --- a/testings/draw_systolic.c +++ b/testings/draw_systolic.c @@ -38,7 +38,7 @@ main(int argc, char ** argv) libhqr_systolic_init( &qrtree, LIBHQR_QR, &matrix, P, Q ); libhqr_print_tree( &qrtree, &matrix ); - libhqr_systolic_finalize( &qrtree ); + libhqr_matrix_finalize( &qrtree ); return 1; } diff --git a/testings/testing_tileinit.c b/testings/testing_tileinit.c index e2cccd2..3da0d51 100644 --- a/testings/testing_tileinit.c +++ b/testings/testing_tileinit.c @@ -33,6 +33,6 @@ main(int argc, char ** argv) matrix.nt = 1; libhqr_hqr_init( &qrtree, LIBHQR_QR, &matrix, 0, 0, 1, 3, 0, 0); rc = libhqr_tree_check( &matrix, &qrtree ); - libhqr_hqr_finalize( &qrtree ); + libhqr_matrix_finalize( &qrtree ); return 1; } -- GitLab