Ignore:
Timestamp:
May 6, 2016, 3:06:29 PM (8 years ago)
Author:
meunier
Message:
  • Added several versions of rosenfeld: { SLOW, FAST } x { FEATURES, NO_FEATURES }
  • Added native linux compilation support
  • Added a script to check results natively
  • Started to refactor nrc code
File:
1 edited

Legend:

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

    r805 r821  
    1515#include <malloc.h>
    1616
    17 #ifdef CLI
    1817#include "nrc_os_config.h"
     18#include "config.h"
    1919#include "nrc.h"
    20 #endif
    21 
     20
     21#if TARGET_OS == GIETVM
     22    #include <giet_config.h>
     23#endif
    2224
    2325#include "util.h"
    2426#include "ecc_common.h"
     27#include "ecc_features.h"
    2528#include "mca_matrix_dist.h"
    2629
     
    3437
    3538
    36 // ----------------------
     39// -----------------------
    3740void MCA_Error(char * msg)
    38 // ----------------------
     41// -----------------------
    3942{
    4043    printf("MCA ERROR: %s\n", msg);
    4144    printf("now exiting to system...\n");
    42     exit(1);   
    43 }
    44 
    45 
    46 // ---------------------
    47 void MCA_Zero(MCA * mca)
    48 // ---------------------
    49 {
     45    exit(1);
    5046}
    5147
     
    5854    mca = (MCA *) malloc(sizeof(MCA));
    5955
    60     if (mca) {
    61         MCA_Zero(mca);
    62     }
    63     else {
     56    if (mca == NULL) {
    6457        MCA_Error("allocation failed in MCA_pConstructor_Empty");
    6558    }
     
    9184
    9285    mca->j0 = 0;
    93     mca->j1 = width-1;
     86    mca->j1 = width - 1;
    9487}
    9588
     
    10295 
    10396    mca->i0 = 0;
    104     mca->i1 = height-1;
     97    mca->i1 = height - 1;
    10598}
    10699
     
    161154    int j0_par, j1_par;
    162155    int height_par, height_mod;
    163    
     156
    164157    int pw2;
    165158    int32 ne_par;          // quantite par bande
    166159    uint32 nemax_par;      // la puissance de 2 >=
    167160    uint32 e0_par, e1_par; // indice par bande [start..end]
     161    int nb_level;
    168162   
    169163    MCA ** mcas;
    170164    MCA *  mca_par;
    171165   
    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));
    178169   
    179170    // array of pointers to mca workers
     
    187178    height_par = height / np;
    188179    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"));
    193183   
    194184    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
    197229        // ----------------- //
    198230        // -- constructor -- //
    199231        // ----------------- //
    200         MCA_VERBOSE1(printf("-- p = %d ----------------\n", p));
     232        MCA_VERBOSE2(printf("-- p = %d ----------------\n", p));
    201233   
    202234        // alloc of mca workers into array of pointers
     
    208240        mca_par->p   = p;
    209241        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
    210249       
    211250        // ------------------------------------- //
     
    214253       
    215254        // hauteur de chaque bande
    216        
    217         //printf("i1_par_previous = %d\n", i1_par_previous);
    218        
    219255        if (p == 0) {
    220256            i0_par = 0;
     
    232268        i1_par_previous = i1_par;
    233269       
    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));
    249272       
    250273        // etiquettes
     
    260283        MCA_VERBOSE2(printf("e0_par = %d\n", e0_par));
    261284        MCA_VERBOSE2(printf("e1_par = %d\n", e1_par));
    262        
     285
    263286        mca_par->width  = width;
    264287        mca_par->height = height_par;
    265    
    266288        mca_par->i0 = i0_par;
    267289        mca_par->i1 = i1_par;
    268290        mca_par->j0 = 0;
    269291        mca_par->j1 = width - 1;
    270    
    271292        mca_par->e0 = e0_par;
    272293        mca_par->e1 = e1_par;
    273        
    274294        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
    275305 
    276306        // ---------------- //
    277307        // -- allocation -- //
    278308        // ---------------- //
    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
    280331        mca_par->X = ui8matrix (i0_par, i1_par, 0, width - 1);
    281332        mca_par->E = dist_ui32matrix(i0_par, i1_par, 0, width - 1); // distributed matrix with border
     
    283334        if (p == 0) {
    284335            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
    285340        }
    286341        else {
    287342            mca_par->T = ui32vector(e0_par, e1_par);
     343#if FEATURES
     344            mca_par->stats = RegionStatsVector(e0_par, e1_par);
     345#endif
    288346        }
    289347       
    290348        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   
    292353        MCA_VERBOSE2(printf("X = %p\n", mca_par->X));
    293354        MCA_VERBOSE2(printf("E = %p\n", mca_par->E));
    294355        MCA_VERBOSE2(printf("T = %p\n", mca_par->T));
    295356        MCA_VERBOSE2(printf("D = %p\n", mca_par->D));
    296    
    297357    } // p
    298358   
    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++) {
    303361        MCA * mca_par = mcas[p];
    304362       
     
    319377    MCA_VERBOSE2(printf("display des tables d'EQ\n"));
    320378    for (int p = 0; p < np; p++) {
    321        
    322379        MCA * mca_par = mcas[p];
    323380       
     
    326383        uint32 e1 = mca_par->e1;
    327384       
    328         MCA_VERBOSE1(printf("p = %d T[%d..%d]\n", p, e0, e1));
     385        MCA_VERBOSE2(printf("p = %d T[%d..%d]\n", p, e0, e1));
    329386        if (p == 0) {
    330             MCA_VERBOSE1(display_ui32vector_number(T, e0 - 1, e0 + 10, "%5d", "T"));
    331         }
    332         else {
    333             MCA_VERBOSE1(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"));
    334391        }
    335392        MCA_VERBOSE2(printf("\n"));
     
    343400    // table d'indirection distribuee D
    344401    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++) {
    348403        MCA * mca_p = mcas[p];
    349404        uint32 ** D = mca_p->D;
     405        RegionStats ** F  = mca_p->F;
    350406       
    351407        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            
    354408            MCA * mca_k = mcas[k];
    355409            uint32 * T = mca_k->T;
    356            
    357410            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
    358415        } // k
    359416    } // p
     
    376433            MCA_VERBOSE2(display_ui32vector(D[k], 0, 9, "%5d", "D\n"));
    377434        }
    378         printf("\n");
     435        MCA_VERBOSE2(printf("\n"));
    379436    }
    380437   
     
    413470// -----------------------------------
    414471{
    415     int p, np = mca->np;
     472    int np = mca->np;
    416473   
    417474    MCA ** mcas = mca->mcas;
    418475    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++) {
    429485        mca_par = mcas[p];
    430486       
    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));
    436492    }
    437493}
     
    442498// -------------------------
    443499{
    444     int p, np = mca->np;
     500    int np = mca->np;
    445501   
    446502    MCA ** mcas = mca->mcas;
     
    451507    uint32 e0, e1;
    452508   
    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++) {
    459516        mca_par = mcas[p];
    460517   
     
    475532        if (p == 0) {
    476533            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
    477537        }
    478538        else {
    479539            free_ui32vector(mca_par->T, e0, e1);
     540#if FEATURES
     541            free_RegionStatsVector(mca_par->stats, e0, e1);
     542#endif
    480543        }
    481544       
    482545        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    }
    486551    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
    494556// -------------------------------
    495557void MCA_Scatter_ImageX(MCA * mca)
     
    498560    // diffusion de l'image binaire source
    499561   
    500     int      np = mca->np;
     562    int np = mca->np;
    501563    uint8 ** X  = mca->mca->X;
    502564   
    503565    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");
    507567    }
    508568   
     
    524584
    525585
    526 // @QM check my modifs...
    527586// ------------------------------
    528587void MCA_Gather_ImageL(MCA * mca)
     
    532591    int np = mca->np;
    533592    uint32 ** E = mca->mca->E;
     593
     594    if (mca->p == 0) {
     595        printf("*** MCA_Gather_ImageL ***\n");
     596    }
    534597
    535598    int i0 = mca->i0;
Note: See TracChangeset for help on using the changeset viewer.