Ignore:
Timestamp:
Jul 13, 2017, 11:01:58 AM (7 years ago)
Author:
meunier
Message:
  • Mise à jour NR2 et Rosenfeld
File:
1 edited

Legend:

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

    r823 r826  
    1212#include <string.h>
    1313#include <math.h>
    14 #include <assert.h>
    1514#if PARMERGE
    1615#include <pthread.h>
     
    2726#else
    2827    #include <stdbool.h>
     28    #include <assert.h>
    2929#endif
    3030
     
    165165    pthread_spin_lock(&F[e1][e0].lock);
    166166    if (D[e1][e0] != eps || D[r1][r0] != root) {
    167         // Someone change the root of epsilon or "root", need to find the new root
     167        // Someone changed the root of epsilon or "root", need to find the new root
    168168        pthread_spin_unlock(&F[e1][e0].lock);
    169169        pthread_spin_unlock(&F[r1][r0].lock);
     
    203203    if (D[e1][e0] != eps) {
    204204        // Someone change the root of epsilon, need to find the new root
    205         printf("race cond 1\n");
     205        //printf("race cond 1\n");
    206206        pthread_spin_unlock(&F[e1][e0].lock);
    207207        pthread_spin_unlock(&F[r1][r0].lock);
     
    210210    if (D[r1][r0] != root) {
    211211        // Someone change the root of "root", need to find the new root
    212         printf("race cond 2\n");
     212        //printf("race cond 2\n");
    213213        pthread_spin_unlock(&F[e1][e0].lock);
    214214        pthread_spin_unlock(&F[r1][r0].lock);
     
    235235
    236236
     237#if FEATURES && PARMERGE && ARSP
     238// ------------------------------------------------------------------------------------------
     239static void Propagate_Features(uint32 e0, uint32 e1, uint32 * T, RegionStats ** F, int shift)
     240// ------------------------------------------------------------------------------------------
     241{
     242    uint32 i;
     243    const int mask = (1 << shift) - 1;
     244    for (i = e0; i <= e1; i++) {
     245        uint32 root = T[i];
     246        if (root != i) {
     247            uint32 r1 = root >> shift;
     248            uint32 r0 = root & mask;
     249
     250            uint32 l1 = i >> shift;
     251            uint32 l0 = i & mask;
     252            // We only lock the destination Features object
     253            pthread_spin_lock(&F[r1][r0].lock);
     254
     255            // F(eps) = F(eps) U F(root)
     256            F[r1][r0].xmin = ui16min2(F[l1][l0].xmin, F[r1][r0].xmin);
     257            F[r1][r0].xmax = ui16max2(F[l1][l0].xmax, F[r1][r0].xmax);
     258            F[r1][r0].ymin = ui16min2(F[l1][l0].ymin, F[r1][r0].ymin);
     259            F[r1][r0].ymax = ui16max2(F[l1][l0].ymax, F[r1][r0].ymax);
     260
     261            F[r1][r0].S  += F[l1][l0].S;
     262            F[r1][r0].Sx += F[l1][l0].Sx;
     263            F[r1][r0].Sy += F[l1][l0].Sy;
     264
     265            pthread_spin_unlock(&F[r1][r0].lock);
     266        }
     267    }
     268}
     269#endif // FEATURES && PARMERGE && ARSP
     270
    237271
    238272#if FAST
     
    405439
    406440
    407 #if FAST && !FEATURES && PARMERGE && ARSP
     441#if FAST && PARMERGE && ARSP
    408442// ----------------------------------------------------------------------------------------------------------------
    409443static bool SetRoot_Parallel_Arsp_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift, RegionStats ** F)
    410444// ----------------------------------------------------------------------------------------------------------------
    411445{
     446    // QM : Pour la version avec features, on est obligé de faire l'accumulation à la fin une fois la fermeture
     447    // transitive globale réalisée : sinon, on peut perdre des features quand on propage vers un epsilon qui
     448    // n'est pas une racine.
    412449    assert(root != 0 && eps != 0);
    413450
    414     MCA_VERBOSE3(printf("F(%d) += F(%d)\n", eps, root));
    415    
    416451    uint32_t mask = (1 << shift) - 1;
    417452
     
    419454    uint32_t r0 = root & mask;
    420455   
     456    // @QM
     457    // A priori ici il n'y a pas besoin de prendre le lock sur eps
     458    // car ce n'est pas une racine
    421459    pthread_spin_lock(&F[r1][r0].lock);
    422460    if (D[r1][r0] != root) {
     
    430468    return true;
    431469}
    432 
    433 // FAST && !FEATURES && PARMERGE && ARSP
    434 
     470#endif // FAST && PARMERGE && ARSP
     471
     472
     473#if FAST && PARMERGE && ARSP
    435474// ------------------------------------------------------------------------------------------------------------------------------
    436475static inline bool FindSmallerAncestor_Link(uint32 ** D, uint32_t rl, uint32_t el, uint32_t rd, uint32_t shift, RegionStats ** F)
    437476// ------------------------------------------------------------------------------------------------------------------------------
    438477{
     478    // Fait pointer rd (racine) vers rl (pas racine) a priori
     479    // mais il faut que l'élément vers lequel rd pointe soit plus petit que rd
     480    // On "remonte" donc vers la racine de rl jusqu'à atteindre un élément plus petit que rd
     481    // Si on atteint la racine de rl et que cette derniÚre est toujours plus grande que rd,
     482    // on fait alors pointer rl vers rd
    439483    bool ok;
    440484    uint32_t el1, el0;
     
    462506}
    463507
    464 // FAST && !FEATURES && PARMERGE && ARSP
     508// FAST && PARMERGE && ARSP
    465509
    466510// -----------------------------------------------------------------------------------------------------------------------
     
    513557}
    514558
    515 // FAST && !FEATURES && PARMERGE && ARSP
     559// FAST && PARMERGE && ARSP
    516560
    517561// -------------------------------------------------------------------------------------------------------------------------------------
     
    617661    } while (!ok);
    618662}
    619 #endif // FAST && !FEATURES && PARMERGE && ARSP
     663#endif // FAST && PARMERGE && ARSP
    620664
    621665
     
    13951439        if (r < e) {
    13961440            T[e] = r; // racine de la classe d'equivalence
    1397 #if FEATURES
     1441#if FEATURES && !(PARMERGE && ARSP)
    13981442            RegionStats_Accumulate_Stats1_From_Index(Stats, r, e);
    13991443#endif
     
    15191563    // -- parallel transitive closure --
    15201564    // ---------------------------------
    1521     // identique a la version sans Features
    15221565     
    15231566    CLOCK_THREAD_START_STEP(p, 2);
     
    15321575    CLOCK_THREAD_END_STEP(p, 2);
    15331576
     1577#if FEATURES && ARSP
     1578    pthread_barrier_wait(&main_barrier);
     1579#endif
     1580
    15341581    // To avoid uninitialized accesses
    15351582    CLOCK_THREAD_START_STEP(p, 3);
     1583    // With FEATURES and ARSP, STEP 3 is the Features propagation
     1584#if FEATURES && ARSP
     1585    Propagate_Features(e0, e1, T, F, mca->alpha);
     1586#endif
    15361587    CLOCK_THREAD_END_STEP(p, 3);
    15371588}
     
    16161667    CLOCK_THREAD_END_STEP(p, 2);
    16171668}
    1618 #endif // !FEATURES
     1669#endif // !PARMERGE
    16191670
    16201671
     
    16361687    uint32 * T = mca->T;
    16371688
    1638     CLOCK_THREAD_START_STEP(mca->p, 3);
     1689    CLOCK_THREAD_START_STEP(mca->p, 4);
    16391690    for (int i = i0; i <= i1; i++) {
    16401691        for (int j = j0; j <= j1; j++) {
     
    16451696        }
    16461697    }
    1647     CLOCK_THREAD_END_STEP(mca->p, 3);
     1698    CLOCK_THREAD_END_STEP(mca->p, 4);
    16481699}
    16491700
Note: See TracChangeset for help on using the changeset viewer.