Changeset 638 for trunk/user


Ignore:
Timestamp:
Jul 18, 2019, 6:48:08 PM (5 years ago)
Author:
alain
Message:

Fix a bug in the FFT work function (wrong upriv buffer allocation).

Location:
trunk/user
Files:
2 edited

Legend:

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

    r637 r638  
    9797#define CHECK                   0               
    9898#define DEBUG_MAIN              1               // trace main() function (detailed if odd)
    99 #define DEBUG_WORK              1               // trace work() function (detailed if odd)
     99#define DEBUG_WORK              0               // trace work() function (detailed if odd)
    100100#define DEBUG_FFT1D             0               // trace FFT1D() function (detailed if odd)
    101101#define DEBUG_ROW               0               // trace FFTRow() function (detailed if odd)
     
    548548#endif
    549549
    550     // core 0 allocate memory from the local cluster
     550    // thread on core 0 allocates memory from the local cluster
    551551    // for the distributed data[], trans[], twid[] buffers
    552     // and for the private upriv[] buffer
    553552    if( lid == 0 )
    554553    {
    555         unsigned int data_size  = (N / nclusters) * 2 * sizeof(double);
     554        unsigned int data_size = (N / nclusters) * 2 * sizeof(double);
    556555        unsigned int coefs_size = (rootN - 1) * 2 * sizeof(double); 
    557556
    558         data[cid]   = (double *)malloc( data_size );
    559         trans[cid]  = (double *)malloc( data_size );
    560         twid[cid]   = (double *)malloc( data_size );
    561 
    562         upriv       = (double *)malloc( coefs_size );
    563     }
    564 
    565     // BARRIER
     557        data[cid] = (double *)malloc( data_size );
     558        if( data[cid] == NULL )
     559        {
     560            printf("\n[fft_error] in work : cannot allocate data[%d] buffer\n", cid );
     561            pthread_barrier_wait( parent_barrier );
     562            pthread_exit( NULL );
     563        }
     564       
     565        trans[cid] = (double *)malloc( data_size );
     566        if( trans[cid] == NULL )
     567        {
     568            printf("\n[fft_error] in work : cannot allocate trans[%d] buffer\n", cid );
     569            pthread_barrier_wait( parent_barrier );
     570            pthread_exit( NULL );
     571        }
     572       
     573        twid[cid] = (double *)malloc( data_size );
     574        if( twid[cid] == NULL )
     575        {
     576            printf("\n[fft_error] in work : cannot allocate twid[%d] buffer\n", cid );
     577            pthread_barrier_wait( parent_barrier );
     578            pthread_exit( NULL );
     579        }
     580    }
     581
     582    // BARRIER to wait distributed buffers allocation
    566583    get_cycle( &barrier_start );
    567584    pthread_barrier_wait( &barrier );
     
    570587
    571588#if DEBUG_WORK
    572 printf("\n[fft] %s : thread %d exit first barrier / cycle %d\n",
     589printf("\n[fft] %s : thread %d exit barrier for buffer allocation / cycle %d\n",
    573590__FUNCTION__, tid, (unsigned int)barrier_stop );
    574591#endif
    575592
    576     // all threads initialize data[] local array
     593    // all threads contribute to data[] local array initialisation
    577594    InitD( data , MODE , tid );
    578595
    579     // all threads initialize twid[] local array
     596    // all threads contribute to data[] local array initialisation
    580597    InitT( twid , tid );
    581598   
    582     // all threads initialise private upriv[] array
    583     InitU( upriv );
    584 
    585     // BARRIER
     599    // BARRIER to wait distributed buffers initialisation
    586600    get_cycle( &barrier_start );
    587601    pthread_barrier_wait( &barrier );
     
    590604
    591605#if DEBUG_WORK
    592 printf("\n[fft] %s : thread %d exit second barrier / cycle %d\n",
     606printf("\n[fft] %s : thread %d exit barrier for buffer initialisation / cycle %d\n",
    593607__FUNCTION__, tid, (unsigned int)barrier_stop );
    594608#endif
    595609
    596     // compute first and last rows handled by the thread
     610    // all threads allocate memory from the local cluster
     611    // for the private upriv[] buffer
     612    upriv = (double *)malloc( (rootN - 1) * 2 * sizeof(double) );
     613    if( upriv == NULL )
     614    {
     615        printf("\n[fft_error] in work : cannot allocate trans[%d] buffer\n", cid );
     616        pthread_barrier_wait( parent_barrier );
     617        pthread_exit( NULL );
     618    }
     619
     620    // all threads initialise the private upriv[] array
     621    InitU( upriv );
     622
     623    // all threads compute first and last rows handled by the thread
    597624    MyFirst = rootN * tid / nthreads;
    598625    MyLast  = rootN * (tid + 1) / nthreads;
    599626
    600     // perform forward FFT
     627    // all threads perform forward FFT
    601628    FFT1D( 1 , data , trans , upriv , twid , tid , MyFirst , MyLast );
    602629
     
    808835    unsigned int    base;
    809836    unsigned int    n1;
    810     double  phi;
     837    double          phi;
    811838
    812839    for (q = 0 ; ((unsigned int)(1 << q) < N) ; q++)
  • trunk/user/ksh/ksh.c

    r637 r638  
    12031203
    12041204
    1205 /* 2. second direct command
     1205// 2. second direct command
    12061206if( sem_wait( &semaphore ) )
    12071207{
     
    12161216strcpy( cmd , "load bin/user/fft.elf" );
    12171217execute( cmd );
    1218 */
     1218//
    12191219
    12201220
Note: See TracChangeset for help on using the changeset viewer.