首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行快速傅立叶变换( splash2基准中的快速傅立叶变换)

运行快速傅立叶变换( splash2基准中的快速傅立叶变换)
EN

Stack Overflow用户
提问于 2015-01-26 19:46:35
回答 1查看 390关注 0票数 1

你好,我想在Ubuntu中运行fft代码(下面的代码)。为了运行它,我在我的Ubuntu中安装了m4,然后在进入fft目录后,我得到了很多错误?为什么?有人能帮我吗?在代码的顶部,我看到了一些命令行?我应该如何处理这些命令?我应该如何使用它们?

以下是fft代码:

代码语言:javascript
复制
                                                                   */
/*  Command line options:                                                */
/*                                                                       */
/*  -mM : M = even integer; 2**M total complex data points transformed.  */
/*  -pP : P = number of processors; Must be a power of 2.                */
/*  -nN : N = number of cache lines.                                     */
/*  -lL : L = Log base 2 of cache line length in bytes.                  */
/*  -s  : Print individual processor timing statistics.                  */
/*  -t  : Perform FFT and inverse FFT.  Test output by comparing the     */
/*        integral of the original data to the integral of the data      */
/*        that results from performing the FFT and inverse FFT.          */
/*  -o  : Print out complex data points.                                 */
/*  -h  : Print out command line options.                                */
/*                                                                       */
/*  Note: This version works under both the FORK and SPROC models        */
/*                                                                       */
/*************************************************************************/

#include <stdio.h>
#include <math.h>
#define PAGE_SIZE               4096
#define NUM_CACHE_LINES        65536 
#define LOG2_LINE_SIZE             4
#define PI                         3.1416
#define DEFAULT_M                 10
#define DEFAULT_P                  1

MAIN_ENV

#define SWAP_VALS(a,b) {double tmp; tmp=a; a=b; b=tmp;}

struct GlobalMemory {
  long id;
  LOCKDEC(idlock)
  BARDEC(start)
  long *transtimes;
  long *totaltimes;
  unsigned long starttime;
  unsigned long finishtime;
  unsigned long initdonetime;
} *Global;


long P = DEFAULT_P;
long M = DEFAULT_M;
long N;                  /* N = 2^M                                */
long rootN;              /* rootN = N^1/2                          */
double *x;              /* x is the original time-domain data     */
double *trans;          /* trans is used as scratch space         */
double *umain;          /* umain is roots of unity for 1D FFTs    */
double *umain2;         /* umain2 is entire roots of unity matrix */
long test_result = 0;
long doprint = 0;
long dostats = 0;
long transtime = 0;
long transtime2 = 0;
long avgtranstime = 0;
long avgcomptime = 0;
unsigned long transstart = 0;
unsigned long transend = 0;
long maxtotal=0;
long mintotal=0;
double maxfrac=0;
double minfrac=0;
double avgfractime=0;
long orig_num_lines = NUM_CACHE_LINES;     /* number of cache lines */
long num_cache_lines = NUM_CACHE_LINES;    /* number of cache lines */
long log2_line_size = LOG2_LINE_SIZE;
long line_size;
long rowsperproc;
double ck1;
double ck3;                        /* checksums for testing answer */
long pad_length;

void SlaveStart(void);
double TouchArray(double *x, double *scratch, double *u, double *upriv, long MyFirst, long MyLast);
double CheckSum(double *x);
void InitX(double *x);
void InitU(long N, double *u);
void InitU2(long N, double *u, long n1);
long BitReverse(long M, long k);
void FFT1D(long direction, long M, long N, double *x, double *scratch, double *upriv, double *umain2,
       long MyNum, long *l_transtime, long MyFirst, long MyLast, long pad_length, long test_result, long dostats);
void TwiddleOneCol(long direction, long n1, long j, double *u, double *x, long pad_length);
void Scale(long n1, long N, double *x);
void Transpose(long n1, double *src, double *dest, long MyNum, long MyFirst, long MyLast, long pad_length);
void CopyColumn(long n1, double *src, double *dest);
void Reverse(long N, long M, double *x);
void FFT1DOnce(long direction, long M, long N, double *u, double *x);
void PrintArray(long N, double *x);
void printerr(char *s);
long log_2(long number);

void srand48(long int seedval);
double drand48(void);

int main(int argc, char *argv[])
{
  long i; 
  long c;
  extern char *optarg;
  long m1;
  long factor;
  long pages;
  unsigned long start;

  CLOCK(start);

  while ((c = getopt(argc, argv, "p:m:n:l:stoh")) != -1) {
    switch(c) {
      case 'p': P = atoi(optarg); 
                if (P < 1) {
                  printerr("P must be >= 1\n");
                  exit(-1);
                }
                if (log_2(P) == -1) {
                  printerr("P must be a power of 2\n");
                  exit(-1);
                }
            break;  
      case 'm': M = atoi(optarg); 
                m1 = M/2;
                if (2*m1 != M) {
                  printerr("M must be even\n");
                  exit(-1);
                }
            break;  
      case 'n': num_cache_lines = atoi(optarg); 
                orig_num_lines = num_cache_lines;
                if (num_cache_lines < 1) {
                  printerr("Number of cache lines must be >= 1\n");
                  exit(-1);
                }
            break;  
      case 'l': log2_line_size = atoi(optarg); 
                if (log2_line_size < 0) {
                  printerr("Log base 2 of cache line length in bytes must be >= 0\n");
                  exit(-1);
                }
            break;  
      case 's': dostats = !dostats; 
            break;
      case 't': test_result = !test_result; 
            break;
      case 'o': doprint = !doprint; 
            break;
      case 'h': printf("Usage: FFT <options>\n\n");
                printf("options:\n");
                printf("  -mM : M = even integer; 2**M total complex data points transformed.\n");
                printf("  -pP : P = number of processors; Must be a power of 2.\n");
                printf("  -nN : N = number of cache lines.\n");
                printf("  -lL : L = Log base 2 of cache line length in bytes.\n");
                printf("  -s  : Print individual processor timing statistics.\n");
                printf("  -t  : Perform FFT and inverse FFT.  Test output by comparing the\n");
                printf("        integral of the original data to the integral of the data that\n");
                printf("        results from performing the FFT and inverse FFT.\n");
                printf("  -o  : Print out complex data points.\n");
                printf("  -h  : Print out command line options.\n\n");
                printf("Default: FFT -m%1d -p%1d -n%1d -l%1d\n",
                       DEFAULT_M,DEFAULT_P,NUM_CACHE_LINES,LOG2_LINE_SIZE);
        exit(0);
            break;
    }
  }

  MAIN_INITENV(,80000000);

  N = 1<<M;
  rootN = 1<<(M/2);
  rowsperproc = rootN/P;
  if (rowsperproc == 0) {
    printerr("Matrix not large enough. 2**(M/2) must be >= P\n");
    exit(-1);
  }

  line_size = 1 << log2_line_size;
  if (line_size < 2*sizeof(double)) {
    printf("WARNING: Each element is a complex double (%ld bytes)\n",2*sizeof(double));
    printf("  => Less than one element per cache line\n");
    printf("     Computing transpose blocking factor\n");
    factor = (2*sizeof(double)) / line_size;
    num_cache_lines = orig_num_lines / factor;
  }  
  if (line_size <= 2*sizeof(double)) {
    pad_length = 1;
  } else {
    pad_length = line_size / (2*sizeof(double));
  }

  if (rowsperproc * rootN * 2 * sizeof(double) >= PAGE_SIZE) {
    pages = (2 * pad_length * sizeof(double) * rowsperproc) / PAGE_SIZE;
    if (pages * PAGE_SIZE != 2 * pad_length * sizeof(double) * rowsperproc) {
      pages ++;
    }
    pad_length = (pages * PAGE_SIZE) / (2 * sizeof(double) * rowsperproc);
  } else {
    pad_length = (PAGE_SIZE - (rowsperproc * rootN * 2 * sizeof(double))) /

                 (2 * sizeof(double) * rowsperproc);
    if (pad_length * (2 * sizeof(double) * rowsperproc) !=
        (PAGE_SIZE - (rowsperproc * rootN * 2 * sizeof(double)))) {
      printerr("Padding algorithm unsuccessful\n");
      exit(-1);
    }
  }

  Global = (struct GlobalMemory *) G_MALLOC(sizeof(struct GlobalMemory));
  x = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);
  trans = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);
  umain = (double *) G_MALLOC(2*rootN*sizeof(double));  
  umain2 = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);

  Global->transtimes = (long *) G_MALLOC(P*sizeof(long));  
  Global->totaltimes = (long *) G_MALLOC(P*sizeof(long));  
  if (Global == NULL) {
    printerr("Could not malloc memory for Global\n");
    exit(-1);
  } else if (x == NULL) {
    printerr("Could not malloc memory for x\n");
    exit(-1);
  } else if (trans == NULL) {
    printerr("Could not malloc memory for trans\n");
    exit(-1);
  } else if (umain == NULL) {
    printerr("Could not malloc memory for umain\n");
    exit(-1);
  } else if (umain2 == NULL) {
    printerr("Could not malloc memory for umain2\n");
    exit(-1);
  }

  x = (double *) (((unsigned long) x) + PAGE_SIZE - ((unsigned long) x) % PAGE_SIZE);
  trans = (double *) (((unsigned long) trans) + PAGE_SIZE - ((unsigned long) trans) % PAGE_SIZE);
  umain2 = (double *) (((unsigned long) umain2) + PAGE_SIZE - ((unsigned long) umain2) % PAGE_SIZE);

/* In order to optimize data distribution, the data structures x, trans, 
   and umain2 have been aligned so that each begins on a page boundary. 
   This ensures that the amount of padding calculated by the program is 
   such that each processor's partition ends on a page boundary, thus 
   ensuring that all data from these structures that are needed by a 
   processor can be allocated to its local memory */

/* POSSIBLE ENHANCEMENT:  Here is where one might distribute the x,
   trans, and umain2 data structures across physically distributed 
   memories as desired.

   One way to place data is as follows:

   double *base;
   long i;

   i = ((N/P)+(rootN/P)*pad_length)*2;
   base = &(x[0]);
   for (j=0;j<P;j++) {
    Place all addresses x such that (base <= x < base+i) on node j
    base += i;
   }

   The trans and umain2 data structures can be placed in a similar manner.

   */

  printf("\n");
  printf("FFT with Blocking Transpose\n");
  printf("   %ld Complex Doubles\n",N);
  printf("   %ld Processors\n",P);
  if (num_cache_lines != orig_num_lines) {
    printf("   %ld Cache lines\n",orig_num_lines);
    printf("   %ld Cache lines for blocking transpose\n",num_cache_lines);
  } else {
    printf("   %ld Cache lines\n",num_cache_lines);
  }
  printf("   %d Byte line size\n",(1 << log2_line_size));
  printf("   %d Bytes per page\n",PAGE_SIZE);
  printf("\n");

  BARINIT(Global->start, P);
  LOCKINIT(Global->idlock);
  Global->id = 0;
  InitX(x);                  /* place random values in x */

  if (test_result) {
    ck1 = CheckSum(x);
  }
  if (doprint) {
    printf("Original data values:\n");
    PrintArray(N, x);
  }

  InitU(N,umain);               /* initialize u arrays*/
  InitU2(N,umain2,rootN);

  /* fire off P processes */

  CREATE(SlaveStart, P);
  WAIT_FOR_END(P);

  if (doprint) {
    if (test_result) {
      printf("Data values after inverse FFT:\n");
    } else {
      printf("Data values after FFT:\n");
    }
    PrintArray(N, x);
  }

  transtime = Global->transtimes[0];
  printf("\n");
  printf("                 PROCESS STATISTICS\n");
  printf("            Computation      Transpose     Transpose\n");
  printf(" Proc          Time            Time        Fraction\n");
  printf("    0        %10ld     %10ld      %8.5f\n",
         Global->totaltimes[0],Global->transtimes[0],
         ((double)Global->transtimes[0])/Global->totaltimes[0]);
  if (dostats) {
    transtime2 = Global->transtimes[0];
    avgtranstime = Global->transtimes[0];
    avgcomptime = Global->totaltimes[0];
    maxtotal = Global->totaltimes[0];
    mintotal = Global->totaltimes[0];
    maxfrac = ((double)Global->transtimes[0])/Global->totaltimes[0];
    minfrac = ((double)Global->transtimes[0])/Global->totaltimes[0];
    avgfractime = ((double)Global->transtimes[0])/Global->totaltimes[0];
    for (i=1;i<P;i++) {
      if (Global->transtimes[i] > transtime) {
        transtime = Global->transtimes[i];
      }
      if (Global->transtimes[i] < transtime2) {
        transtime2 = Global->transtimes[i];
      }
      if (Global->totaltimes[i] > maxtotal) {
        maxtotal = Global->totaltimes[i];
      }
      if (Global->totaltimes[i] < mintotal) {
        mintotal = Global->totaltimes[i];
      }
      if (((double)Global->transtimes[i])/Global->totaltimes[i] > maxfrac) {
        maxfrac = ((double)Global->transtimes[i])/Global->totaltimes[i];
      }
      if (((double)Global->transtimes[i])/Global->totaltimes[i] < minfrac) {
        minfrac = ((double)Global->transtimes[i])/Global->totaltimes[i];
      }
      printf("  %3ld        %10ld     %10ld      %8.5f\n",
             i,Global->totaltimes[i],Global->transtimes[i],
             ((double)Global->transtimes[i])/Global->totaltimes[i]);
      avgtranstime += Global->transtimes[i];
      avgcomptime += Global->totaltimes[i];
      avgfractime += ((double)Global->transtimes[i])/Global->totaltimes[i];
    }
    printf("  Avg        %10.0f     %10.0f      %8.5f\n",
           ((double) avgcomptime)/P,((double) avgtranstime)/P,avgfractime/P);
    printf("  Max        %10ld     %10ld      %8.5f\n",
       maxtotal,transtime,maxfrac);
    printf("  Min        %10ld     %10ld      %8.5f\n",
       mintotal,transtime2,minfrac);
  }
  Global->starttime = start;
  printf("\n");
  printf("                 TIMING INFORMATION\n");
  printf("Start time                        : %16lu\n",
      Global->starttime);
  printf("Initialization finish time        : %16lu\n",
      Global->initdonetime);
  printf("Overall finish time               : %16lu\n",
      Global->finishtime);
  printf("Total time with initialization    : %16lu\n",
      Global->finishtime-Global->starttime);
  printf("Total time without initialization : %16lu\n",
      Global->finishtime-Global->initdonetime);
  printf("Overall transpose time            : %16ld\n",
         transtime);
  printf("Overall transpose fraction        : %16.5f\n",
         ((double) transtime)/(Global->finishtime-Global->initdonetime));
  printf("\n");

  if (test_result) {
    ck3 = CheckSum(x);
    printf("              INVERSE FFT TEST RESULTS\n");
    printf("Checksum difference is %.3f (%.3f, %.3f)\n",
       ck1-ck3, ck1, ck3);
    if (fabs(ck1-ck3) < 0.001) {
      printf("TEST PASSED\n");
    } else {
      printf("TEST FAILED\n");
    }
  }

  MAIN_END;
}


void SlaveStart()
{
  long i;
  long MyNum;
  double *upriv;
  long initdone; 
  long finish; 
  long l_transtime=0;
  long MyFirst; 
  long MyLast;

  LOCK(Global->idlock);
    MyNum = Global->id;
    Global->id++;
  UNLOCK(Global->idlock); 

  BARINCLUDE(Global->start);

/* POSSIBLE ENHANCEMENT:  Here is where one might pin processes to
   processors to avoid migration */

  BARRIER(Global->start, P);

  upriv = (double *) malloc(2*(rootN-1)*sizeof(double));  
  if (upriv == NULL) {
    fprintf(stderr,"Proc %ld could not malloc memory for upriv\n",MyNum);
    exit(-1);
  }
  for (i=0;i<2*(rootN-1);i++) {
    upriv[i] = umain[i];
  }   

  MyFirst = rootN*MyNum/P;
  MyLast = rootN*(MyNum+1)/P;

  TouchArray(x, trans, umain2, upriv, MyFirst, MyLast);

  BARRIER(Global->start, P);

/* POSSIBLE ENHANCEMENT:  Here is where one might reset the
   statistics that one is measuring about the parallel execution */

  if ((MyNum == 0) || (dostats)) {
    CLOCK(initdone);
  }

  /* perform forward FFT */
  FFT1D(1, M, N, x, trans, upriv, umain2, MyNum, &l_transtime, MyFirst, 
    MyLast, pad_length, test_result, dostats);

  /* perform backward FFT */
  if (test_result) {
    FFT1D(-1, M, N, x, trans, upriv, umain2, MyNum, &l_transtime, MyFirst, 
      MyLast, pad_length, test_result, dostats);
  }  

  if ((MyNum == 0) || (dostats)) {
    CLOCK(finish);
    Global->transtimes[MyNum] = l_transtime;
    Global->totaltimes[MyNum] = finish-initdone;
  }
  if (MyNum == 0) {
    Global->finishtime = finish;
    Global->initdonetime = initdone;
  }
}


double TouchArray(double *x, double *scratch, double *u, double *upriv, long MyFirst, long MyLast)
{
  long i,j,k;
  double tot = 0.0;

  /* touch my data */
  for (j=0;j<2*(rootN-1);j++) {
    tot += upriv[j];
  }   
  for (j=MyFirst; j<MyLast; j++) {
    k = j * (rootN + pad_length);
    for (i=0;i<rootN;i++) {
      tot += x[2*(k+i)] + x[2*(k+i)+1] + 
             scratch[2*(k+i)] + scratch[2*(k+i)+1] +
         u[2*(k+i)] + u[2*(k+i)+1];
    }
  }  
  return tot;
}


double CheckSum(double *x)
{
  long i,j,k;
  double cks;

  cks = 0.0;
  for (j=0; j<rootN; j++) {
    k = j * (rootN + pad_length);
    for (i=0;i<rootN;i++) {
      cks += x[2*(k+i)] + x[2*(k+i)+1];
    }
  }

  return(cks);
}


void InitX(double *x)
{
  long i,j,k;

  srand48(0);
  for (j=0; j<rootN; j++) {
    k = j * (rootN + pad_length);
    for (i=0;i<rootN;i++) {
      x[2*(k+i)] = drand48();
      x[2*(k+i)+1] = drand48();
    }
  }
}


void InitU(long N, double *u)
{
  long q; 
  long j; 
  long base; 
  long n1;

  for (q=0; 1<<q<N; q++) {  
    n1 = 1<<q;
    base = n1-1;
    for (j=0; j<n1; j++) {
      if (base+j > rootN-1) { 
    return;
      }
      u[2*(base+j)] = cos(2.0*PI*j/(2*n1));
      u[2*(base+j)+1] = -sin(2.0*PI*j/(2*n1));
    }
  }
}


void InitU2(long N, double *u, long n1)
{
  long i,j,k; 

  for (j=0; j<n1; j++) {  
    k = j*(rootN+pad_length);
    for (i=0; i<n1; i++) {  
      u[2*(k+i)] = cos(2.0*PI*i*j/(N));
      u[2*(k+i)+1] = -sin(2.0*PI*i*j/(N));
    }
  }
}


long BitReverse(long M, long k)
{
  long i; 
  long j; 
  long tmp;

  j = 0;
  tmp = k;
  for (i=0; i<M; i++) {
    j = 2*j + (tmp&0x1);
    tmp = tmp>>1;
  }
  return(j);
}


void FFT1D(long direction, long M, long N, double *x, double *scratch, double *upriv, double *umain2,
           long MyNum, long *l_transtime, long MyFirst, long MyLast, long pad_length, long test_result, long dostats)
{
  long j;
  long m1; 
  long n1;
  unsigned long clocktime1;
  unsigned long clocktime2;

  m1 = M/2;
  n1 = 1<<m1;

  BARRIER(Global->start, P);

  if ((MyNum == 0) || (dostats)) {
    CLOCK(clocktime1);
  }

  /* transpose from x into scratch */
  Transpose(n1, x, scratch, MyNum, MyFirst, MyLast, pad_length);

  if ((MyNum == 0) || (dostats)) {
    CLOCK(clocktime2);
    *l_transtime += (clocktime2-clocktime1);
  }

  /* do n1 1D FFTs on columns */
  for (j=MyFirst; j<MyLast; j++) {
    FFT1DOnce(direction, m1, n1, upriv, &scratch[2*j*(n1+pad_length)]);
    TwiddleOneCol(direction, n1, j, umain2, &scratch[2*j*(n1+pad_length)], pad_length);
  }  

  BARRIER(Global->start, P);

  if ((MyNum == 0) || (dostats)) {
    CLOCK(clocktime1);
  }
  /* transpose */
  Transpose(n1, scratch, x, MyNum, MyFirst, MyLast, pad_length);

  if ((MyNum == 0) || (dostats)) {
    CLOCK(clocktime2);
    *l_transtime += (clocktime2-clocktime1);
  }

  /* do n1 1D FFTs on columns again */
  for (j=MyFirst; j<MyLast; j++) {
    FFT1DOnce(direction, m1, n1, upriv, &x[2*j*(n1+pad_length)]);
    if (direction == -1)
      Scale(n1, N, &x[2*j*(n1+pad_length)]);
  }

  BARRIER(Global->start, P);

  if ((MyNum == 0) || (dostats)) {
    CLOCK(clocktime1);
  }

  /* transpose back */
  Transpose(n1, x, scratch, MyNum, MyFirst, MyLast, pad_length);

  if ((MyNum == 0) || (dostats)) {
    CLOCK(clocktime2);
    *l_transtime += (clocktime2-clocktime1);
  }

  BARRIER(Global->start, P);

  /* copy columns from scratch to x */
  if ((test_result) || (doprint)) {  
    for (j=MyFirst; j<MyLast; j++) {
      CopyColumn(n1, &scratch[2*j*(n1+pad_length)], &x[2*j*(n1+pad_length)]); 
    }  
  }  

  BARRIER(Global->start, P);
}


void TwiddleOneCol(long direction, long n1, long j, double *u, double *x, long pad_length)
{
  long i;
  double omega_r; 
  double omega_c; 
  double x_r; 
  double x_c;

  for (i=0; i<n1; i++) {
    omega_r = u[2*(j*(n1+pad_length)+i)];
    omega_c = direction*u[2*(j*(n1+pad_length)+i)+1];  
    x_r = x[2*i]; 
    x_c = x[2*i+1];
    x[2*i] = omega_r*x_r - omega_c*x_c;
    x[2*i+1] = omega_r*x_c + omega_c*x_r;
  }
}


void Scale(long n1, long N, double *x)
{
  long i;

  for (i=0; i<n1; i++) {
    x[2*i] /= N;
    x[2*i+1] /= N;
  }
}


void Transpose(long n1, double *src, double *dest, long MyNum, long MyFirst, long MyLast, long pad_length)
{
  long i; 
  long j; 
  long k; 
  long l; 
  long m;
  long blksize;
  long numblks;
  long firstfirst;
  long h_off;
  long v_off;
  long v;
  long h;
  long n1p;
  long row_count;

  blksize = MyLast-MyFirst;
  numblks = (2*blksize)/num_cache_lines;
  if (numblks * num_cache_lines != 2 * blksize) {
    numblks ++;
  }
  blksize = blksize / numblks;
  firstfirst = MyFirst;
  row_count = n1/P;
  n1p = n1+pad_length;
  for (l=MyNum+1;l<P;l++) {
    v_off = l*row_count;
    for (k=0; k<numblks; k++) {
      h_off = firstfirst;
      for (m=0; m<numblks; m++) {
        for (i=0; i<blksize; i++) {
      v = v_off + i;
          for (j=0; j<blksize; j++) {
        h = h_off + j;
            dest[2*(h*n1p+v)] = src[2*(v*n1p+h)];
            dest[2*(h*n1p+v)+1] = src[2*(v*n1p+h)+1];
          }
        }
    h_off += blksize;
      }
      v_off+=blksize;
    }
  }

  for (l=0;l<MyNum;l++) {
    v_off = l*row_count;
    for (k=0; k<numblks; k++) {
      h_off = firstfirst;
      for (m=0; m<numblks; m++) {
        for (i=0; i<blksize; i++) {
      v = v_off + i;
          for (j=0; j<blksize; j++) {
            h = h_off + j;
            dest[2*(h*n1p+v)] = src[2*(v*n1p+h)];
            dest[2*(h*n1p+v)+1] = src[2*(v*n1p+h)+1];
          }
        }
    h_off += blksize;
      }
      v_off+=blksize;
    }
  }

  v_off = MyNum*row_count;
  for (k=0; k<numblks; k++) {
    h_off = firstfirst;
    for (m=0; m<numblks; m++) {
      for (i=0; i<blksize; i++) {
        v = v_off + i;
        for (j=0; j<blksize; j++) {
          h = h_off + j;
          dest[2*(h*n1p+v)] = src[2*(v*n1p+h)];
          dest[2*(h*n1p+v)+1] = src[2*(v*n1p+h)+1];
    }
      }
      h_off += blksize;
    }
    v_off+=blksize;
  }
}


void CopyColumn(long n1, double *src, double *dest)
{
  long i;

  for (i=0; i<n1; i++) {
    dest[2*i] = src[2*i];
    dest[2*i+1] = src[2*i+1];
  }
}


void Reverse(long N, long M, double *x)
{
  long j, k;

  for (k=0; k<N; k++) {
    j = BitReverse(M, k);
    if (j > k) {
      SWAP_VALS(x[2*j], x[2*k]);
      SWAP_VALS(x[2*j+1], x[2*k+1]);
    }
  }
}


void FFT1DOnce(long direction, long M, long N, double *u, double *x)
{
  long j; 
  long k; 
  long q; 
  long L; 
  long r; 
  long Lstar;
  double *u1; 
  double *x1; 
  double *x2;
  double omega_r; 
  double omega_c; 
  double tau_r; 
  double tau_c; 
  double x_r; 
  double x_c;

  Reverse(N, M, x);

  for (q=1; q<=M; q++) {
    L = 1<<q; r = N/L; Lstar = L/2;
    u1 = &u[2*(Lstar-1)];
    for (k=0; k<r; k++) {
      x1 = &x[2*(k*L)];
      x2 = &x[2*(k*L+Lstar)];
      for (j=0; j<Lstar; j++) {
    omega_r = u1[2*j]; 
        omega_c = direction*u1[2*j+1];
    x_r = x2[2*j]; 
        x_c = x2[2*j+1];
    tau_r = omega_r*x_r - omega_c*x_c;
    tau_c = omega_r*x_c + omega_c*x_r;
    x_r = x1[2*j]; 
        x_c = x1[2*j+1];
    x2[2*j] = x_r - tau_r;
    x2[2*j+1] = x_c - tau_c;
    x1[2*j] = x_r + tau_r;
    x1[2*j+1] = x_c + tau_c;
      }
    }
  }
}


void PrintArray(long N, double *x)
{
  long i, j, k;

  for (i=0; i<rootN; i++) {
    k = i*(rootN+pad_length);
    for (j=0; j<rootN; j++) {
      printf(" %4.2f %4.2f", x[2*(k+j)], x[2*(k+j)+1]);
      if (i*rootN+j != N-1) {
        printf(",");
      }
      if ((i*rootN+j+1) % 8 == 0) {
        printf("\n");
      }
    }
  }
  printf("\n");
  printf("\n");
}


void printerr(char *s)
{
  fprintf(stderr,"ERROR: %s\n",s);
}


long log_2(long number)
{
  long cumulative = 1, out = 0, done = 0;

  while ((cumulative < number) && (!done) && (out < 50)) {
    if (cumulative == number) {
      done = 1;
    } else {
      cumulative = cumulative * 2;
      out ++;
    }
  }

  if (cumulative == number) {
    return(out);
  } else {
    return(-1);
  }
}

以下是我收到的一些错误:

代码语言:javascript
复制
fft.C: In function ‘FFT1D’:
fft.C:603:17: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARRIER(Global->start, P);
                 ^
fft.C:623:17: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARRIER(Global->start, P);
                 ^
fft.C:643:17: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARRIER(Global->start, P);
                 ^
fft.C:657:17: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARRIER(Global->start, P);
                 ^
fft.C:666:17: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARRIER(Global->start, P);
                 ^
fft.C: In function ‘main’:
fft.C:416:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
../../Makefile.config:30: recipe for target 'fft.o' failed
make: *** [fft.o] Error 1
EN

回答 1

Stack Overflow用户

发布于 2015-01-26 21:50:15

~/Desktop/splash2/code/kernels/fft$ make

代码语言:javascript
复制
gcc -c -O3 -pthread -D_POSIX_C_SOURCE=200112 -Wall -W -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wdisabled-optimization -Wpadded -Winline -Wpointer-arith -Wsign-compare -Wendif-labels fft.c
fft.C:59:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘struct’
 struct GlobalMemory {
 ^
fft.C: In function ‘main’:
fft.C:134:3: warning: implicit declaration of function ‘CLOCK’ [-Wimplicit-function-declaration]
   CLOCK(start);
   ^
fft.C:136:3: warning: implicit declaration of function ‘getopt’ [-Wimplicit-function-declaration]
   while ((c = getopt(argc, argv, "p:m:n:l:stoh")) != -1) {
   ^
fft.C:138:7: warning: implicit declaration of function ‘atoi’ [-Wimplicit-function-declaration]
       case 'p': P = atoi(optarg); 
       ^
fft.C:141:19: warning: implicit declaration of function ‘exit’ [-Wimplicit-function-declaration]
                   exit(-1);
                   ^
fft.C:141:19: warning: incompatible implicit declaration of built-in function ‘exit’
fft.C:145:19: warning: incompatible implicit declaration of built-in function ‘exit’
                   exit(-1);
                   ^
fft.C:152:19: warning: incompatible implicit declaration of built-in function ‘exit’
                   exit(-1);
                   ^
fft.C:159:19: warning: incompatible implicit declaration of built-in function ‘exit’
                   exit(-1);
                   ^
fft.C:165:19: warning: incompatible implicit declaration of built-in function ‘exit’
                   exit(-1);
                   ^
fft.C:188:3: warning: incompatible implicit declaration of built-in function ‘exit’
   exit(0);
   ^
fft.C:193:3: warning: implicit declaration of function ‘MAIN_INITENV’ [-Wimplicit-function-declaration]
   MAIN_INITENV(,80000000);
   ^
fft.C:193:16: error: expected expression before ‘,’ token
   MAIN_INITENV(,80000000);
                ^
fft.C:200:5: warning: incompatible implicit declaration of built-in function ‘exit’
     exit(-1);
     ^
fft.C:204:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (line_size < 2*sizeof(double)) {
                 ^
fft.C:211:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (line_size <= 2*sizeof(double)) {
                 ^
fft.C:219:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (pages * PAGE_SIZE != 2 * pad_length * sizeof(double) * rowsperproc) {
                           ^
fft.C:230:7: warning: incompatible implicit declaration of built-in function ‘exit’
       exit(-1);
       ^
fft.C:234:20: warning: implicit declaration of function ‘G_MALLOC’ [-Wimplicit-function-declaration]
   Global = (struct GlobalMemory *) G_MALLOC(sizeof(struct GlobalMemory));
                    ^
fft.C:234:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   Global = (struct GlobalMemory *) G_MALLOC(sizeof(struct GlobalMemory));
            ^
fft.C:235:7: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   x = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);
       ^
fft.C:236:11: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   trans = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);
           ^
fft.C:237:11: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   umain = (double *) G_MALLOC(2*rootN*sizeof(double));  
           ^
fft.C:238:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   umain2 = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);
            ^
fft.C:240:9: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
   Global->transtimes = (long *) G_MALLOC(P*sizeof(long));  
         ^
fft.C:240:24: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   Global->transtimes = (long *) G_MALLOC(P*sizeof(long));  
                        ^
fft.C:241:9: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
   Global->totaltimes = (long *) G_MALLOC(P*sizeof(long));  
         ^
fft.C:241:24: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   Global->totaltimes = (long *) G_MALLOC(P*sizeof(long));  
                        ^
fft.C:244:5: warning: incompatible implicit declaration of built-in function ‘exit’
     exit(-1);
     ^
fft.C:247:5: warning: incompatible implicit declaration of built-in function ‘exit’
     exit(-1);
     ^
fft.C:250:5: warning: incompatible implicit declaration of built-in function ‘exit’
     exit(-1);
     ^
fft.C:253:5: warning: incompatible implicit declaration of built-in function ‘exit’
     exit(-1);
     ^
fft.C:256:5: warning: incompatible implicit declaration of built-in function ‘exit’
     exit(-1);
     ^
fft.C:304:3: warning: implicit declaration of function ‘BARINIT’ [-Wimplicit-function-declaration]
   BARINIT(Global->start, P);
   ^
fft.C:304:17: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARINIT(Global->start, P);
                 ^
fft.C:305:3: warning: implicit declaration of function ‘LOCKINIT’ [-Wimplicit-function-declaration]
   LOCKINIT(Global->idlock);
   ^
fft.C:305:18: error: ‘struct GlobalMemory’ has no member named ‘idlock’
   LOCKINIT(Global->idlock);
                  ^
fft.C:306:9: error: ‘struct GlobalMemory’ has no member named ‘id’
   Global->id = 0;
         ^
fft.C:322:3: warning: implicit declaration of function ‘CREATE’ [-Wimplicit-function-declaration]
   CREATE(SlaveStart, P);
   ^
fft.C:323:3: warning: implicit declaration of function ‘WAIT_FOR_END’ [-Wimplicit-function-declaration]
   WAIT_FOR_END(P);
   ^
fft.C:334:21: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
   transtime = Global->transtimes[0];
                     ^
fft.C:340:16: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
          Global->totaltimes[0],Global->transtimes[0],
                ^
fft.C:340:38: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
          Global->totaltimes[0],Global->transtimes[0],
                                      ^
fft.C:341:25: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
          ((double)Global->transtimes[0])/Global->totaltimes[0]);
                         ^
fft.C:341:48: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
          ((double)Global->transtimes[0])/Global->totaltimes[0]);
                                                ^
fft.C:343:24: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
     transtime2 = Global->transtimes[0];
                        ^
fft.C:344:26: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
     avgtranstime = Global->transtimes[0];
                          ^
fft.C:345:25: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
     avgcomptime = Global->totaltimes[0];
                         ^
fft.C:346:22: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
     maxtotal = Global->totaltimes[0];
                      ^
fft.C:347:22: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
     mintotal = Global->totaltimes[0];
                      ^
fft.C:348:30: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
     maxfrac = ((double)Global->transtimes[0])/Global->totaltimes[0];
                              ^
fft.C:348:53: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
     maxfrac = ((double)Global->transtimes[0])/Global->totaltimes[0];
                                                     ^
fft.C:349:30: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
     minfrac = ((double)Global->transtimes[0])/Global->totaltimes[0];
                              ^
fft.C:349:53: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
     minfrac = ((double)Global->transtimes[0])/Global->totaltimes[0];
                                                     ^
fft.C:350:34: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
     avgfractime = ((double)Global->transtimes[0])/Global->totaltimes[0];
                                  ^
fft.C:350:57: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
     avgfractime = ((double)Global->transtimes[0])/Global->totaltimes[0];
                                                         ^
fft.C:352:17: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
       if (Global->transtimes[i] > transtime) {
                 ^
fft.C:353:27: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
         transtime = Global->transtimes[i];
                           ^
fft.C:355:17: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
       if (Global->transtimes[i] < transtime2) {
                 ^
fft.C:356:28: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
         transtime2 = Global->transtimes[i];
                            ^
fft.C:358:17: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
       if (Global->totaltimes[i] > maxtotal) {
                 ^
fft.C:359:26: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
         maxtotal = Global->totaltimes[i];
                          ^
fft.C:361:17: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
       if (Global->totaltimes[i] < mintotal) {
                 ^
fft.C:362:26: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
         mintotal = Global->totaltimes[i];
                          ^
fft.C:364:26: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
       if (((double)Global->transtimes[i])/Global->totaltimes[i] > maxfrac) {
                          ^
fft.C:364:49: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
       if (((double)Global->transtimes[i])/Global->totaltimes[i] > maxfrac) {
                                                 ^
fft.C:365:34: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
         maxfrac = ((double)Global->transtimes[i])/Global->totaltimes[i];
                                  ^
fft.C:365:57: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
         maxfrac = ((double)Global->transtimes[i])/Global->totaltimes[i];
                                                         ^
fft.C:367:26: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
       if (((double)Global->transtimes[i])/Global->totaltimes[i] < minfrac) {
                          ^
fft.C:367:49: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
       if (((double)Global->transtimes[i])/Global->totaltimes[i] < minfrac) {
                                                 ^
fft.C:368:34: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
         minfrac = ((double)Global->transtimes[i])/Global->totaltimes[i];
                                  ^
fft.C:368:57: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
         minfrac = ((double)Global->transtimes[i])/Global->totaltimes[i];
                                                         ^
fft.C:371:22: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
              i,Global->totaltimes[i],Global->transtimes[i],
                      ^
fft.C:371:44: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
              i,Global->totaltimes[i],Global->transtimes[i],
                                            ^
fft.C:372:29: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
              ((double)Global->transtimes[i])/Global->totaltimes[i]);
                             ^
fft.C:372:52: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
              ((double)Global->transtimes[i])/Global->totaltimes[i]);
                                                    ^
fft.C:373:29: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
       avgtranstime += Global->transtimes[i];
                             ^
fft.C:374:28: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
       avgcomptime += Global->totaltimes[i];
                            ^
fft.C:375:37: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
       avgfractime += ((double)Global->transtimes[i])/Global->totaltimes[i];
                                     ^
fft.C:375:60: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
       avgfractime += ((double)Global->transtimes[i])/Global->totaltimes[i];
                                                            ^
fft.C:384:9: error: ‘struct GlobalMemory’ has no member named ‘starttime’
   Global->starttime = start;
         ^
fft.C:388:10: error: ‘struct GlobalMemory’ has no member named ‘starttime’
    Global->starttime);
          ^
fft.C:390:10: error: ‘struct GlobalMemory’ has no member named ‘initdonetime’
    Global->initdonetime);
          ^
fft.C:392:10: error: ‘struct GlobalMemory’ has no member named ‘finishtime’
    Global->finishtime);
          ^
fft.C:394:10: error: ‘struct GlobalMemory’ has no member named ‘finishtime’
    Global->finishtime-Global->starttime);
          ^
fft.C:394:29: error: ‘struct GlobalMemory’ has no member named ‘starttime’
    Global->finishtime-Global->starttime);
                             ^
fft.C:396:10: error: ‘struct GlobalMemory’ has no member named ‘finishtime’
    Global->finishtime-Global->initdonetime);
          ^
fft.C:396:29: error: ‘struct GlobalMemory’ has no member named ‘initdonetime’
    Global->finishtime-Global->initdonetime);
                             ^
fft.C:400:38: error: ‘struct GlobalMemory’ has no member named ‘finishtime’
          ((double) transtime)/(Global->finishtime-Global->initdonetime));
                                      ^
fft.C:400:57: error: ‘struct GlobalMemory’ has no member named ‘initdonetime’
          ((double) transtime)/(Global->finishtime-Global->initdonetime));
                                                         ^
fft.C:415:3: error: ‘MAIN_END’ undeclared (first use in this function)
   MAIN_END;
   ^
fft.C:415:3: note: each undeclared identifier is reported only once for each function it appears in
fft.C: In function ‘SlaveStart’:
fft.C:430:3: warning: implicit declaration of function ‘LOCK’ [-Wimplicit-function-declaration]
   LOCK(Global->idlock);
   ^
fft.C:430:14: error: ‘struct GlobalMemory’ has no member named ‘idlock’
   LOCK(Global->idlock);
              ^
fft.C:431:19: error: ‘struct GlobalMemory’ has no member named ‘id’
     MyNum = Global->id;
                   ^
fft.C:432:11: error: ‘struct GlobalMemory’ has no member named ‘id’
     Global->id++;
           ^
fft.C:433:3: warning: implicit declaration of function ‘UNLOCK’ [-Wimplicit-function-declaration]
   UNLOCK(Global->idlock); 
   ^
fft.C:433:16: error: ‘struct GlobalMemory’ has no member named ‘idlock’
   UNLOCK(Global->idlock); 
                ^
fft.C:435:3: warning: implicit declaration of function ‘BARINCLUDE’ [-Wimplicit-function-declaration]
   BARINCLUDE(Global->start);
   ^
fft.C:435:20: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARINCLUDE(Global->start);
                    ^
fft.C:440:3: warning: implicit declaration of function ‘BARRIER’ [-Wimplicit-function-declaration]
   BARRIER(Global->start, P);
   ^
fft.C:440:17: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARRIER(Global->start, P);
                 ^
fft.C:442:3: warning: implicit declaration of function ‘malloc’ [-Wimplicit-function-declaration]
   upriv = (double *) malloc(2*(rootN-1)*sizeof(double));  
   ^
fft.C:442:22: warning: incompatible implicit declaration of built-in function ‘malloc’
   upriv = (double *) malloc(2*(rootN-1)*sizeof(double));  
                      ^
fft.C:445:5: warning: incompatible implicit declaration of built-in function ‘exit’
     exit(-1);
     ^
fft.C:456:17: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARRIER(Global->start, P);
                 ^
fft.C:477:11: error: ‘struct GlobalMemory’ has no member named ‘transtimes’
     Global->transtimes[MyNum] = l_transtime;
           ^
fft.C:478:11: error: ‘struct GlobalMemory’ has no member named ‘totaltimes’
     Global->totaltimes[MyNum] = finish-initdone;
           ^
fft.C:481:11: error: ‘struct GlobalMemory’ has no member named ‘finishtime’
     Global->finishtime = finish;
           ^
fft.C:482:11: error: ‘struct GlobalMemory’ has no member named ‘initdonetime’
     Global->initdonetime = initdone;
           ^
fft.C: In function ‘FFT1D’:
fft.C:603:17: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARRIER(Global->start, P);
                 ^
fft.C:623:17: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARRIER(Global->start, P);
                 ^
fft.C:643:17: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARRIER(Global->start, P);
                 ^
fft.C:657:17: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARRIER(Global->start, P);
                 ^
fft.C:666:17: error: ‘struct GlobalMemory’ has no member named ‘start’
   BARRIER(Global->start, P);
                 ^
fft.C: In function ‘main’:
fft.C:416:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
../../Makefile.config:30: recipe for target 'fft.o' failed
make: *** [fft.o] Error 1
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28149500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档