Changeset 641 for trunk/user/fft/fft.c


Ignore:
Timestamp:
Oct 10, 2019, 1:42:04 PM (5 years ago)
Author:
alain
Message:
  • Fix several bugs.
  • Introduce the "stat" command in KSH.

This almos-mkh version sucessfully executed the FFT application
(65536 complex points) on the TSAR architecture from 1 to 64 cores.

File:
1 edited

Legend:

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

    r640 r641  
    9292// parameters
    9393
    94 #define DEFAULT_M               14              // 16384 data points
     94#define DEFAULT_M               16              // 16384 data points
    9595#define USE_DQT_BARRIER         1               // use DDT barrier if non zero
    9696#define MODE                    COSIN           // DATA array initialisation mode
     
    135135
    136136// instrumentation counters
     137unsigned int   pgfault_nr[THREADS_MAX];    // total number of page faults (per thread)
     138unsigned int   pgfault_cost[THREADS_MAX];  // total page faults cost (per thread)
     139unsigned int   pgfault_max[THREADS_MAX];   // max page faults cost (per thread)
    137140unsigned int   parallel_time[THREADS_MAX]; // total computation time (per thread)
    138141unsigned int   sync_time[THREADS_MAX];     // cumulated waiting time in barriers (per thread)
     
    458461    }
    459462
    460     // get instrumentation results for each thread
     463    // initializes global (all threads) instrumentation values
     464    unsigned int time_para      = parallel_time[0];
     465    unsigned int time_sync      = sync_time[0];
     466    unsigned int pgfaults_nr    = 0;
     467    unsigned int pgfaults_cost  = 0;
     468    unsigned int pgfaults_max   = pgfault_max[0];
     469
     470    // loop on threads to compute global instrumentation results
    461471    for (tid = 0 ; tid < nthreads ; tid++)
    462472    {
    463         snprintf( string , 256 , "- tid %d : Sequencial %d / Parallel %d / Barrier %d\n",
    464         tid, init_time, parallel_time[tid], sync_time[tid] );
     473        snprintf( string , 256 ,
     474        "- tid %d : Seq %d / Para %d / Sync %d / Pgfaults %d ( cost %d / max %d )\n",
     475        tid, init_time, parallel_time[tid], sync_time[tid],
     476        pgfault_nr[tid], (pgfault_cost[tid] / pgfault_nr[tid]) , pgfault_max[tid] );
    465477
    466478        // save  to instrumentation file
     
    468480        if( ret < 0 )
    469481        {
    470             printf("\n[fft error] cannot write thread %d to file <%s>\n", tid, path );
     482            printf("\n[fft error] cannot save thread %d results to file <%s>\n", tid, path );
    471483            printf("%s", string );
    472484            exit(0);
    473485        }
    474     }
    475 
    476     // compute min/max values
    477     unsigned int min_para = parallel_time[0];
    478     unsigned int max_para = parallel_time[0];
    479     unsigned int min_sync = sync_time[0];
    480     unsigned int max_sync = sync_time[0];
    481 
    482     for (tid = 0 ; tid < nthreads ; tid++)
    483     {
    484         if (parallel_time[tid] > max_para)  max_para = parallel_time[tid];
    485         if (parallel_time[tid] < min_para)  min_para = parallel_time[tid];
    486         if (sync_time[tid]     > max_sync)  max_sync = sync_time[tid];
    487         if (sync_time[tid]     < min_sync)  min_sync = sync_time[tid];
    488     }
    489 
    490     // display MIN/MAX values on terminal and save to file
    491     snprintf( string , 256 , "\n      Sequencial  Parallel       Barrier\n"
    492                              "MIN : %d\t | %d\t | %d\t   (cycles)\n"
    493                              "MAX : %d\t | %d\t | %d\t   (cycles)\n",
    494                              (int)init_time, (int)min_para, (int)min_sync,
    495                              (int)init_time, (int)max_para, (int)max_sync );
     486
     487        // compute global values
     488        if (parallel_time[tid] > time_para)    time_para      = parallel_time[tid];
     489        if (sync_time[tid]     > time_sync)    time_sync      = sync_time[tid];
     490                                               pgfaults_nr   += pgfault_nr[tid];
     491                                               pgfaults_cost += pgfault_cost[tid];
     492        if (pgfault_max[tid]   > pgfaults_max) pgfaults_max   = pgfault_max[tid];
     493    }
     494
     495    // display global values on terminal and save to file
     496    snprintf( string , 256 ,
     497    "\nSeq %d / Para %d / Sync %d / Pgfaults %d ( cost %d / max %d )\n",
     498    init_time, time_para, time_sync, pgfaults_nr, (pgfaults_cost / pgfaults_nr), pgfaults_max );
     499
    496500    printf("%s", string );
     501
     502    // save global values to file
    497503    ret = fprintf( f , "%s", string );
     504
    498505    if( ret < 0 )
    499506    {
    500         printf("\n[fft error] cannot write MIN/MAX to file <%s>\n", path );
     507        printf("\n[fft error] cannot save global results to file <%s>\n", path );
     508        exit(0);
     509    }
     510
     511    // close instrumentation file
     512    ret = fclose( f );
     513
     514    if( ret < 0 )
     515    {
     516        printf("\n[fft error] cannot close file <%s>\n", path );
    501517        exit(0);
    502518    }
     
    504520#if DEBUG_MAIN
    505521get_cycle( &debug_cycle );
    506 printf("\n[fft] main close file <%s> at cycle %d\n",
     522printf("\n[fft] main exit <%s> at cycle %d\n",
    507523path, (unsigned int)debug_cycle );
    508524#endif
     
    645661    get_cycle( &parallel_stop );
    646662
    647     // register parallel time
     663    // register parallel time in instrumentation counters
    648664    parallel_time[tid] = (unsigned int)(parallel_stop - parallel_start);
    649665
     666    // get work thread info for page faults
     667    thread_info_t info;
     668    get_thread_info( &info );
     669   
     670    // register page faults in instrumentation counters
     671    pgfault_nr[tid]   = info.false_pgfault_nr +
     672                        info.local_pgfault_nr +
     673                        info.global_pgfault_nr;
     674    pgfault_cost[tid] = info.false_pgfault_cost +
     675                        info.local_pgfault_cost +
     676                        info.global_pgfault_cost;
     677    pgfault_max[tid]  = info.false_pgfault_max +
     678                        info.local_pgfault_max +
     679                        info.global_pgfault_max;
    650680#if DEBUG_WORK
    651681printf("\n[fft] %s : thread %d completes fft / p_start %d / p_stop %d\n",
Note: See TracChangeset for help on using the changeset viewer.