Changeset 822 for soft/giet_vm/applications/rosenfeld/src-par/mca_main.c
- Timestamp:
- Jun 1, 2016, 10:25:43 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/rosenfeld/src-par/mca_main.c
r821 r822 126 126 127 127 128 // QM : The cost of this function is horrible129 // but it is only for testing purpose130 128 // Renumbers object in a contiguous way, for an image which has already 131 129 // been processed with several threads 132 // ------------------------------------------------------------------ --133 static void renumber_image( uint32 ** E, int i0, int i1, int j0, int j1)134 // ------------------------------------------------------------------ --135 { 136 int size = 10;137 int idx = 1; // next label to give, first invalid index in the equiv table138 uint32 * equiv = malloc(sizeof(uint32) * size);139 equiv[0] = 0; // unused 140 int found;141 142 for (int i = i0; i <= i1; i++) {143 for (int j = j0; j <= j1; j++) {144 if (E[i][j] != 0) {145 found = 0;146 for (int k = 1; k < idx; k++) {147 if (equiv[k] == E[i][j]) {148 E[i][j] = k;149 found = 1;150 break;151 }152 }153 if (found == 0) {154 equiv[idx] = E[i][j];155 E[i][j] = idx;156 idx += 1;157 if (idx == size) {158 size = size * 2;159 equiv = realloc(equiv, sizeof(uint32) * size);160 }161 }130 // ------------------------------------------------------------------ 131 static void renumber_image(MCA * mca, int i0, int i1, int j0, int j1) 132 // ------------------------------------------------------------------ 133 { 134 int32_t na = 0; 135 uint32_t ** E = mca->E; 136 uint32_t ** D = mca->mcas[0]->D; 137 138 uint32_t shift = mca->alpha; 139 uint32_t mask = (1 << shift) - 1; 140 141 for (int32_t p = 0; p < mca->np; p++) { 142 MCA * mca_par = mca->mcas[p]; 143 uint32 * T = mca_par->T; 144 for (uint32_t e = mca_par->e0; e <= mca_par->ne; e++) { 145 if (T[e] != e) { 146 // FindRoot_Dist 147 uint32_t r = T[e]; 148 uint32_t a = e; 149 do { 150 uint32_t e1 = r >> shift; 151 uint32_t e0 = r & mask; 152 a = r; 153 r = D[e1][e0]; 154 } while (r < a); 155 T[e] = r; 156 } 157 else { 158 na += 1; 159 T[e] = na; 162 160 } 163 161 } 164 162 } 165 free(equiv); 163 164 for (int32_t i = i0; i <= i1; i++) { 165 for (int32_t j = j0; j <= j1; j++) { 166 if (E[i][j] != 0) { 167 uint32_t e0 = E[i][j] & mask; 168 uint32_t e1 = E[i][j] >> shift; 169 E[i][j] = D[e1][e0]; 170 } 171 } 172 } 166 173 } 167 174 … … 203 210 204 211 display_ui8matrix_positive(mca->X, i0, i1, j0, j1, 5, "X0"); 205 #if FEATURES206 for (int i = 1; i < num_threads; i++) {207 pthread_create(&thread_table[i], NULL, MCA_Label_Features_Rosenfeld, (void *) mca->mcas[i]);208 }209 MCA_Label_Features_Rosenfeld(mca->mcas[0]);210 #else211 212 for (int i = 1; i < num_threads; i++) { 212 213 pthread_create(&thread_table[i], NULL, MCA_Label_Rosenfeld, (void *) mca->mcas[i]); 213 214 } 215 214 216 MCA_Label_Rosenfeld(mca->mcas[0]); 215 #endif 217 216 218 for (int i = 1; i < num_threads; i++) { 217 219 pthread_join(thread_table[i], NULL); … … 221 223 222 224 // -- free -- 223 printf("Finalize\n");225 MCA_VERBOSE1(printf("Finalize\n")); 224 226 MCA_Finalize(mca); 225 227 226 printf("Free_matrix\n");228 MCA_VERBOSE1(printf("Free_matrix\n")); 227 229 free_ui8matrix (X0, i0, i1, j0, j1); 228 230 free_ui32matrix(E, i0, i1, j0, j1); … … 249 251 Palette_18ColorsBW(palette); 250 252 251 printf("Loading file %s... ", infile);253 MCA_VERBOSE1(printf("Loading file %s... ", infile)); 252 254 X = LoadPGM_ui8matrix(infile, &i0, &i1, &j0, &j1); 253 printf("done.\n");254 255 printf("Allocating memory... ");255 MCA_VERBOSE1(printf("done.\n")); 256 257 MCA_VERBOSE1(printf("Allocating memory... ")); 256 258 height = i1 - i0 + 1; 257 259 width = j1 - j0 + 1; … … 265 267 // pre-traitements 266 268 binarisation_ui8matrix(X, i0, i1, j0, j1, 20, 1, X); // pour le traitement 267 printf("done.\n");268 269 printf("Allocating and initializing MCA... \n");269 MCA_VERBOSE1(printf("done.\n")); 270 271 MCA_VERBOSE1(printf("Allocating and initializing MCA... \n")); 270 272 mca = MCA_pConstructor_Empty(); 271 273 … … 279 281 MCA_Initialize(mca); 280 282 MCA_Display_Parameters(mca); 281 printf("End of MCA allocation and initialization.\n");283 MCA_VERBOSE1(printf("End of MCA allocation and initialization.\n")); 282 284 283 285 CLOCK_APP_CREATE; 284 #if FEATURES285 for (int i = 1; i < num_threads; i++) {286 pthread_create(&thread_table[i], NULL, MCA_Label_Features_Rosenfeld, (void *) mca->mcas[i]);287 }288 MCA_Label_Features_Rosenfeld(mca->mcas[0]);289 #else290 286 for (int i = 1; i < num_threads; i++) { 291 287 pthread_create(&thread_table[i], NULL, MCA_Label_Rosenfeld, (void *) mca->mcas[i]); 292 288 } 289 293 290 MCA_Label_Rosenfeld(mca->mcas[0]); 294 #endif 291 295 292 for (int i = 1; i < num_threads; i++) { 296 293 pthread_join(thread_table[i], NULL); … … 300 297 if (generate_output_image) { 301 298 #if TARGET_OS != GIETVM 302 renumber_image(mca ->E, i0, i1, j0, j1);299 renumber_image(mca, i0, i1, j0, j1); 303 300 #else 304 301 printf("Warning: the output image has not been renumbered, it cannot be used as a comparison with the reference\n"); 305 302 #endif 306 303 mod_ui32matrix_ui8matrix(mca->E, i0, i1, j0, j1, E8); 307 printf("Saving file %s for verification... ", outfile);304 MCA_VERBOSE1(printf("Saving file %s for verification... ", outfile)); 308 305 SaveBMP2_ui8matrix(E8, width, height, palette, outfile); 309 printf("done.\n");306 MCA_VERBOSE1(printf("done.\n")); 310 307 } 311 308 312 309 MCA_Finalize(mca); 313 printf("Deallocating memory...");310 MCA_VERBOSE1(printf("Deallocating memory...")); 314 311 free_ui8matrix (X, i0, i1, j0, j1); 315 312 free_ui8matrix (E8, i0, i1, j0, j1); 316 313 free_ui32matrix(E, i0, i1, j0, j1); 317 printf("done.\n");314 MCA_VERBOSE1(printf("done.\n")); 318 315 } 319 316 … … 353 350 int num_threads = DEFAULT_NTHREADS; 354 351 355 printf("*** Starting application Rosenfeld ***\n");352 MCA_VERBOSE1(printf("*** Starting application Rosenfeld ***\n")); 356 353 357 354 #if TARGET_OS != GIETVM // @QM I think the giet has some random (uninitialized) values for argc and argv … … 410 407 } 411 408 412 printf("Parameters:\n");413 printf("- Number of threads: %d\n", num_threads);414 printf("- Input file: %s\n", infile);415 printf("- Output file: %s\n", outfile);409 MCA_VERBOSE1(printf("Parameters:\n")); 410 MCA_VERBOSE1(printf("- Number of threads: %d\n", num_threads)); 411 MCA_VERBOSE1(printf("- Input file: %s\n", infile)); 412 MCA_VERBOSE1(printf("- Output file: %s\n", outfile)); 416 413 #if FAST 417 printf("- Using decision trees (fast): yes\n");414 MCA_VERBOSE1(printf("- Using decision trees (fast): yes\n")); 418 415 #elif SLOW 419 printf("- Using decision trees (fast): no\n");416 MCA_VERBOSE1(printf("- Using decision trees (fast): no\n")); 420 417 #endif 421 418 #if FEATURES 422 printf("- Computing features: yes\n"); 423 #else 424 printf("- Computing features: no\n"); 419 MCA_VERBOSE1(printf("- Computing features: yes\n")); 420 #else 421 MCA_VERBOSE1(printf("- Computing features: no\n")); 422 #endif 423 #if PARMERGE 424 MCA_VERBOSE1(printf("- Parallel Merge: yes\n")); 425 #else 426 MCA_VERBOSE1(printf("- Parallel Merge: no\n")); 427 #endif 428 #if ARSP 429 MCA_VERBOSE1(printf("- Optimization ARemSP: yes\n")); 430 #else 431 MCA_VERBOSE1(printf("- Optimization ARemSP: no\n")); 432 #endif 433 #if PYR_BARRIERS 434 MCA_VERBOSE1(printf("- Pyramidal Barriers: yes\n")); 435 #else 436 MCA_VERBOSE1(printf("- Pyramidal Barriers: no\n")); 425 437 #endif 426 438 … … 428 440 #if TARGET_OS == GIETVM 429 441 giet_tty_alloc(1); 430 printf("Initializing heaps... ");442 MCA_VERBOSE1(printf("Initializing heaps... ")); 431 443 for (int i = 0; i < X_SIZE; i++) { 432 444 for (int j = 0; j < X_SIZE; j++) { … … 434 446 } 435 447 } 436 printf("done.\n");448 MCA_VERBOSE1(printf("done.\n")); 437 449 #endif 438 450 … … 443 455 } 444 456 457 // Local Variables: 458 // tab-width: 4 459 // c-basic-offset: 4 460 // c-file-offsets:((innamespace . 0)(inline-open . 0)) 461 // indent-tabs-mode: nil 462 // End: 463 464 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 465
Note: See TracChangeset
for help on using the changeset viewer.