Ignore:
Timestamp:
Jun 14, 2016, 5:23:56 PM (9 years ago)
Author:
meunier
Message:
  • Improved scripts for simulations and graphes
  • Continued to clean up the lib nrc2 (from nrio2x.x to nrmem1.c)
  • Added a version (Fast - Parmerge - No stats)
Location:
soft/giet_vm/applications/rosenfeld/src-par
Files:
3 edited

Legend:

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

    r822 r823  
    9898
    9999
    100 // -----------------------------------------------
     100// ------------------------------------------------
    101101void MCA_Set_Size(MCA * mca, int width, int height)
    102 // -----------------------------------------------
     102// ------------------------------------------------
    103103{
    104104    MCA_Set_Width(mca, width);
     
    107107
    108108
    109 // ----------------------------------------------------
     109// -----------------------------------------------------
    110110void MCA_Set_Dimension(MCA * mca, int width, int height)
    111 // ----------------------------------------------------
     111// -----------------------------------------------------
    112112{
    113113    MCA_Set_Width(mca, width);
     
    116116
    117117
    118 // ------------------------------
     118// -------------------------------
    119119void MCA_Set_NP(MCA * mca, int np)
    120 // ------------------------------
     120// -------------------------------
    121121{
    122122    mca->np = np;
    123123}
     124
     125
     126// -------------------------------
     127void MCA_Set_NR(MCA * mca, int nr)
     128// -------------------------------
     129{
     130    mca->nr = nr;
     131}
     132
    124133
    125134
     
    146155    // input
    147156    int np     = mca->np;
     157    int nr     = mca->nr;
    148158    int width  = mca->width;
    149159    int height = mca->height;
     
    292302        mca_par->e0 = e0_par;
    293303        mca_par->e1 = e1_par;
     304        // à la premiÚre itération, on remet à 0 toute la table T
     305        mca_par->ne_prev = e1_par;
    294306        mca_par->alpha = pw2;
    295307        mca_par->np = np;
     308        mca_par->nr = nr;
    296309        // Pour les barriÚres pyramidales
    297310        mca_par->nb_level = nb_level;
     
    311324        mca_par->E = remote_dist_ui32matrix(i0_par, i1_par, 0, width - 1, x, y); // distributed matrix with border
    312325       
    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             mca_par->stats = remote_RegionStatsVector(e0_par - 1, e1_par, x, y);
    316         }
    317         else {
    318             mca_par->T = remote_ui32vector(e0_par, e1_par, x, y);
    319             mca_par->stats = remote_RegionStatsVector(e0_par, e1_par, x, y);
    320         }
     326        mca_par->T = remote_ui32vector(e0_par, e1_par, x, y);
     327        mca_par->stats = remote_RegionStatsVector(e0_par, e1_par, x, y);
    321328       
    322329        mca_par->D = (uint32 **) remote_vvector(0, np - 1, x, y);
     
    326333        mca_par->E = dist_ui32matrix(i0_par, i1_par, 0, width - 1); // distributed matrix with border
    327334       
    328         if (p == 0) {
    329             mca_par->T = ui32vector(e0_par - 1, e1_par); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
    330             mca_par->stats = RegionStatsVector(e0_par - 1, e1_par);
    331         }
    332         else {
    333             mca_par->T = ui32vector(e0_par, e1_par);
    334             mca_par->stats = RegionStatsVector(e0_par, e1_par);
    335         }
     335        mca_par->T = ui32vector(e0_par, e1_par);
     336        mca_par->stats = RegionStatsVector(e0_par, e1_par);
    336337       
    337338        mca_par->D = (uint32 **) vvector(0, np - 1);
     
    353354   
    354355        MCA_VERBOSE3(printf("p = %d T[%d..%d]\n", p, e0, e1));
    355         if (p == 0) {
    356             set_ui32vector_j(T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
    357         }
    358         else {
    359             set_ui32vector_j(T, e0, e1);
    360         }
    361         MCA_VERBOSE3(printf("\n"));
     356        set_ui32vector_j(T, e0, e1);
    362357    }
    363358   
     
    371366       
    372367        MCA_VERBOSE3(printf("p = %d T[%d..%d]\n", p, e0, e1));
    373         if (p == 0) {
    374             MCA_VERBOSE3(display_ui32vector_number(T, e0 - 1, e0 + 10, "%5d", "T"));
    375         }
    376         else {
    377             MCA_VERBOSE3(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T"));
    378         }
     368        MCA_VERBOSE3(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T"));
    379369        MCA_VERBOSE3(printf("\n"));
    380370    }
     
    506496        free_dist_ui32matrix(mca_par->E, i0, i1, j0, j1);
    507497       
    508         if (p == 0) {
    509             free_ui32vector(mca_par->T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
    510             free_RegionStatsVector(mca_par->stats, e0 - 1, e1);
    511         }
    512         else {
    513             free_ui32vector(mca_par->T, e0, e1);
    514             free_RegionStatsVector(mca_par->stats, e0, e1);
    515         }
     498        free_ui32vector(mca_par->T, e0, e1);
     499        free_RegionStatsVector(mca_par->stats, e0, e1);
    516500       
    517501        free_vvector((void **) mca_par->D, 0, np - 1);
  • soft/giet_vm/applications/rosenfeld/src-par/mca_main.c

    r822 r823  
    4343#define MAX_THREADS 256
    4444#define DEFAULT_NTHREADS 1
     45#define DEFAULT_NRUNS 1
    4546#define DEFAULT_IN_FILENAME "/misc/cadastre.pgm"
    4647#define DEFAULT_OUT_FILENAME "out.bmp"
     
    233234
    234235
    235 // -----------------------------------------------------------
    236 void mca_test2(int num_threads, char * infile, char * outfile)
    237 // -----------------------------------------------------------
     236// -------------------------------------------------------------------------
     237void mca_test2(int num_threads, int num_runs, char * infile, char * outfile)
     238// -------------------------------------------------------------------------
    238239{
    239240    int i0, i1, j0, j1;
     
    277278    MCA_Set_ImageL(mca, E);
    278279    MCA_Set_NP(mca, num_threads);
     280    MCA_Set_NR(mca, num_runs);
    279281   
    280282    // -- MCA init
     
    316318
    317319
    318 // --------------------------------------------------------------
    319 int main_test_mca(int num_threads, char * infile, char * outfile)
    320 // --------------------------------------------------------------
     320// ----------------------------------------------------------------------------
     321int main_test_mca(int num_threads, int num_runs, char * infile, char * outfile)
     322// ----------------------------------------------------------------------------
    321323{
    322324    CLOCK_INIT(num_threads, 4); // 4 = Number of steps in body
    323325    CLOCK_APP_START;
    324326
    325     mca_test2(num_threads, infile, outfile);
     327    mca_test2(num_threads, num_runs, infile, outfile);
    326328
    327329    CLOCK_APP_END;
     
    349351    int ch;
    350352    int num_threads = DEFAULT_NTHREADS;
     353    int num_runs = DEFAULT_NRUNS;
    351354
    352355    MCA_VERBOSE1(printf("*** Starting application Rosenfeld ***\n"));
    353356
    354357#if TARGET_OS != GIETVM // @QM I think the giet has some random (uninitialized) values for argc and argv
    355     while ((ch = getopt(argc, argv, "i:o:n:hdg")) != EOF) {
     358    while ((ch = getopt(argc, argv, "i:o:n:r:hdg")) != EOF) {
    356359        switch (ch) {
    357360        case 'i':
     
    363366        case 'n':
    364367            num_threads = atoi(optarg);
     368            break;
     369        case 'r':
     370            num_runs = atoi(optarg);
    365371            break;
    366372        case 'h':
     
    409415    MCA_VERBOSE1(printf("Parameters:\n"));
    410416    MCA_VERBOSE1(printf("- Number of threads: %d\n", num_threads));
     417    MCA_VERBOSE1(printf("- Number of images processed: %d\n", num_runs));
    411418    MCA_VERBOSE1(printf("- Input file: %s\n", infile));
    412419    MCA_VERBOSE1(printf("- Output file: %s\n", outfile));
     
    450457
    451458    pthread_mutex_init(&print_lock, PTHREAD_PROCESS_PRIVATE);
    452     main_test_mca(num_threads, infile, outfile);
     459    main_test_mca(num_threads, num_runs, infile, outfile);
    453460
    454461    return 0;
  • soft/giet_vm/applications/rosenfeld/src-par/mca_rosenfeld.c

    r822 r823  
    142142}
    143143#endif // FEATURES && !PARMERGE
     144
     145
     146#if !FEATURES && PARMERGE
     147// -----------------------------------------------------------------------------------------------------------
     148static bool SetRoot_Parallel_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift, RegionStats ** F)
     149// -----------------------------------------------------------------------------------------------------------
     150{
     151    assert(root != 0 && eps != 0);
     152
     153    MCA_VERBOSE3(printf("F(%d) += F(%d)\n", eps, root));
     154   
     155    int mask = (1 << shift) - 1;
     156
     157    uint32 r1 = root >> shift;
     158    uint32 r0 = root & mask;
     159   
     160    uint32 e1 = eps >> shift;
     161    uint32 e0 = eps & mask;
     162
     163    // Locking towards the root (first root, then eps)
     164    pthread_spin_lock(&F[r1][r0].lock);
     165    pthread_spin_lock(&F[e1][e0].lock);
     166    if (D[e1][e0] != eps || D[r1][r0] != root) {
     167        // Someone change the root of epsilon or "root", need to find the new root
     168        pthread_spin_unlock(&F[e1][e0].lock);
     169        pthread_spin_unlock(&F[r1][r0].lock);
     170        return false;
     171    }
     172
     173    D[r1][r0] = eps;
     174   
     175    pthread_spin_unlock(&F[e1][e0].lock);
     176    pthread_spin_unlock(&F[r1][r0].lock);
     177    return true;
     178}
     179#endif // !FEATURES && PARMERGE
    144180
    145181
     
    585621
    586622
    587 #if FAST && FEATURES && PARMERGE && !ARSP
     623#if FAST && PARMERGE && !ARSP // Valid for FEATURES and !FEATURES
    588624// ---------------------------------------------------------------------------------------------------------------------------
    589 static void vuse2_Parallel_Features_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
     625static void vuse2_Parallel_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
    590626// ---------------------------------------------------------------------------------------------------------------------------
    591627{
     
    610646        // qui a fait un test
    611647        if (rd < rl) {
    612             ok = SetRoot_Parallel_Features_Rosenfeld_Dist(D, rl, rd, alpha, F);
     648            // Features or No Features depending on config
     649            ok = SetRoot_Parallel_FNF(D, rl, rd, alpha, F);
    613650        }
    614651        else {
    615             ok = SetRoot_Parallel_Features_Rosenfeld_Dist(D, rd, rl, alpha, F);
     652            ok = SetRoot_Parallel_FNF(D, rd, rl, alpha, F);
    616653        }
    617654    } while (!ok);
    618655}
    619656
    620 // FAST && FEATURES && PARMERGE && !ARSP
     657// FAST && PARMERGE && !ARSP
    621658
    622659// -----------------------------------------------------------------------------------------------------------------------------------------
    623 static void vuse3_Parallel_Features_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
     660static void vuse3_Parallel_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
    624661// -----------------------------------------------------------------------------------------------------------------------------------------
    625662{
     
    649686        ok3 = true;
    650687        if (r1 > eps) {
    651             ok1 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r1, eps, alpha, F);
     688            ok1 = SetRoot_Parallel_FNF(D, r1, eps, alpha, F);
    652689        }
    653690        if (r2 > eps && r2 != r1) {
    654             ok2 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r2, eps, alpha, F);
     691            ok2 = SetRoot_Parallel_FNF(D, r2, eps, alpha, F);
    655692        }
    656693        if (r3 > eps && r3 != r2 && r3 != r1) {
    657             ok3 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r3, eps, alpha, F);
     694            ok3 = SetRoot_Parallel_FNF(D, r3, eps, alpha, F);
    658695        }
    659696    } while (!(ok1 && ok2 && ok3));
    660697}
    661 #endif // FAST && FEATURES && PARMERGE && !ARSP
     698#endif // FAST && PARMERGE && !ARSP
    662699
    663700
     
    13811418    uint32 e0 = mca->e0;
    13821419    uint32 e1 = mca->e1;
     1420    uint32 ne_prev = mca->ne_prev;
    13831421    uint32 ne = e0 - 1;
    13841422    uint32 nr = 0;
     
    13901428    RegionStats * stats = mca->stats;
    13911429
    1392     // reset sous optimal (pour le moment = voir region32)
    1393     if (mca->p == 0) {
    1394         set_ui32vector_j(T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
     1430    CLOCK_THREAD_START_STEP(mca->p, 0);
     1431
     1432    set_ui32vector_j(T, e0, ne_prev);
    13951433#if FEATURES
    1396         zero_RegionStatsVector(stats, e0 - 1, e1);
     1434    zero_RegionStatsVector(stats, e0, ne_prev);
    13971435#endif
    1398     }
    1399     else {
    1400         set_ui32vector_j(T, e0, e1);
    1401 #if FEATURES
    1402         zero_RegionStatsVector(stats, e0, e1);
    1403 #endif
    1404     }
    14051436
    14061437    if (mca->p == 0) {
     
    14111442    // -- Etiquetage d'une bande -- //
    14121443    // ---------------------------- //
    1413 
    1414     CLOCK_THREAD_START_STEP(mca->p, 0);
    14151444
    14161445    ne = line0Labeling_Rosenfeld(X, i0, width, E, T, ne);
     
    16441673
    16451674    CLOCK_THREAD_START(mca->p);
    1646     CLOCK_THREAD_COMPUTE_START(mca->p);
    1647 
    1648     MCA_Scatter_ImageX(mca);
    1649     pthread_barrier_wait(&main_barrier);
    1650 
    1651     MCA_Label_Rosenfeld_PAR1(mca);
    1652     pthread_barrier_wait(&main_barrier);
    1653    
     1675
     1676    int num_runs = mca->nr;
     1677
     1678    // We always perform one more run than the num_runs
     1679    // value, so as to know "ne", i.e. the number of
     1680    // elements to reset in the T and F tables (labels and stats)
     1681    // After this first extra run, clock times are not accumulated
     1682    // and thus are lost.
     1683    // Note: the CLOCK_THREAD_START will still include this first run,
     1684    // and in case of multiple runs, only averaged times should be
     1685    // considered.
     1686    for (int run = 0; run < num_runs + 1; run++) {
     1687
     1688        CLOCK_THREAD_COMPUTE_START(mca->p);
     1689
     1690        MCA_Scatter_ImageX(mca);
     1691        pthread_barrier_wait(&main_barrier);
     1692
     1693        MCA_Label_Rosenfeld_PAR1(mca);
     1694        pthread_barrier_wait(&main_barrier);
     1695 
    16541696#if PARMERGE
    1655     MCA_Label_Rosenfeld_PAR2(mca);
     1697        MCA_Label_Rosenfeld_PAR2(mca);
    16561698#else
    1657     MCA_Label_Rosenfeld_PYR2(mca);
     1699        MCA_Label_Rosenfeld_PYR2(mca);
    16581700#endif
    1659     pthread_barrier_wait(&main_barrier);
    1660    
    1661     MCA_Label_Rosenfeld_PAR3(mca);
    1662     pthread_barrier_wait(&main_barrier);
    1663 
    1664     MCA_Gather_ImageL(mca);
    1665     pthread_barrier_wait(&main_barrier);
    1666 
    1667     CLOCK_THREAD_COMPUTE_END(mca->p);
     1701        pthread_barrier_wait(&main_barrier);
     1702 
     1703        MCA_Label_Rosenfeld_PAR3(mca);
     1704        pthread_barrier_wait(&main_barrier);
     1705
     1706        MCA_Gather_ImageL(mca);
     1707        pthread_barrier_wait(&main_barrier);
     1708       
     1709        CLOCK_THREAD_COMPUTE_END(mca->p);
     1710
     1711        if (run == 0) {
     1712            // Mise à jour du ne_prev par chaque thread
     1713            mca->ne_prev = mca->ne;
     1714            mca->ne = 0;
     1715        }
     1716        else {
     1717            // Accumulation du temps COMPUTE et de toutes les STEP
     1718            if (mca->p == 0) {
     1719                CLOCK_ACCUMULATE;
     1720            }
     1721            assert(mca->ne == mca->ne_prev);
     1722            // Reinitialisation de "ne" s'il ne s'agit pas du dernier run
     1723            if (run != num_runs) {
     1724                mca->ne = 0;
     1725            }
     1726        }
     1727        pthread_barrier_wait(&main_barrier);
     1728    }
     1729
    16681730 
    16691731#if FEATURES
Note: See TracChangeset for help on using the changeset viewer.