Changeset 257


Ignore:
Timestamp:
Nov 22, 2013, 5:53:31 PM (11 years ago)
Author:
cfuguet
Message:

Modifications in the sort application:

  • Improving comments
  • Allowing processors other than 0 to display some information
  • When using only one TTY, it is shared by all processors. Therefore a spin-lock is used to avoid several processors writing at the

same time

File:
1 edited

Legend:

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

    r256 r257  
    1 //=================================================================================================
    2 // File       : main.c
    3 //
    4 // Date       : 11/2013
    5 //
    6 // Author     : Cesar Fuguet Tortolero
    7 //            :<cesar.fuguet-tortolero@lip6.fr>
    8 //
    9 // Description: Sort application using the GIET-VM OS.
    10 //              This application uses the barrier routines to apply a sort algorithm
    11 //              in several stages.
    12 //=================================================================================================
     1///////////////////////////////////////////////////////////////////////////////
     2// File :
     3//     
     4//      main.c
     5//
     6// Date :
     7//     
     8//      November 2013
     9//
     10// Author :
     11//
     12//      Cesar Fuguet Tortolero <cesar.fuguet-tortolero@lip6.fr>
     13//
     14// Description :
     15//
     16//      Sort application using the GIET-VM OS. This application uses the
     17//      barrier routines to apply a sort algorithm in several stages.
     18//
     19//      Considerations :
     20//
     21//          - It supports up to 256 processors and the number of processors
     22//            must be a power of 2.
     23//
     24//          - If there is only one TTY available, this application uses a spin
     25//            lock to avoid several threads writting at the same time.
     26//
     27//          - This application must be executed on a cache coherent
     28//            architecture. Otherwise some modifications must be applied
     29//
     30//          - The processors executing this application must have a contiguous
     31//            processor id and the first processor must have id 0.
     32//
     33//      TODO: Replace processor id based identification mechanism by one based
     34//            on thread id
     35//
     36///////////////////////////////////////////////////////////////////////////////
    1337
    1438#include "stdio.h"
    1539#include "hard_config.h"
    1640#include "barrier.h"
    17 
    18 #define NPROCS          8
    19 #define ARRAY_LENGTH    (NPROCS * 50)
     41#include "spin_lock.h"
     42
     43//////////////////////////////////////////////////////////////////////////
     44// The NPROCS constant must be modified depending on the desired number of
     45// threads
     46
     47#define NPROCS          16
     48#define ARRAY_LENGTH    (NPROCS * 128)
    2049#define IPP             (ARRAY_LENGTH / NPROCS) // ITEMS PER PROCESSOR
    2150
    22 // Other processors than 0 display algorithm state
     51////////////////////////////////////////////////////////////////////////////////
     52// Processors other than 0 display algorithm state
     53// The processor 0 always displays some information so this does not affect him
     54
    2355#define VERBOSE         1
    2456
     57///////////////////////////////////////////////////////////////////////
     58// Define printf according to verbosity option and number of available
     59// TTY
     60
    2561#if (VERBOSE == 1)
    26 #define printf(...)     giet_tty_printf(__VA_ARGS__)
    27 #define puts(...)       giet_tty_puts(__VA_ARGS__)
    28 #else
    29 #define printf(...)
    30 #define puts(...)
     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
     72#else       // VERBOSE == 0
     73#   define printf(...)
     74#   define puts(...)
    3175#endif
     76
     77#define task0_printf(...) if(procid() == 0) giet_tty_printf(__VA_ARGS__)
    3278
    3379#define exit    giet_exit
    3480#define procid  giet_procid
    3581#define rand    giet_rand
    36 
    37 #define task0_printf(...) if(procid() == 0) giet_tty_printf(__VA_ARGS__)
    3882
    3983int array0[ARRAY_LENGTH];
     
    5599        int init_pos_result);
    56100
    57 // this application support at most 256 processors
    58 // number of barriers = log2(NPROCS)
     101///////////////////////////////////////////////////
     102// This application support at most 256 processors
     103// Number of barriers = log2(NPROCS)
     104
    59105giet_barrier_t barrier[8];
     106giet_lock_t tty_lock;
    60107
    61108__attribute__ ((constructor)) void sort()
     
    66113    int i;
    67114
    68     /**************************************************************************/
    69     /* Hello World */
    70 
    71115    task0_printf("Starting SORT application\n");
    72116
    73     /**************************************************************************/
    74     /* Array Inititialitatin */
     117    ////////////////////////
     118    // Array Initialization
    75119
    76120    for (i = IPP * proc_id; i < IPP * (proc_id + 1); i++)
     
    79123    }
    80124
    81     /**************************************************************************/
    82     /* Barriers Inititialitatin */
     125    ///////////////////////////
     126    // Barriers Initialization
    83127
    84128    while((proc_id != 0) && (init_ok == 0));
     
    88132        for (i = 0; i < __builtin_ctz(NPROCS); i++)
    89133        {
    90             printf("Initializing barrier %d with %d\n", i, NPROCS >> i);
     134            task0_printf("Initializing barrier %d with %d\n", i, NPROCS >> i);
    91135            barrier_init(&barrier[i], NPROCS >> i);
    92136        }
     
    99143    barrier_wait(&barrier[0]);
    100144
    101     /**************************************************************************/
    102     /* Parallel sorting of array pieces */
    103 
    104     task0_printf("Stage 0: Processor Sorting...\n\r");
     145    ///////////////////////////////////
     146    // Parallel sort of array elements
     147
     148    printf("Proc %d Stage 0: Processor Sorting...\n\r", proc_id);
     149
    105150    bubbleSort(array0, IPP, IPP * proc_id);
    106     task0_printf("Finishing Stage 0...\n\r");
     151
     152    printf("Proc %d Finishing Stage 0...\n\r", proc_id);
    107153
    108154    for (i = 0; i < __builtin_ctz(NPROCS); i++)
     
    110156        asm volatile ("sync");
    111157        barrier_wait(&barrier[i]);
    112         task0_printf("Stage %d: Starting...\n\r", i+1);
     158
     159        printf("Proc %d Stage %d: Starting...\n\r", proc_id, i+1);
    113160
    114161        if((proc_id % (2 << i)) != 0) exit();
     
    132179                );
    133180
    134         task0_printf("Finishing Stage %d...\n\r", i + 1);
     181        printf("Proc %d Finishing Stage %d...\n\r", proc_id, i + 1);
    135182    }
    136183
    137184    int success;
    138185    int failure_index;
     186
     187    //////////////////////////////
     188    // Verify the resulting array
    139189
    140190    if(proc_id == 0)
Note: See TracChangeset for help on using the changeset viewer.