diff --git a/include/displays.h b/include/displays.h index 6a33d23..3a48228 100644 --- a/include/displays.h +++ b/include/displays.h @@ -43,6 +43,7 @@ void print_user_action(struct arrow_t *arrows, int arrows_nb, int address, int r void print_user_choices(struct arrow_t *arrows, int arrows_nb, int space_size_x, int space_size_y, int space_size_z, int show_array, int show_space_design); +void print_evolution (struct arrow_t *arrows, int arrows_nb, int modified, int deleted, int show_array); /* * Prints the initial user choices : * - space dimension size and appearance (grids) diff --git a/src/graphics/displays.c b/src/graphics/displays.c index 6d0cfc3..8f14321 100644 --- a/src/graphics/displays.c +++ b/src/graphics/displays.c @@ -58,15 +58,30 @@ void print_user_choices(struct arrow_t *arrows, int arrows_nb, int space_size_x, int space_size_y, int space_size_z, int show_array, int show_space_design) { - printf("model + user constraints :\tspace size x,y,z = %d,%d,%d\tarrows nb = %d\t",\ + printf("model + user constraints :\tspace size x,y,z (%3d,%3d,%3d)\tarrows nb : %6d\t",\ space_size_x, space_size_y, space_size_z, arrows_nb); - if (show_space_design) printf("orientations grilles alternées"); + if (show_space_design) printf(" (grilles alternées)"); printf("\n"); if (show_array) print_arrows_array (arrows, arrows_nb); } +/* Prints the evolution after adding / removing arrows : + * - arrows[] array + * NB The space may be empty or saturated with arrows or any value in between + * Only one arrow per possible coordinates with a load max equal to ? TODO + * + * + * print_evolution (arrows, added, mem, deleted, print_arrows_data); + */ +void print_evolution (struct arrow_t *arrows, int arrows_nb, int modified, int deleted, int show_array) +{ + printf("evolution\t\t\t\t\t\t\tarrows nb > %6d\t (%d added / %d deleted) (modified : %d)\n",\ + arrows_nb + modified - deleted * 2, modified - deleted, deleted, modified); + if (show_array) print_arrows_array (arrows, arrows_nb); +} + /* * Prints the arrows[] array * diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 6a37b0e..b43973f 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -627,6 +627,8 @@ static inline int set_arrow (struct arrow_t *arrows, int arrows_nb, int requeste { int address = -1, current_weight = -1; +#pragma omp parallel schedule(static, 12) +{ for (int i = 0; i < arrows_nb; i++) { if ((site == arrows[i].site) && (x == arrows[i].x) @@ -638,7 +640,7 @@ static inline int set_arrow (struct arrow_t *arrows, int arrows_nb, int requeste break; } } - +} //printf("\n[%d]set_arrow() invoked with requested weight = %2d + ", arrows_nb, requested_weight); if (TEST) show_user_action(arrows, arrows_nb, address, requested_weight, current_weight, site, x, y, z); @@ -673,11 +675,12 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) // assert : no more than one arrow per address // notify : weights are replaced, NOT added (could be !) + struct timespec ts; srand(time(NULL)); // Initialisation du générateur pseudo-aléatoire int rand(void); void srand(unsigned int seed); // printf ("Valeur max : %d\n", RAND_MAX); min + rand() % (max+1 - min); - int arbitrary = 0; + int arbitrary = 200; int space_X = 1 + rand() % arbitrary, space_Y = 1 + rand() % arbitrary, space_Z = 1 + rand() % arbitrary; @@ -687,37 +690,48 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) int show_space_design = 1, print_arrows_data = 0; int load = 0, site = 0, x = 0, y = 0, z = 0; - int specif_arrows_nb = rand() % density_max / 3; - int arrows_nb = 0; + int specif_arrows_nb = rand() % density_max; + int arrows_nb = 0, cpt = 0, t_initial = 0; - /* while (arrows_nb < specif_arrows_nb){ */ - /* arrows_nb = set_arrow (arrows, arrows_nb, */ - /* rand() % arbitrary + 1, // load / weight */ - /* rand() % 6, // site, */ - /* rand() % space_X, // x */ - /* rand() % space_Y, // y */ - /* rand() % space_Z); // z */ - /* } */ + clock_gettime(CLOCK_REALTIME, &ts); t_initial = ts.tv_sec; + printf("%10d | ", specif_arrows_nb / 1000); +#pragma omp parallel +{ + while (arrows_nb < specif_arrows_nb){ + arrows_nb = set_arrow (arrows, arrows_nb, + rand() % arbitrary + 1, // load / weight + rand() % 6, // site, + rand() % space_X, // x + rand() % space_Y, // y + rand() % space_Z); // z + /* clock_gettime(CLOCK_REALTIME, &ts); < Je n'arrive pas à afficher les temps en cours d'exécutuion */ + /* if (arrows_nb % 1000 == 0) {cpt++; printf("%8d", arrows_nb / 1000); if (cpt % 22 == 0) printf(" %f\n%10d | ", specif_arrows_nb / 1000, ts.tv_sec - t_initial);} */ + if (arrows_nb % 1000 == 0) {cpt++; printf("%8d", arrows_nb / 1000); if (cpt % 24 == 0) printf("\n%10d | ", specif_arrows_nb / 1000);} + } + printf("\n"); +} // clock_t start, end; /* Recording the starting clock tick.*/ // start = clock(); - arbitrary = 24; - space_X = arbitrary; space_Y = arbitrary; space_Z = arbitrary; - density_max = space_X * space_Y * space_Z; - for (int i =0; i < space_X; i++) - for (int j =0; j < space_Y; j++) - for (int k =0; k < space_Z; k++) - for (int u =0; u < 6; u++) - arrows_nb = set_arrow (arrows, arrows_nb, - 1, // load / weight - u,//i % 6, // site, - i,//i % space_X, // x - j,//i % space_Y, // y - k//i % space_Z); - ); + /* arbitrary = 26; */ + /* space_X = arbitrary; space_Y = arbitrary; space_Z = arbitrary; */ + /* density_max = space_X * space_Y * space_Z; + * C E T T E T R I P L E B O U C L E + * S A T U R E L ' E S P A C E S Y S T É M A T I Q U E M E N T */ + /* for (int i =0; i < space_X; i++) */ + /* for (int j =0; j < space_Y; j++) */ + /* for (int k =0; k < space_Z; k++) */ + /* for (int u =0; u < 6; u++) */ + /* arrows_nb = set_arrow (arrows, arrows_nb, */ + /* 1, // load / weight */ + /* u,//i % 6, // site, */ + /* i,//i % space_X, // x */ + /* j,//i % space_Y, // y */ + /* k//i % space_Z); */ + /* ); */ // end = clock(); printf("Elapsed time %ld\n", end - start); print_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, print_arrows_data, show_space_design); @@ -737,13 +751,13 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) offset_vertex += write_space_ridges_vertex (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z); offset_colors = offset_vertex; - if (1) printf("offset_vertex after writing_space_ridges_vertex : %d (x 3 = %d)\n\n", offset_vertex, offset_vertex * 3); + if (0) printf("offset_vertex after writing_space_ridges_vertex : %d (x 3 = %d)\n\n", offset_vertex, offset_vertex * 3); offset_vertex += write_grids_on_space_faces_vertex (offset_vertex, offset_colors, offset_lines, space_X, space_Y, space_Z, show_space_design); offset_colors = offset_vertex; - if (1) printf("offset_vertex after writing_space_faces_vertex = %4d - 8 = %3d (x 3 = %4d)\n", offset_vertex, offset_vertex - 8, (offset_vertex - 8) * 3); - if (1) printf("(space_X - 1) * 4 + (space_Y - 1) * 4 + (space_Z - 1) * 4 = %3d (x 3 = %4d)\n\n",\ + if (0) printf("offset_vertex after writing_space_faces_vertex = %4d - 8 = %3d (x 3 = %4d)\n", offset_vertex, offset_vertex - 8, (offset_vertex - 8) * 3); + if (0) printf("(space_X - 1) * 4 + (space_Y - 1) * 4 + (space_Z - 1) * 4 = %3d (x 3 = %4d)\n\n",\ (space_X - 1) * 4 + (space_Y - 1) * 4 + (space_Z - 1) * 4, ((space_X - 1) * 4 + (space_Y - 1) * 4 + (space_Z - 1) * 4) * 3); @@ -762,7 +776,7 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) offset_colors = offset_vertex; } - if (1) printf("offset_vertex after writing_arrows_vertex : %d (x 3 = %d) (arrows_nb = %d)\n", offset_vertex, offset_vertex * 3, arrows_nb); + if (0) printf("offset_vertex after writing_arrows_vertex : %d (x 3 = %d) (arrows_nb = %d)\n", offset_vertex, offset_vertex * 3, arrows_nb); /*---------------------------------------------------------------*/ @@ -790,10 +804,29 @@ void __attribute__((optimize("no-unroll-loops"))) main_test_graphics (void) load, site, x, y, z); } + assert : arrows_nb > arbitrary; + int random_choice, modified = 0, deleted = 0; + +#pragma omp parallel +{ + while (modified < arbitrary) { + + random_choice = rand() % 6; + if (random_choice == 0) deleted++; + + modified = set_arrow (arrows, modified, + random_choice, // load / weight + rand() % 6, // site, + rand() % space_X, // x + rand() % space_Y, // y + rand() % space_Z); // z + } +} + print_evolution (arrows, arrows_nb, arbitrary, deleted, print_arrows_data); + + // ? free (space) TODO free(arrows); arrows = NULL; arrows_nb = 0; - - }