Changeset 821 for soft/giet_vm/applications/rosenfeld/src-par/mca.c
- Timestamp:
- May 6, 2016, 3:06:29 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/rosenfeld/src-par/mca.c
r805 r821 15 15 #include <malloc.h> 16 16 17 #ifdef CLI18 17 #include "nrc_os_config.h" 18 #include "config.h" 19 19 #include "nrc.h" 20 #endif 21 20 21 #if TARGET_OS == GIETVM 22 #include <giet_config.h> 23 #endif 22 24 23 25 #include "util.h" 24 26 #include "ecc_common.h" 27 #include "ecc_features.h" 25 28 #include "mca_matrix_dist.h" 26 29 … … 34 37 35 38 36 // ---------------------- 39 // ----------------------- 37 40 void MCA_Error(char * msg) 38 // ---------------------- 41 // ----------------------- 39 42 { 40 43 printf("MCA ERROR: %s\n", msg); 41 44 printf("now exiting to system...\n"); 42 exit(1); 43 } 44 45 46 // --------------------- 47 void MCA_Zero(MCA * mca) 48 // --------------------- 49 { 45 exit(1); 50 46 } 51 47 … … 58 54 mca = (MCA *) malloc(sizeof(MCA)); 59 55 60 if (mca) { 61 MCA_Zero(mca); 62 } 63 else { 56 if (mca == NULL) { 64 57 MCA_Error("allocation failed in MCA_pConstructor_Empty"); 65 58 } … … 91 84 92 85 mca->j0 = 0; 93 mca->j1 = width -1;86 mca->j1 = width - 1; 94 87 } 95 88 … … 102 95 103 96 mca->i0 = 0; 104 mca->i1 = height -1;97 mca->i1 = height - 1; 105 98 } 106 99 … … 161 154 int j0_par, j1_par; 162 155 int height_par, height_mod; 163 156 164 157 int pw2; 165 158 int32 ne_par; // quantite par bande 166 159 uint32 nemax_par; // la puissance de 2 >= 167 160 uint32 e0_par, e1_par; // indice par bande [start..end] 161 int nb_level; 168 162 169 163 MCA ** mcas; 170 164 MCA * mca_par; 171 165 172 MCA_VERBOSE1(printf("====================\n")); 173 MCA_VERBOSE1(printf("== MCA_Initialize ==\n")); 174 MCA_VERBOSE1(printf("====================\n")); 175 176 MCA_VERBOSE1(printf("height = %d\n", height)); 177 MCA_VERBOSE1(printf("width = %d\n", width)); 166 printf("*** %s ***\n", __func__); 167 MCA_VERBOSE1(printf(" height = %d\n", height)); 168 MCA_VERBOSE1(printf(" width = %d\n", width)); 178 169 179 170 // array of pointers to mca workers … … 187 178 height_par = height / np; 188 179 height_mod = height % np; 189 //if(height % np) height_par++; 190 MCA_VERBOSE1(printf("height_par = %d x %d + %d\n", height_par, np, height_mod)); 191 192 MCA_VERBOSE1(printf("========================\n")); 180 181 MCA_VERBOSE1(printf(" height_par = %d x %d + %d\n", height_par, np, height_mod)); 182 MCA_VERBOSE1(printf(" ========================\n")); 193 183 194 184 i1_par_previous = 0; 195 196 for (int p = 0; p < np; p++) { 185 186 // puissance de 2 de chaque bande 187 ne_par = height_par * width + 1; 188 MCA_VERBOSE1(printf(" ne_par = %d\n", ne_par)); 189 pw2 = i32log2(ne_par); 190 if (ne_par > (1 << pw2)) { 191 pw2++; 192 } 193 nemax_par = 1 << pw2; 194 195 MCA_VERBOSE1(printf(" nemax_par = %d\n", nemax_par)); 196 197 nb_level = i32log2(np); 198 if ((1 << nb_level) < np) { 199 nb_level++; 200 } 201 202 #if PYR_BARRIERS 203 // ------------------------------------------ 204 // -- Allocation des barriÚres pyramidales -- 205 // ------------------------------------------ 206 207 pthread_barrier_t * barriers = NULL; 208 if (nb_level > 0) { 209 barriers = malloc(sizeof(pthread_barrier_t) * nb_level); 210 211 // Initially all threads are active except thread 0 212 int nb_active = np - 1; 213 pthread_barrier_init(&barriers[0], NULL, nb_active); 214 for (int i = 1; i < nb_level; i++) { 215 // thread 0 never does any merge 216 for (int p = 1; p < np; p++) { 217 if ((p + (1 << (i - 1))) % (1 << i) == 0) { 218 // thread inactive at level i 219 nb_active -= 1; 220 } 221 } 222 pthread_barrier_init(&barriers[i], NULL, nb_active); 223 } 224 } 225 #endif 226 227 for (int p = 0; p < np; p++) { 228 197 229 // ----------------- // 198 230 // -- constructor -- // 199 231 // ----------------- // 200 MCA_VERBOSE 1(printf("-- p = %d ----------------\n", p));232 MCA_VERBOSE2(printf("-- p = %d ----------------\n", p)); 201 233 202 234 // alloc of mca workers into array of pointers … … 208 240 mca_par->p = p; 209 241 mca_par->mca = mca; // pointer to master 242 #if TARGET_OS == GIETVM 243 int x, y; // cluster coordinates 244 // We have p == 4 => x = 0; y = 1 245 x = (p / NB_PROCS_MAX) / Y_SIZE; 246 y = (p / NB_PROCS_MAX) % Y_SIZE; 247 MCA_VERBOSE2(printf("p = %d (x = %d, y = %d)\n", p, x, y)); 248 #endif 210 249 211 250 // ------------------------------------- // … … 214 253 215 254 // hauteur de chaque bande 216 217 //printf("i1_par_previous = %d\n", i1_par_previous);218 219 255 if (p == 0) { 220 256 i0_par = 0; … … 232 268 i1_par_previous = i1_par; 233 269 234 MCA_VERBOSE1(printf("i0_par = %d\n", i0_par)); 235 MCA_VERBOSE1(printf("i1_par = %d\n", i1_par)); 236 237 // puissance de 2 de chaque bande 238 ne_par = height_par * width + 1; 239 //if (p == 0) { 240 // ne_par++; 241 //} 242 MCA_VERBOSE1(printf("ne_par = %d\n", ne_par)); 243 pw2 = i32log2(ne_par); 244 if (ne_par > (1 << pw2)) { 245 pw2++; 246 } 247 nemax_par = 1 << pw2; 248 MCA_VERBOSE1(printf("nemax_par = %d\n", nemax_par)); 270 MCA_VERBOSE2(printf("i0_par = %d\n", i0_par)); 271 MCA_VERBOSE2(printf("i1_par = %d\n", i1_par)); 249 272 250 273 // etiquettes … … 260 283 MCA_VERBOSE2(printf("e0_par = %d\n", e0_par)); 261 284 MCA_VERBOSE2(printf("e1_par = %d\n", e1_par)); 262 285 263 286 mca_par->width = width; 264 287 mca_par->height = height_par; 265 266 288 mca_par->i0 = i0_par; 267 289 mca_par->i1 = i1_par; 268 290 mca_par->j0 = 0; 269 291 mca_par->j1 = width - 1; 270 271 292 mca_par->e0 = e0_par; 272 293 mca_par->e1 = e1_par; 273 274 294 mca_par->alpha = pw2; 295 mca_par->np = np; 296 // Pour les barriÚres pyramidales 297 mca_par->nb_level = nb_level; 298 #if PYR_BARRIERS 299 mca_par->barriers = barriers; 300 #else 301 mca_par->barriers = NULL; 302 #endif 303 mca_par->F = NULL; // default init 304 mca_par->stats = NULL; // default init 275 305 276 306 // ---------------- // 277 307 // -- allocation -- // 278 308 // ---------------- // 279 309 #if TARGET_OS == GIETVM 310 mca_par->X = remote_ui8matrix(i0_par, i1_par, 0, width - 1, x, y); 311 mca_par->E = remote_dist_ui32matrix(i0_par, i1_par, 0, width - 1, x, y); // distributed matrix with border 312 313 if (p == 0) { 314 mca_par->T = remote_ui32vector(e0_par - 1, e1_par, x, y); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot 315 #if FEATURES 316 mca_par->stats = remote_RegionStatsVector(e0_par - 1, e1_par, x, y); 317 #endif 318 } 319 else { 320 mca_par->T = remote_ui32vector(e0_par, e1_par, x, y); 321 #if FEATURES 322 mca_par->stats = remote_RegionStatsVector(e0_par, e1_par, x, y); 323 #endif 324 } 325 326 mca_par->D = (uint32 **) remote_vvector(0, np - 1, x, y); 327 #if FEATURES 328 mca_par->F = (RegionStats **) remote_vvector(0, np - 1, x, y); 329 #endif 330 #else // !GIETVM 280 331 mca_par->X = ui8matrix (i0_par, i1_par, 0, width - 1); 281 332 mca_par->E = dist_ui32matrix(i0_par, i1_par, 0, width - 1); // distributed matrix with border … … 283 334 if (p == 0) { 284 335 mca_par->T = ui32vector(e0_par - 1, e1_par); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot 336 #if FEATURES 337 mca_par->stats = RegionStatsVector(e0_par - 1, e1_par); 338 339 #endif 285 340 } 286 341 else { 287 342 mca_par->T = ui32vector(e0_par, e1_par); 343 #if FEATURES 344 mca_par->stats = RegionStatsVector(e0_par, e1_par); 345 #endif 288 346 } 289 347 290 348 mca_par->D = (uint32 **) vvector(0, np - 1); 291 349 #if FEATURES 350 mca_par->F = (RegionStats **) vvector(0, np - 1); 351 #endif 352 #endif 292 353 MCA_VERBOSE2(printf("X = %p\n", mca_par->X)); 293 354 MCA_VERBOSE2(printf("E = %p\n", mca_par->E)); 294 355 MCA_VERBOSE2(printf("T = %p\n", mca_par->T)); 295 356 MCA_VERBOSE2(printf("D = %p\n", mca_par->D)); 296 297 357 } // p 298 358 299 // pour debug 300 MCA_VERBOSE2(printf("init des tables d'EQ a l'identite\n")); 301 for (int p = 0; p < np; p++) { 302 359 360 for (int p = 0; p < np; p++) { 303 361 MCA * mca_par = mcas[p]; 304 362 … … 319 377 MCA_VERBOSE2(printf("display des tables d'EQ\n")); 320 378 for (int p = 0; p < np; p++) { 321 322 379 MCA * mca_par = mcas[p]; 323 380 … … 326 383 uint32 e1 = mca_par->e1; 327 384 328 MCA_VERBOSE 1(printf("p = %d T[%d..%d]\n", p, e0, e1));385 MCA_VERBOSE2(printf("p = %d T[%d..%d]\n", p, e0, e1)); 329 386 if (p == 0) { 330 MCA_VERBOSE 1(display_ui32vector_number(T, e0 - 1, e0 + 10, "%5d", "T"));331 } 332 else { 333 MCA_VERBOSE 1(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T"));387 MCA_VERBOSE2(display_ui32vector_number(T, e0 - 1, e0 + 10, "%5d", "T")); 388 } 389 else { 390 MCA_VERBOSE2(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T")); 334 391 } 335 392 MCA_VERBOSE2(printf("\n")); … … 343 400 // table d'indirection distribuee D 344 401 MCA_VERBOSE2(printf("nemax_par = %d\n", nemax_par)); 345 346 for (int p = 0; p < np; p++) { 347 402 for (int p = 0; p < np; p++) { 348 403 MCA * mca_p = mcas[p]; 349 404 uint32 ** D = mca_p->D; 405 RegionStats ** F = mca_p->F; 350 406 351 407 for (int k = 0; k < np; k++) { 352 //mcas[p]->D[k] = (void*) (&(mcas[k]->T[mcas[k]->e0])) - mcas[k]->e0; //k * nemax_par;353 354 408 MCA * mca_k = mcas[k]; 355 409 uint32 * T = mca_k->T; 356 357 410 D[k] = T + k * nemax_par; // il faut soustraire le "MSB" 411 #if FEATURES 412 RegionStats * stat = mca_k->stats; 413 F[k] = stat + k * nemax_par; // il faut soustraire le "MSB" 414 #endif 358 415 } // k 359 416 } // p … … 376 433 MCA_VERBOSE2(display_ui32vector(D[k], 0, 9, "%5d", "D\n")); 377 434 } 378 printf("\n");435 MCA_VERBOSE2(printf("\n")); 379 436 } 380 437 … … 413 470 // ----------------------------------- 414 471 { 415 int p,np = mca->np;472 int np = mca->np; 416 473 417 474 MCA ** mcas = mca->mcas; 418 475 MCA * mca_par; 419 420 printf("============================\n"); 421 printf("== MCA_Display_Parameters ==\n"); 422 printf("============================\n"); 423 424 printf("height = %d\n", mca->height); 425 printf("width = %d\n", mca->width); 426 printf("np = %d\n", mca->np); 427 428 for (p = 0; p < np; p++) { 476 (void) mca_par; 477 478 printf("*** MCA_Display_Parameters ***\n"); 479 480 MCA_VERBOSE1(printf(" height = %d\n", mca->height)); 481 MCA_VERBOSE1(printf(" width = %d\n", mca->width)); 482 MCA_VERBOSE1(printf(" np = %d\n", mca->np)); 483 484 for (int p = 0; p < np; p++) { 429 485 mca_par = mcas[p]; 430 486 431 printf("Display MCA[%d]\n", p);432 printf("p = %d\n", mca_par->p);433 printf("i0 = %8d i1 = %8d\n", mca_par->i0, mca_par->i1);434 printf("j0 = %8d j1 = %8d\n", mca_par->j0, mca_par->j1);435 printf("e0 = %8d e1 = %8d\n", mca_par->e0, mca_par->e1);487 MCA_VERBOSE2(printf("Display MCA[%d]\n", p)); 488 MCA_VERBOSE2(printf("p = %d\n", mca_par->p)); 489 MCA_VERBOSE2(printf("i0 = %8d i1 = %8d\n", mca_par->i0, mca_par->i1)); 490 MCA_VERBOSE2(printf("j0 = %8d j1 = %8d\n", mca_par->j0, mca_par->j1)); 491 MCA_VERBOSE2(printf("e0 = %8d e1 = %8d\n", mca_par->e0, mca_par->e1)); 436 492 } 437 493 } … … 442 498 // ------------------------- 443 499 { 444 int p,np = mca->np;500 int np = mca->np; 445 501 446 502 MCA ** mcas = mca->mcas; … … 451 507 uint32 e0, e1; 452 508 453 printf("==================\n"); 454 printf("== MCA_Finalize ==\n"); 455 printf("==================\n"); 456 457 for (p = 0; p < np; p++) { 458 509 printf("*** MCA_Finalize ***\n"); 510 511 #if PYR_BARRIERS 512 free(mcas[0]->barriers); 513 #endif 514 515 for (int p = 0; p < np; p++) { 459 516 mca_par = mcas[p]; 460 517 … … 475 532 if (p == 0) { 476 533 free_ui32vector(mca_par->T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot 534 #if FEATURES 535 free_RegionStatsVector(mca_par->stats, e0 - 1, e1); 536 #endif 477 537 } 478 538 else { 479 539 free_ui32vector(mca_par->T, e0, e1); 540 #if FEATURES 541 free_RegionStatsVector(mca_par->stats, e0, e1); 542 #endif 480 543 } 481 544 482 545 free_vvector((void **) mca_par->D, 0, np - 1); 483 484 } 485 printf("[MCA_Finalize]: fin boucle\n"); 546 #if FEATURES 547 free_vvector((void **) mca_par->F, 0, np - 1); 548 #endif 549 free(mca_par); 550 } 486 551 free(mcas); 487 printf("[MCA_Finalize]: mcas freed\n"); 488 free(mca); // plante si free XET, ne plante pas si pas de free ... 489 printf("[MCA_Finalize]: mca freed\n"); 490 } 491 492 493 // @QM check my modifs... 552 free(mca); 553 } 554 555 494 556 // ------------------------------- 495 557 void MCA_Scatter_ImageX(MCA * mca) … … 498 560 // diffusion de l'image binaire source 499 561 500 int 562 int np = mca->np; 501 563 uint8 ** X = mca->mca->X; 502 564 503 565 if (mca->p == 0) { 504 MCA_VERBOSE1(printf("------------------------\n")); 505 MCA_VERBOSE1(printf("-- MCA_Scatter_ImageX --\n")); 506 MCA_VERBOSE1(printf("------------------------\n")); 566 printf("*** MCA_Scatter_ImageX ***\n"); 507 567 } 508 568 … … 524 584 525 585 526 // @QM check my modifs...527 586 // ------------------------------ 528 587 void MCA_Gather_ImageL(MCA * mca) … … 532 591 int np = mca->np; 533 592 uint32 ** E = mca->mca->E; 593 594 if (mca->p == 0) { 595 printf("*** MCA_Gather_ImageL ***\n"); 596 } 534 597 535 598 int i0 = mca->i0;
Note: See TracChangeset
for help on using the changeset viewer.