Changeset 619 for trunk/user/sort


Ignore:
Timestamp:
Feb 12, 2019, 1:15:47 PM (6 years ago)
Author:
alain
Message:

1) Fix a bug in KSH : after the "load" command,

the [ksh] prompt is now printed after completion
of the loaded application.

2) Fix a bug in vmm_handle_cow() : the copy-on-write

use now a hal_remote_memcpy() to replicate the page content.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user/sort/sort.c

    r596 r619  
    2929#include <hal_macros.h>
    3030
    31 #define ARRAY_LENGTH        0x1000    // 4096 values
    32 
     31#define ARRAY_LENGTH        256        // number of values
    3332#define MAX_THREADS         1024       // 16 * 16 * 4
    34 
     33#define USE_DQT_BARRIER     1
    3534#define DISPLAY_ARRAY       0
    3635#define INTERACTIVE_MODE    0
     
    4241typedef struct
    4342{
    44     unsigned int threads;      // total number of threads
     43    unsigned int threads;       // total number of threads
    4544    unsigned int thread_uid;    // thread user index (0 to threads -1)
    4645    unsigned int main_uid;      // main thread user index
     
    206205void main( void )
    207206{
     207    int                    error;
    208208    unsigned int           x_size;             // number of rows
    209209    unsigned int           y_size;             // number of columns
    210210    unsigned int           ncores;             // number of cores per cluster
    211     unsigned int           threads;            // total number of threads
     211    unsigned int           total_threads;      // total number of threads
    212212    unsigned int           thread_uid;         // user defined thread index
    213213    unsigned int           main_cxy;           // cluster identifier for main
     
    226226    // compute number of threads (one thread per core)
    227227    get_config( &x_size , &y_size , &ncores );
    228     threads = x_size * y_size * ncores;
     228    total_threads = x_size * y_size * ncores;
    229229
    230230    // get core coordinates and user index for the main thread
     
    235235
    236236    // checks number of threads
    237     if ( (threads != 1)   && (threads != 2)   && (threads != 4)   &&
    238          (threads != 8)   && (threads != 16 ) && (threads != 32)  &&
    239          (threads != 64)  && (threads != 128) && (threads != 256) &&
    240          (threads != 512) && (threads != 1024) )
     237    if ( (total_threads != 1)   && (total_threads != 2)   && (total_threads != 4)   &&
     238         (total_threads != 8)   && (total_threads != 16 ) && (total_threads != 32)  &&
     239         (total_threads != 64)  && (total_threads != 128) && (total_threads != 256) &&
     240         (total_threads != 512) && (total_threads != 1024) )
    241241    {
    242242        printf("\n[SORT ERROR] number of cores must be power of 2\n");
     
    245245
    246246    // check array size
    247     if ( ARRAY_LENGTH % threads)
     247    if ( ARRAY_LENGTH % total_threads)
    248248    {
    249249        printf("\n[SORT ERROR] array size must be multiple of number of threads\n");
     
    251251    }
    252252
    253     printf("\n[SORT] main starts on core[%x,%d] / %d thread(s) / %d values / PID %x\n",
    254     main_cxy, main_lid, threads, ARRAY_LENGTH, getpid() );
    255 
    256     // Barrier initialization
    257     barrier_attr.x_size   = x_size;
    258     barrier_attr.y_size   = y_size;
    259     barrier_attr.nthreads = ncores;
    260     if( pthread_barrier_init( &barrier, &barrier_attr , threads ) )
     253    printf("\n\n[SORT] main starts on core[%x,%d] / %d threads / %d values / PID %x\n",
     254    main_cxy, main_lid, total_threads, ARRAY_LENGTH, getpid() );
     255
     256    // initialize barrier
     257    if( USE_DQT_BARRIER )
     258    {
     259        barrier_attr.x_size   = x_size;
     260        barrier_attr.y_size   = y_size;
     261        barrier_attr.nthreads = ncores;
     262        error = pthread_barrier_init( &barrier, &barrier_attr , total_threads );
     263    }
     264    else // use SIMPLE_BARRIER
     265    {
     266        error = pthread_barrier_init( &barrier, NULL , total_threads );
     267    }
     268
     269    if( error )
    261270    {
    262271        printf("\n[SORT ERROR] cannot initialise barrier\n" );
     
    290299
    291300                // set sort arguments for all threads
    292                 arg[thread_uid].threads      = threads;
     301                arg[thread_uid].threads      = total_threads;
    293302                arg[thread_uid].thread_uid   = thread_uid;
    294303                arg[thread_uid].main_uid     = main_uid;
     
    330339    sort( &arg[main_uid] );
    331340
     341#if INTERACTIVE_MODE
     342idbg();
     343#endif
     344
     345    // destroy barrier
     346    pthread_barrier_destroy( &barrier );
     347
     348#if INTERACTIVE_MODE
     349idbg();
     350#endif
     351
    332352    // Check result
    333353    int    success = 1;
    334     int*   res_array = ( (threads==  2) ||
    335                          (threads==  8) ||
    336                          (threads== 32) ||
    337                          (threads==128) ||
    338                          (threads==512) ) ? array1 : array0;
     354    int*   res_array = ( (total_threads ==   2) ||
     355                         (total_threads ==   8) ||
     356                         (total_threads == 32) ||
     357                         (total_threads == 128) ||
     358                         (total_threads == 512) ) ? array1 : array0;
    339359   
    340360    for( n=0 ; n<(ARRAY_LENGTH-2) ; n++ )
     
    359379    {
    360380        printf("\n[SORT] success at cycle %d\n", (unsigned int)cycle );
    361         exit( 0 );
    362381    }
    363382    else
    364383    {
    365384        printf("\n[SORT] failure at cycle %d\n", (unsigned int)cycle );
    366         exit( 1 );
    367     }
     385    }
     386
     387#if INTERACTIVE_MODE
     388idbg();
     389#endif
     390
     391    exit( 0 );
    368392
    369393}  // end main()
Note: See TracChangeset for help on using the changeset viewer.