Ignore:
Timestamp:
Jun 1, 2016, 10:25:43 AM (8 years ago)
Author:
meunier
Message:

In rosenfeld:

  • Updated nrio0, nrio1, nrio2, nrio1f, nrio2f, nrio1x, nrbool1, nrbool2 and nralloc1 in the nrc2 lib in order to use macro-typed functions
  • Updated the simulation script to include performance evaluation with random images, and a script to generate graphs
  • Updated the clock.h to use 64-bit integers, which potentially breaks the printing on the giet
File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/rosenfeld/src-par/mca_main.c

    r821 r822  
    126126
    127127
    128 // QM : The cost of this function is horrible
    129 // but it is only for testing purpose
    130128// Renumbers object in a contiguous way, for an image which has already
    131129// 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 table
    138     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// ------------------------------------------------------------------
     131static 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;
    162160            }
    163161        }
    164162    }
    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    }
    166173}
    167174
     
    203210   
    204211    display_ui8matrix_positive(mca->X, i0, i1, j0, j1, 5, "X0");
    205 #if FEATURES
    206     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 #else
    211212    for (int i = 1; i < num_threads; i++) {
    212213        pthread_create(&thread_table[i], NULL, MCA_Label_Rosenfeld, (void *) mca->mcas[i]);
    213214    }
     215   
    214216    MCA_Label_Rosenfeld(mca->mcas[0]);
    215 #endif
     217
    216218    for (int i = 1; i < num_threads; i++) {
    217219        pthread_join(thread_table[i], NULL);
     
    221223   
    222224    // -- free --
    223     printf("Finalize\n");
     225    MCA_VERBOSE1(printf("Finalize\n"));
    224226    MCA_Finalize(mca);
    225227   
    226     printf("Free_matrix\n");
     228    MCA_VERBOSE1(printf("Free_matrix\n"));
    227229    free_ui8matrix (X0, i0, i1, j0, j1);
    228230    free_ui32matrix(E,  i0, i1, j0, j1);
     
    249251    Palette_18ColorsBW(palette);
    250252   
    251     printf("Loading file %s... ", infile);
     253    MCA_VERBOSE1(printf("Loading file %s... ", infile));
    252254    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... "));
    256258    height = i1 - i0 + 1;
    257259    width  = j1 - j0 + 1;
     
    265267    // pre-traitements
    266268    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"));
    270272    mca = MCA_pConstructor_Empty();
    271273   
     
    279281    MCA_Initialize(mca);
    280282    MCA_Display_Parameters(mca);
    281     printf("End of MCA allocation and initialization.\n");
     283    MCA_VERBOSE1(printf("End of MCA allocation and initialization.\n"));
    282284   
    283285    CLOCK_APP_CREATE;
    284 #if FEATURES
    285     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 #else
    290286    for (int i = 1; i < num_threads; i++) {
    291287        pthread_create(&thread_table[i], NULL, MCA_Label_Rosenfeld, (void *) mca->mcas[i]);
    292288    }
     289   
    293290    MCA_Label_Rosenfeld(mca->mcas[0]);
    294 #endif
     291
    295292    for (int i = 1; i < num_threads; i++) {
    296293        pthread_join(thread_table[i], NULL);
     
    300297    if (generate_output_image) {
    301298#if TARGET_OS != GIETVM
    302         renumber_image(mca->E, i0, i1, j0, j1);
     299        renumber_image(mca, i0, i1, j0, j1);
    303300#else
    304301        printf("Warning: the output image has not been renumbered, it cannot be used as a comparison with the reference\n");
    305302#endif
    306303        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));
    308305        SaveBMP2_ui8matrix(E8, width, height, palette, outfile);
    309         printf("done.\n");
     306        MCA_VERBOSE1(printf("done.\n"));
    310307    }
    311308
    312309    MCA_Finalize(mca);
    313     printf("Deallocating memory...");
     310    MCA_VERBOSE1(printf("Deallocating memory..."));
    314311    free_ui8matrix (X,  i0, i1, j0, j1);
    315312    free_ui8matrix (E8, i0, i1, j0, j1);
    316313    free_ui32matrix(E,  i0, i1, j0, j1);
    317     printf("done.\n");
     314    MCA_VERBOSE1(printf("done.\n"));
    318315}
    319316
     
    353350    int num_threads = DEFAULT_NTHREADS;
    354351
    355     printf("*** Starting application Rosenfeld ***\n");
     352    MCA_VERBOSE1(printf("*** Starting application Rosenfeld ***\n"));
    356353
    357354#if TARGET_OS != GIETVM // @QM I think the giet has some random (uninitialized) values for argc and argv
     
    410407    }
    411408
    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));
    416413#if FAST
    417     printf("- Using decision trees (fast): yes\n");
     414    MCA_VERBOSE1(printf("- Using decision trees (fast): yes\n"));
    418415#elif SLOW
    419     printf("- Using decision trees (fast): no\n");
     416    MCA_VERBOSE1(printf("- Using decision trees (fast): no\n"));
    420417#endif
    421418#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"));
    425437#endif
    426438
     
    428440#if TARGET_OS == GIETVM
    429441    giet_tty_alloc(1);
    430     printf("Initializing heaps... ");
     442    MCA_VERBOSE1(printf("Initializing heaps... "));
    431443    for (int i = 0; i < X_SIZE; i++) {
    432444        for (int j = 0; j < X_SIZE; j++) {
     
    434446        }
    435447    }
    436     printf("done.\n");
     448    MCA_VERBOSE1(printf("done.\n"));
    437449#endif
    438450
     
    443455}
    444456
     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.