Changeset 638 for trunk/user/fft/fft.c
- Timestamp:
- Jul 18, 2019, 6:48:08 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user/fft/fft.c
r637 r638 97 97 #define CHECK 0 98 98 #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) 100 100 #define DEBUG_FFT1D 0 // trace FFT1D() function (detailed if odd) 101 101 #define DEBUG_ROW 0 // trace FFTRow() function (detailed if odd) … … 548 548 #endif 549 549 550 // core 0 allocatememory from the local cluster550 // thread on core 0 allocates memory from the local cluster 551 551 // for the distributed data[], trans[], twid[] buffers 552 // and for the private upriv[] buffer553 552 if( lid == 0 ) 554 553 { 555 unsigned int data_size 554 unsigned int data_size = (N / nclusters) * 2 * sizeof(double); 556 555 unsigned int coefs_size = (rootN - 1) * 2 * sizeof(double); 557 556 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 566 583 get_cycle( &barrier_start ); 567 584 pthread_barrier_wait( &barrier ); … … 570 587 571 588 #if DEBUG_WORK 572 printf("\n[fft] %s : thread %d exit first barrier/ cycle %d\n",589 printf("\n[fft] %s : thread %d exit barrier for buffer allocation / cycle %d\n", 573 590 __FUNCTION__, tid, (unsigned int)barrier_stop ); 574 591 #endif 575 592 576 // all threads initialize data[] local array593 // all threads contribute to data[] local array initialisation 577 594 InitD( data , MODE , tid ); 578 595 579 // all threads initialize twid[] local array596 // all threads contribute to data[] local array initialisation 580 597 InitT( twid , tid ); 581 598 582 // all threads initialise private upriv[] array 583 InitU( upriv ); 584 585 // BARRIER 599 // BARRIER to wait distributed buffers initialisation 586 600 get_cycle( &barrier_start ); 587 601 pthread_barrier_wait( &barrier ); … … 590 604 591 605 #if DEBUG_WORK 592 printf("\n[fft] %s : thread %d exit second barrier/ cycle %d\n",606 printf("\n[fft] %s : thread %d exit barrier for buffer initialisation / cycle %d\n", 593 607 __FUNCTION__, tid, (unsigned int)barrier_stop ); 594 608 #endif 595 609 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 597 624 MyFirst = rootN * tid / nthreads; 598 625 MyLast = rootN * (tid + 1) / nthreads; 599 626 600 // perform forward FFT627 // all threads perform forward FFT 601 628 FFT1D( 1 , data , trans , upriv , twid , tid , MyFirst , MyLast ); 602 629 … … 808 835 unsigned int base; 809 836 unsigned int n1; 810 double phi;837 double phi; 811 838 812 839 for (q = 0 ; ((unsigned int)(1 << q) < N) ; q++)
Note: See TracChangeset
for help on using the changeset viewer.