Changeset 269


Ignore:
Timestamp:
Jan 13, 2014, 3:23:38 PM (10 years ago)
Author:
cfuguet
Message:

Modifying the sort application to use the giet_thread_id()
function instead of the giet_proc_id(). This allows this
application to be executed in any processor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/sort/main.c

    r258 r269  
    3131//            processor id and the first processor must have id 0.
    3232//
    33 //      TODO: Replace processor id based identification mechanism by one based
    34 //            on thread id
    35 //
    3633///////////////////////////////////////////////////////////////////////////////
    3734
     
    3936#include "hard_config.h"
    4037#include "barrier.h"
    41 #include "spin_lock.h"
    4238
    4339//////////////////////////////////////////////////////////////////////////
     
    6056
    6157#if (VERBOSE == 1)
    62 #   if (NB_TTY_CHANNELS > 1)
    63 #       define printf(...)     giet_tty_printf(__VA_ARGS__)
    64 #       define puts(...)       giet_tty_puts(__VA_ARGS__)
    65 
    66 #   else    // NB_TTY_CHANNELS == 0
    67 #       define printf(...) \
    68         lock_acquire(&tty_lock); \
    69         giet_tty_printf(__VA_ARGS__); \
    70         lock_release(&tty_lock); 
    71 #   endif
     58#   define printf(...)     giet_tty_printf(__VA_ARGS__)
     59#   define puts(...)       giet_tty_puts(__VA_ARGS__)
    7260#else       // VERBOSE == 0
    7361#   define printf(...)
     
    7563#endif
    7664
    77 #define task0_printf(...) if(procid() == 0) giet_tty_printf(__VA_ARGS__)
     65#define task0_printf(...) if(thread_id == 0) giet_tty_printf(__VA_ARGS__)
    7866
    7967#define exit    giet_exit
     
    10492
    10593giet_barrier_t barrier[8];
    106 giet_lock_t tty_lock;
    10794
    10895__attribute__ ((constructor)) void sort()
    10996{
    110     int proc_id = procid();
     97    int thread_id = giet_thread_id();
     98
    11199    int * src_array;
    112100    int * dst_array;
    113101    int i;
    114102
    115     task0_printf("Starting SORT application\n");
     103    task0_printf("[ Thread 0 ] Starting SORT application\n");
     104
     105    ///////////////////////////
     106    // Barriers Initialization
     107
     108    for (i = 0; i < __builtin_ctz(NPROCS); i++)
     109    {
     110        barrier_init(&barrier[i], NPROCS >> i);
     111    }
    116112
    117113    ////////////////////////
    118114    // Array Initialization
    119115
    120     for (i = IPP * proc_id; i < IPP * (proc_id + 1); i++)
     116    for (i = IPP * thread_id; i < IPP * (thread_id + 1); i++)
    121117    {
    122118        array0[i] = rand();
    123119    }
    124 
    125     ///////////////////////////
    126     // Barriers Initialization
    127 
    128     while((proc_id != 0) && (init_ok == 0));
    129 
    130     if (proc_id == 0)
    131     {
    132         for (i = 0; i < __builtin_ctz(NPROCS); i++)
    133         {
    134             task0_printf("Initializing barrier %d with %d\n", i, NPROCS >> i);
    135             barrier_init(&barrier[i], NPROCS >> i);
    136         }
    137 
    138         asm volatile ("sync");
    139         init_ok = 1;
    140     }
    141 
    142     asm volatile ("sync");
    143     barrier_wait(&barrier[0]);
    144120
    145121    ///////////////////////////////////
    146122    // Parallel sort of array elements
    147123
    148     printf("Proc %d Stage 0: Processor Sorting...\n\r", proc_id);
    149 
    150     bubbleSort(array0, IPP, IPP * proc_id);
    151 
    152     printf("Proc %d Finishing Stage 0...\n\r", proc_id);
     124    printf("[ Thread %d ] Stage 0: Processor Sorting...\n\r", thread_id);
     125
     126    bubbleSort(array0, IPP, IPP * thread_id);
     127
     128    printf("[ Thread %d ] Finishing Stage 0\n\r", thread_id);
    153129
    154130    for (i = 0; i < __builtin_ctz(NPROCS); i++)
     
    157133        barrier_wait(&barrier[i]);
    158134
    159         printf("Proc %d Stage %d: Starting...\n\r", proc_id, i+1);
    160 
    161         if((proc_id % (2 << i)) != 0) exit();
     135        if((thread_id % (2 << i)) != 0)
     136        {
     137            printf("[ Thread %d ] Quits\n\r", thread_id);
     138            exit();
     139        }
     140
     141        printf("[ Thread %d ] Stage %d: Starting...\n\r", thread_id, i+1);
    162142
    163143        if((i % 2) == 0)
     
    174154        merge(src_array, dst_array
    175155                , IPP << i
    176                 , IPP * proc_id
    177                 , IPP * (proc_id + (1 << i))
    178                 , IPP * proc_id
     156                , IPP * thread_id
     157                , IPP * (thread_id + (1 << i))
     158                , IPP * thread_id
    179159                );
    180160
    181         printf("Proc %d Finishing Stage %d...\n\r", proc_id, i + 1);
     161        printf("[ Thread %d ] Finishing Stage %d\n\r", thread_id, i + 1);
    182162    }
    183163
     
    188168    // Verify the resulting array
    189169
    190     if(proc_id == 0)
     170    if(thread_id == 0)
    191171    {
    192172        success = 1;
     
    205185        if (success)
    206186        {
    207             printf("Success!!\n\r");
     187            printf("[ Thread 0 ] Success!!\n\r");
    208188        }
    209189        else
    210190        {
    211             printf("Failure!! Incorrect element: %d\n\r", failure_index);
     191            printf("[ Thread 0 ] Failure!! Incorrect element: %d\n\r", failure_index);
    212192
    213193
Note: See TracChangeset for help on using the changeset viewer.