TestFFT.cpp 24.5 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4 5 6
// -*- C++ -*-
/***************************************************************************
 *
 ***************************************************************************/

#include "Ippl.h"
adelmann's avatar
adelmann committed
7 8
#include "Utilities/Timer.h"

uldis_l's avatar
uldis_l committed
9
#include <fstream>
gsell's avatar
gsell committed
10 11 12
#include <complex>
using namespace std;

adelmann's avatar
adelmann committed
13 14 15 16 17 18 19
bool Configure(int argc, char *argv[],
	       unsigned int *nx, unsigned int *ny, unsigned int *nz,
	       int *domainDec, unsigned *processes,  unsigned int *nLoop) 
{

  Inform msg("Configure ");
  Inform errmsg("Error ");
gsell's avatar
gsell committed
20

adelmann's avatar
adelmann committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  for (int i=1; i < argc; ++i) {
    string s(argv[i]);
    if (s == "-grid") {
      *nx = atoi(argv[++i]);
      *ny = atoi(argv[++i]);
      *nz = atoi(argv[++i]);
    }   else if (s == "-Loop") {
      *nLoop = atoi(argv[++i]);
    } else if (s == "-Decomp") {
      *domainDec = atoi(argv[++i]);
    } 
    else {
      errmsg << "Illegal format for or unknown option '" << s.c_str() << "'.";
      errmsg << endl;
    }
  }
gsell's avatar
gsell committed
37

adelmann's avatar
adelmann committed
38 39 40
  *processes = Ippl::getNodes();
  return true;
}
adelmann's avatar
adelmann committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139


void writeMemoryHeader(std::ofstream &outputFile)
{

    std::string dateStr("no time");
    std::string timeStr("no time");
    std::string indent("        ");

    IpplMemoryUsage::IpplMemory_p memory = IpplMemoryUsage::getInstance();

    outputFile << "SDDS1" << std::endl;
    outputFile << "&description\n"
               << indent << "text=\"Memory statistics '"
               << "TestFFT" << "' "
               << dateStr << "" << timeStr << "\",\n"
               << indent << "contents=\"stat parameters\"\n"
               << "&end\n";
    outputFile << "&parameter\n"
               << indent << "name=processors,\n"
               << indent << "type=long,\n"
               << indent << "description=\"Number of Cores used\"\n"
               << "&end\n";
    outputFile << "&parameter\n"
               << indent << "name=revision,\n"
               << indent << "type=string,\n"
               << indent << "description=\"git revision of TestFFT\"\n"
               << "&end\n";
    outputFile << "&parameter\n"
               << indent << "name=flavor,\n"
               << indent << "type=string,\n"
               << indent << "description=\"n.a\"\n"
               << "&end\n";
    outputFile << "&column\n"
               << indent << "name=t,\n"
               << indent << "type=double,\n"
               << indent << "units=ns,\n"
               << indent << "description=\"1 Time\"\n"
               << "&end\n";
    outputFile << "&column\n"
               << indent << "name=memory,\n"
               << indent << "type=double,\n"
               << indent << "units=" + memory->getUnit() + ",\n"
               << indent << "description=\"2 Total Memory\"\n"
               << "&end\n";

    unsigned int columnStart = 3;

    for (int p = 0; p < Ippl::getNodes(); ++p) {
        outputFile << "&column\n"
                   << indent << "name=processor-" << p << ",\n"
                   << indent << "type=double,\n"
                   << indent << "units=" + memory->getUnit() + ",\n"
                   << indent << "description=\"" << columnStart
                   << " Memory per processor " << p << "\"\n"
                   << "&end\n";
        ++columnStart;
    }

    outputFile << "&data\n"
               << indent << "mode=ascii,\n"
               << indent << "no_row_counts=1\n"
               << "&end\n";

    outputFile << Ippl::getNodes() << std::endl;
    outputFile << "IPPL test" << " " << "no version" << " git rev. #" << "no version " << std::endl;
    outputFile << "IPPL test" << std::endl;
}

void open_m(std::ofstream& os, const std::string& fileName, const std::ios_base::openmode mode) {
    os.open(fileName.c_str(), mode);
    os.precision(15);
    os.setf(std::ios::scientific, std::ios::floatfield);
}

void writeMemoryData(std::ofstream &os_memData, unsigned int pwi, unsigned int step)
{
    os_memData << step << "\t";     // 1

    IpplMemoryUsage::IpplMemory_p memory = IpplMemoryUsage::getInstance();

    int nProcs = Ippl::getNodes();
    double total = 0.0;
    for (int p = 0; p < nProcs; ++p) {
        total += memory->getMemoryUsage(p);
    }

    os_memData << total << std::setw(pwi) << "\t";

    for (int p = 0; p < nProcs; p++) {
        os_memData << memory->getMemoryUsage(p)  << std::setw(pwi);

        if ( p < nProcs - 1 )
            os_memData << "\t";

    }
    os_memData << std::endl;
}

adelmann's avatar
adelmann committed
140
int main(int argc, char *argv[])
gsell's avatar
gsell committed
141
{
adelmann's avatar
adelmann committed
142 143 144
  Ippl ippl(argc,argv);
  Inform testmsg(NULL,0);
  const unsigned D=3U;
gsell's avatar
gsell committed
145

adelmann's avatar
adelmann committed
146 147 148 149
  unsigned int nx,ny,nz;
  int domDec;
  unsigned processes;
  unsigned int nLoop; 
gsell's avatar
gsell committed
150

adelmann's avatar
adelmann committed
151 152 153 154 155
  Configure(argc, argv, &nx, &ny, &nz, &domDec, &processes, &nLoop);
  
  // Compression of temporaries:
  bool compressTemps = true;
  bool constInput = true;  // preserve input field in two-field transform
gsell's avatar
gsell committed
156

adelmann's avatar
adelmann committed
157 158 159 160
  unsigned ngrid[D];   // grid sizes
  ngrid[0] = nx;
  ngrid[1] = ny;
  ngrid[2] = ny;
gsell's avatar
gsell committed
161

adelmann's avatar
adelmann committed
162 163 164
  // Used in evaluating correctness of results:
  double realDiff;
  const double errorTol = 1.0e-10;
adelmann's avatar
adelmann committed
165
  //  bool correct = true;
gsell's avatar
gsell committed
166

adelmann's avatar
adelmann committed
167
  // Various counters, constants, etc:
adelmann's avatar
adelmann committed
168 169
  //  double pi = acos(-1.0);
  //double twopi = 2.0*pi;
gsell's avatar
gsell committed
170 171


adelmann's avatar
adelmann committed
172
  // probes etc.
gsell's avatar
gsell committed
173

adelmann's avatar
adelmann committed
174 175 176 177
  std::string baseFn = std::string(argv[0])  + 
    std::string("-mx=") + std::to_string(nx) +
    std::string("-my=") + std::to_string(ny) +
    std::string("-mz=") + std::to_string(nz) +
adelmann's avatar
adelmann committed
178
    std::string("-p=") + std::to_string(processes);
adelmann's avatar
adelmann committed
179

adelmann's avatar
adelmann committed
180 181
  //  unsigned int pwi = 10;
  //  std::ios_base::openmode mode_m = std::ios::out;
adelmann's avatar
adelmann committed
182

adelmann's avatar
adelmann committed
183 184
  //  std::ofstream os_memData;
  //open_m(os_memData, baseFn+std::string(".mem"), mode_m);
adelmann's avatar
adelmann committed
185 186 187

  static IpplTimings::TimerRef mainTimer = IpplTimings::getTimer("mainTimer");           
  IpplTimings::startTimer(mainTimer);                                                    
gsell's avatar
gsell committed
188

adelmann's avatar
adelmann committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
  static IpplTimings::TimerRef fftccppTimer = IpplTimings::getTimer("FFTCCPP");           
  static IpplTimings::TimerRef ifftccppTimer = IpplTimings::getTimer("IFFTCCPP");
  static IpplTimings::TimerRef fftccpsTimer = IpplTimings::getTimer("FFTCCPS");           
  static IpplTimings::TimerRef ifftccpsTimer = IpplTimings::getTimer("IFFTCCPS");

  static IpplTimings::TimerRef fftrcppTimer = IpplTimings::getTimer("FFTRCPP");           
  static IpplTimings::TimerRef ifftrcppTimer = IpplTimings::getTimer("IFFTRCPP");
  static IpplTimings::TimerRef fftrcpsTimer = IpplTimings::getTimer("FFTRCPS");           
  static IpplTimings::TimerRef ifftrcpsTimer = IpplTimings::getTimer("IFFTRCPS");
           
  static IpplTimings::TimerRef fEvalccppTimer = IpplTimings::getTimer("fEvalCCPP");
  static IpplTimings::TimerRef fEvalccpsTimer = IpplTimings::getTimer("fEvalCCPS");

  static IpplTimings::TimerRef fEvalrcppTimer = IpplTimings::getTimer("fEvalRCPP");
  static IpplTimings::TimerRef fEvalrcpsTimer = IpplTimings::getTimer("fEvalRCPS");
           
  static IpplTimings::TimerRef fInitTimer = IpplTimings::getTimer("init fields");           
  static IpplTimings::TimerRef fsetupTimer = IpplTimings::getTimer("setup fields");           

  //  writeMemoryHeader(os_memData);
gsell's avatar
gsell committed
209 210
  
  e_dim_tag allParallel[D];    // Specifies SERIAL, PARALLEL dims
211
  for (unsigned int d=0; d<D; d++)
gsell's avatar
gsell committed
212 213
    allParallel[d] = PARALLEL;

adelmann's avatar
adelmann committed
214 215
  e_dim_tag serialParallel[D]; // Specifies SERIAL, PARALLEL dims
  serialParallel[0] = SERIAL;
216
  for (unsigned int d=1; d<D; d++) 
adelmann's avatar
adelmann committed
217 218 219 220 221 222 223 224 225
    serialParallel[d] = PARALLEL;

  testmsg << "Make fields" << endl;
  IpplTimings::startTimer(fsetupTimer);

  //------------------------complex<-->complex-------------------------------
  // Complex test Fields

  // create standard domain
adelmann's avatar
cleanup  
adelmann committed
226
  NDIndex<D> ndiStandard;
227
  for (unsigned int d=0; d<D; d++) 
adelmann's avatar
cleanup  
adelmann committed
228
    ndiStandard[d] = Index(ngrid[d]);
adelmann's avatar
adelmann committed
229
    // create new domain with axes permuted to match FFT output
adelmann's avatar
cleanup  
adelmann committed
230 231
  NDIndex<D> ndiPermuted;
  ndiPermuted[0] = ndiStandard[D-1];
232
  for (unsigned int d=1; d<D; d++) 
adelmann's avatar
cleanup  
adelmann committed
233 234 235 236 237
    ndiPermuted[d] = ndiStandard[d-1];

  // create half-size domain for RC transform along zeroth axis
  NDIndex<D> ndiStandard0h = ndiStandard;
  ndiStandard0h[0] = Index(ngrid[0]/2+1);
adelmann's avatar
adelmann committed
238

adelmann's avatar
cleanup  
adelmann committed
239 240 241
  // create new domain with axes permuted to match FFT output
  NDIndex<D> ndiPermuted0h;
  ndiPermuted0h[0] = ndiStandard0h[D-1];
242
  for (unsigned int d=1; d<D; d++) 
adelmann's avatar
cleanup  
adelmann committed
243 244 245 246 247 248
    ndiPermuted0h[d] = ndiStandard0h[d-1];

  // create half-size domain for sine transform along zeroth axis
  // and RC transform along first axis
  NDIndex<D> ndiStandard1h = ndiStandard;
  ndiStandard1h[1] = Index(ngrid[1]/2+1);
adelmann's avatar
adelmann committed
249

adelmann's avatar
cleanup  
adelmann committed
250 251 252
  // create new domain with axes permuted to match FFT output
  NDIndex<D> ndiPermuted1h;
  ndiPermuted1h[0] = ndiStandard1h[D-1];
253
  for (unsigned int d=1; d<D; d++) 
adelmann's avatar
cleanup  
adelmann committed
254 255 256
    ndiPermuted1h[d] = ndiStandard1h[d-1];

  // all parallel layout, standard domain, normal axis order
adelmann's avatar
adelmann committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
  FieldLayout<D> layoutPPStan(ndiStandard,allParallel,processes);

  // zeroth axis serial, standard domain, normal axis order
  FieldLayout<D> layoutSPStan(ndiStandard,serialParallel,processes);
  // zeroth axis serial, standard domain, permuted axis order
  FieldLayout<D> layoutSPPerm(ndiPermuted,serialParallel,processes);

  // all parallel layout, zeroth axis half-size domain, normal axis order
  FieldLayout<D> layoutPPStan0h(ndiStandard0h,allParallel,processes);

  // zeroth axis serial, zeroth axis half-size domain, normal axis order
  FieldLayout<D> layoutSPStan0h(ndiStandard0h,serialParallel,processes);
  // zeroth axis serial, zeroth axis half-size domain, permuted axis order
  FieldLayout<D> layoutSPPerm0h(ndiPermuted0h,serialParallel,processes);


  // all parallel layout, first axis half-size domain, normal axis order
  FieldLayout<D> layoutPPStan1h(ndiStandard1h,allParallel,processes);

  // zeroth axis serial, first axis half-size domain, normal axis order
  FieldLayout<D> layoutSPStan1h(ndiStandard1h,serialParallel,processes);
  // zeroth axis serial, first axis half-size domain, permuted axis order
  FieldLayout<D> layoutSPPerm1h(ndiPermuted1h,serialParallel,processes);


adelmann's avatar
cleanup  
adelmann committed
282
  // create test Fields for complex-to-complex FFT
gsell's avatar
gsell committed
283 284
  BareField<std::complex<double>,D> CFieldPPStan(layoutPPStan);
  BareField<std::complex<double>,D> CFieldPPStan_save(layoutPPStan);
adelmann's avatar
cleanup  
adelmann committed
285 286
  BareField<double,D> diffFieldPPStan(layoutPPStan);

gsell's avatar
gsell committed
287 288
  BareField<std::complex<double>,D> CFieldSPStan(layoutSPStan);
  BareField<std::complex<double>,D> CFieldSPStan_save(layoutSPStan);
adelmann's avatar
adelmann committed
289
  BareField<double,D> diffFieldSPStan(layoutSPStan);
gsell's avatar
gsell committed
290
  BareField<std::complex<double>,D> CFieldSPPerm(layoutSPPerm);
adelmann's avatar
adelmann committed
291 292 293 294

  // create test Fields for real-to-complex FFT
  BareField<double,D> RFieldPPStan(layoutPPStan);
  BareField<double,D> RFieldPPStan_save(layoutPPStan);
gsell's avatar
gsell committed
295
  BareField<std::complex<double>,D> CFieldPPStan0h(layoutPPStan0h);
adelmann's avatar
adelmann committed
296 297 298

  BareField<double,D> RFieldSPStan(layoutSPStan);
  BareField<double,D> RFieldSPStan_save(layoutSPStan);
gsell's avatar
gsell committed
299 300
  BareField<std::complex<double>,D> CFieldSPStan0h(layoutSPStan0h);
  BareField<std::complex<double>,D> CFieldSPPerm0h(layoutSPPerm0h);
adelmann's avatar
adelmann committed
301 302

  // create test Fields for sine transform and real-to-complex FFT
gsell's avatar
gsell committed
303
  BareField<std::complex<double>,D> CFieldPPStan1h(layoutPPStan1h);
adelmann's avatar
adelmann committed
304

gsell's avatar
gsell committed
305 306
  BareField<std::complex<double>,D> CFieldSPStan1h(layoutSPStan1h);
  BareField<std::complex<double>,D> CFieldSPPerm1h(layoutSPPerm1h);
adelmann's avatar
adelmann committed
307 308 309 310 311

  testmsg << "Initialize fields ..." << endl;
  IpplTimings::stopTimer(fsetupTimer);

  IpplTimings::startTimer(fInitTimer);
adelmann's avatar
cleanup  
adelmann committed
312
  // Rather more complete test functions (sine or cosine mode):
313 314
  // std::complex<double> sfact(1.0,0.0);      // (1,0) for sine mode; (0,0) for cosine mode
  // std::complex<double> cfact(0.0,0.0);      // (0,0) for sine mode; (1,0) for cosine mode
adelmann's avatar
cleanup  
adelmann committed
315

adelmann's avatar
adelmann committed
316
 /*
adelmann's avatar
cleanup  
adelmann committed
317 318 319 320 321
  double xfact, kx, yfact, ky, zfact, kz;
  xfact = pi/(ngrid[0] + 1.0);
  yfact = 2.0*twopi/(ngrid[1]);
  zfact = 2.0*twopi/(ngrid[2]);
  kx = 1.0; ky = 2.0; kz = 3.0; // wavenumbers
adelmann's avatar
adelmann committed
322 323
 
    CFieldPPStan[ndiStandard[0]][ndiStandard[1]][ndiStandard[2]] = 
adelmann's avatar
cleanup  
adelmann committed
324
    sfact * ( sin( (ndiStandard[0]+1) * kx * xfact +
adelmann's avatar
adelmann committed
325 326
		   ndiStandard[1]    * ky * yfact +
		   ndiStandard[2]    * kz * zfact ) +
adelmann's avatar
cleanup  
adelmann committed
327
	      sin( (ndiStandard[0]+1) * kx * xfact -
adelmann's avatar
adelmann committed
328 329
		   ndiStandard[1]    * ky * yfact -
		   ndiStandard[2]    * kz * zfact ) ) + 
adelmann's avatar
cleanup  
adelmann committed
330
    cfact * (-cos( (ndiStandard[0]+1) * kx * xfact +
adelmann's avatar
adelmann committed
331 332 333 334 335 336
		   ndiStandard[1]    * ky * yfact +
		   ndiStandard[2]    * kz * zfact ) + 
	     cos( (ndiStandard[0]+1) * kx * xfact -
		  ndiStandard[1]    * ky * yfact -
		  ndiStandard[2]    * kz * zfact ) );
  */
gsell's avatar
gsell committed
337 338 339
  CFieldPPStan = std::complex<double>(0.0,0.0);// 
  CFieldSPStan = std::complex<double>(0.0,0.0); //CFieldPPStan;
  CFieldSPPerm = std::complex<double>(0.0,0.0);
adelmann's avatar
cleanup  
adelmann committed
340 341

  CFieldPPStan_save = CFieldPPStan; // Save values for checking later
adelmann's avatar
adelmann committed
342 343 344
  CFieldSPStan_save = CFieldSPStan;
  IpplTimings::stopTimer(fInitTimer);

adelmann's avatar
cleanup  
adelmann committed
345 346 347 348
  // CC FFT tests
  // Instantiate complex<-->complex FFT object
  // Transform in all directions
  FFT<CCTransform,D,double> ccfft(ndiStandard, compressTemps);
adelmann's avatar
adelmann committed
349
  
adelmann's avatar
cleanup  
adelmann committed
350 351 352 353
  // set direction names
  ccfft.setDirectionName(+1, "forward");
  ccfft.setDirectionName(-1, "inverse");

adelmann's avatar
adelmann committed
354
  testmsg << nLoop << " x In-place CC transform using all-parallel layout ..." << endl;
355
  for (uint i=0; i<nLoop; i++) {
adelmann's avatar
adelmann committed
356 357 358 359 360 361 362
    IpplTimings::startTimer(fftccppTimer);
    ccfft.transform("forward", CFieldPPStan);
    IpplTimings::stopTimer(fftccppTimer);
    IpplTimings::startTimer(ifftccppTimer);
    ccfft.transform("inverse", CFieldPPStan);
    IpplTimings::stopTimer(ifftccppTimer);
    IpplTimings::startTimer(fEvalccppTimer);
adelmann's avatar
cleanup  
adelmann committed
363 364
    diffFieldPPStan = Abs(CFieldPPStan - CFieldPPStan_save);
    realDiff = max(diffFieldPPStan);
adelmann's avatar
adelmann committed
365
    if (fabs(realDiff) > errorTol) {
adelmann's avatar
adelmann committed
366
      //      correct = false;
adelmann's avatar
adelmann committed
367 368 369 370
      testmsg << "fabs(realDiff) = " << fabs(realDiff) << endl;
    }
    IpplTimings::stopTimer(fEvalccppTimer);
  }
adelmann's avatar
cleanup  
adelmann committed
371

adelmann's avatar
adelmann committed
372
  testmsg << "In-place CC transform using layout with zeroth dim serial ..." << endl;
373
  for (uint i=0; i<nLoop; i++) {
adelmann's avatar
adelmann committed
374 375 376 377 378 379 380 381 382 383
    IpplTimings::startTimer(fftccpsTimer);
    ccfft.transform("forward", CFieldSPStan);
    IpplTimings::stopTimer(fftccpsTimer);
    IpplTimings::startTimer(ifftccpsTimer);
    ccfft.transform("inverse", CFieldSPStan);
    IpplTimings::stopTimer(ifftccpsTimer);
    IpplTimings::startTimer(fEvalccpsTimer);
    diffFieldSPStan = Abs(CFieldSPStan - CFieldSPStan_save);
    realDiff = max(diffFieldSPStan);
    if (fabs(realDiff) > errorTol) {
adelmann's avatar
adelmann committed
384
      //      correct = false;
adelmann's avatar
adelmann committed
385 386 387
      testmsg << "fabs(realDiff) = " << fabs(realDiff) << endl;
    }
    IpplTimings::stopTimer(fEvalccpsTimer);
adelmann's avatar
cleanup  
adelmann committed
388
  }
gsell's avatar
gsell committed
389

adelmann's avatar
adelmann committed
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
  /*

  //-------------------------------------------------------------------------
    CFieldSPStan = CFieldSPStan_save;  // restore field, just in case ...

    timer.start();
    // Test complex<-->complex transform (simple test: forward then inverse
    // transform, see if get back original values.
    testmsg << "Forward transform ..." << endl;
    ccfft.transform("forward", CFieldSPStan, CFieldSPPerm, constInput);
    testmsg << "Inverse transform ..." << endl;
    ccfft.transform("inverse", CFieldSPPerm, CFieldSPStan, constInput);
    timer.stop();

    diffFieldSPStan = Abs(CFieldSPStan - CFieldSPStan_save);
    realDiff = max(diffFieldSPStan);
    if (fabs(realDiff) > errorTol) {
      correct = false;
      testmsg << "fabs(realDiff) = " << fabs(realDiff) << endl;
    }
    testmsg << "CPU time used = " << timer.cpu_time() << " secs." << endl;
    timer.clear();
    //-------------------------------------------------------------------------
gsell's avatar
gsell committed
413

adelmann's avatar
adelmann committed
414 415 416 417
    */

    // RC FFT tests
    RFieldPPStan = real(CFieldPPStan_save);
gsell's avatar
gsell committed
418
    CFieldPPStan0h = std::complex<double>(0.0,0.0);
adelmann's avatar
adelmann committed
419
    RFieldSPStan = real(CFieldSPStan_save);
gsell's avatar
gsell committed
420 421
    CFieldSPStan0h = std::complex<double>(0.0,0.0);
    CFieldSPPerm0h = std::complex<double>(0.0,0.0);
adelmann's avatar
adelmann committed
422 423 424 425 426 427 428 429 430 431 432

    RFieldPPStan_save = RFieldPPStan;  // save input data for checking results
    RFieldSPStan_save = RFieldSPStan;

    // create RC FFT object
    FFT<RCTransform,D,double> rcfft(ndiStandard, ndiStandard0h, compressTemps);

    rcfft.setDirectionName(+1, "forward");
    rcfft.setDirectionName(-1, "inverse");

    testmsg << "RC transform using all-parallel layout ..." << endl;
433
    for (uint i=0; i<nLoop; i++) {
adelmann's avatar
adelmann committed
434 435 436 437 438 439 440 441 442 443
      IpplTimings::startTimer(fftrcppTimer);
      rcfft.transform("forward", RFieldPPStan, CFieldPPStan0h, constInput);
      IpplTimings::stopTimer(fftrcppTimer);
      IpplTimings::startTimer(ifftrcppTimer);
      rcfft.transform("inverse", CFieldPPStan0h, RFieldPPStan, constInput);
      IpplTimings::stopTimer(ifftrcppTimer);
      IpplTimings::startTimer(fEvalrcppTimer);
      diffFieldPPStan = Abs(RFieldPPStan - RFieldPPStan_save);
      realDiff = max(diffFieldPPStan);
      if (fabs(realDiff) > errorTol) {
adelmann's avatar
adelmann committed
444
	//	correct = false;
adelmann's avatar
adelmann committed
445 446 447 448 449 450 451
	testmsg << "fabs(realDiff) = " << fabs(realDiff) << endl;
      }
      IpplTimings::stopTimer(fEvalrcppTimer);
    }

    testmsg << "RC transform using layout with zeroth dim serial ..." << endl;

452
    for (uint i=0; i<nLoop; i++) {
adelmann's avatar
adelmann committed
453 454 455 456 457 458 459 460 461 462
      IpplTimings::startTimer(fftrcpsTimer);
      rcfft.transform("forward", RFieldSPStan, CFieldSPStan0h, constInput);
      IpplTimings::stopTimer(fftrcpsTimer);
      IpplTimings::startTimer(ifftrcpsTimer);
      rcfft.transform("inverse", CFieldSPStan0h, RFieldSPStan, constInput);
      IpplTimings::stopTimer(ifftrcpsTimer);
      IpplTimings::startTimer(fEvalrcpsTimer);
      diffFieldSPStan = Abs(RFieldSPStan - RFieldSPStan_save);
      realDiff = max(diffFieldSPStan);
      if (fabs(realDiff) > errorTol) {
adelmann's avatar
adelmann committed
463
	//	correct = false;
adelmann's avatar
adelmann committed
464 465 466 467
	testmsg << "fabs(realDiff) = " << fabs(realDiff) << endl;
      }
      IpplTimings::stopTimer(fEvalrcpsTimer);
    }
gsell's avatar
gsell committed
468

adelmann's avatar
cleanup  
adelmann committed
469
    /*
adelmann's avatar
adelmann committed
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498

    RFieldSPStan = RFieldSPStan_save;  // restore field, just in case ...

    testmsg << "RC transform using layout with axes permuted ..." << endl;
    timer.start();

    // Test real<-->complex transform (simple test: forward then inverse
    // transform, see if we get back original values.
    testmsg << "Forward transform ..." << endl;
    rcfft.transform("forward", RFieldSPStan, CFieldSPPerm0h, constInput);
    testmsg << "Inverse transform ..." << endl;
    rcfft.transform("inverse", CFieldSPPerm0h, RFieldSPStan, constInput);
    timer.stop();

    diffFieldSPStan = Abs(RFieldSPStan - RFieldSPStan_save);
    realDiff = max(diffFieldSPStan);
    if (fabs(realDiff) > errorTol) {
      correct = false;
      testmsg << "fabs(realDiff) = " << fabs(realDiff) << endl;
    }
    testmsg << "CPU time used = " << timer.cpu_time() << " secs." << endl;
    timer.clear();

  */

    /*
    // define zeroth axis to be sine transform
    bool sineTransformDims[D];
    sineTransformDims[0] = true;
499
    for (unsigned int d=1; d<D; ++d) sineTransformDims[d] = false;
adelmann's avatar
adelmann committed
500 501 502 503

    // Sine and RC transform tests

    RFieldPPStan = RFieldPPStan_save;
gsell's avatar
gsell committed
504
    CFieldPPStan1h = std::complex<double>(0.0,0.0);
adelmann's avatar
adelmann committed
505
    RFieldSPStan = RFieldSPStan_save;
gsell's avatar
gsell committed
506 507
    CFieldSPStan1h = std::complex<double>(0.0,0.0);
    CFieldSPPerm1h = std::complex<double>(0.0,0.0);
adelmann's avatar
adelmann committed
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650

    // create Sine FFT object
    FFT<SineTransform,D,double> sinefft(ndiStandard, ndiStandard1h,
                                        sineTransformDims, compressTemps);
    // set direction names
    sinefft.setDirectionName(+1,"forward");
    sinefft.setDirectionName(-1,"inverse");

    testmsg << "Sine and RC transform using all-parallel layout ..." << endl;
    timer.start();
    // Test sine transform (simple test: forward then inverse
    // transform, see if we get back original values.
    testmsg << "Forward transform ..." << endl;
    sinefft.transform("forward", RFieldPPStan, CFieldPPStan1h, constInput);
    testmsg << "Inverse transform ..." << endl;
    sinefft.transform("inverse", CFieldPPStan1h, RFieldPPStan, constInput);
    timer.stop();

    diffFieldPPStan = Abs(RFieldPPStan - RFieldPPStan_save);
    realDiff = max(diffFieldPPStan);
    if (fabs(realDiff) > errorTol) {
      correct = false;
      testmsg << "fabs(realDiff) = " << fabs(realDiff) << endl;
    }
    testmsg << "CPU time used = " << timer.cpu_time() << " secs." << endl;
    timer.clear();
    //-------------------------------------------------------------------------

    testmsg << "Sine and RC transform using layout with zeroth dim serial ..."
            << endl;
    timer.start();
    // Test sine transform (simple test: forward then inverse
    // transform, see if we get back original values.
    testmsg << "Forward transform ..." << endl;
    sinefft.transform("forward", RFieldSPStan, CFieldSPStan1h, constInput);
    testmsg << "Inverse transform ..." << endl;
    sinefft.transform("inverse", CFieldSPStan1h, RFieldSPStan, constInput);
    timer.stop();

    diffFieldSPStan = Abs(RFieldSPStan - RFieldSPStan_save);
    realDiff = max(diffFieldSPStan);
    if (fabs(realDiff) > errorTol) {
      correct = false;
      testmsg << "fabs(realDiff) = " << fabs(realDiff) << endl;
    }
    testmsg << "CPU time used = " << timer.cpu_time() << " secs." << endl;
    timer.clear();
    //-------------------------------------------------------------------------

    RFieldSPStan = RFieldSPStan_save;  // restore field, just in case ...

    testmsg << "Sine and RC transform using layout with axes permuted ..."
            << endl;
    timer.start();
    // Test sine transform (simple test: forward then inverse
    // transform, see if we get back original values.
    testmsg << "Forward transform ..." << endl;
    sinefft.transform("forward", RFieldSPStan, CFieldSPPerm1h, constInput);
    testmsg << "Inverse transform ..." << endl;
    sinefft.transform("inverse", CFieldSPPerm1h, RFieldSPStan, constInput);
    timer.stop();

    diffFieldSPStan = Abs(RFieldSPStan - RFieldSPStan_save);
    realDiff = max(diffFieldSPStan);
    if (fabs(realDiff) > errorTol) {
      correct = false;
      testmsg << "fabs(realDiff) = " << fabs(realDiff) << endl;
    }
    testmsg << "CPU time used = " << timer.cpu_time() << " secs." << endl;
    timer.clear();
    //-------------------------------------------------------------------------

    // Sine transform tests
    RFieldPPStan = RFieldPPStan_save;
    RFieldSPStan = RFieldSPStan_save;

    // create Sine FFT object
    FFT<SineTransform,D,double> sinefft2(ndiStandard, sineTransformDims,
                                         compressTemps);
    // set direction names
    sinefft2.setDirectionName(+1,"forward");
    sinefft2.setDirectionName(-1,"inverse");

    testmsg << "In-place sine transform using all-parallel layout ..." << endl;
    timer.start();
    // Test sine transform (simple test: forward then inverse
    // transform, see if we get back original values.
    testmsg << "Forward transform ..." << endl;
    sinefft2.transform("forward", RFieldPPStan);
    testmsg << "Inverse transform ..." << endl;
    sinefft2.transform("inverse", RFieldPPStan);
    timer.stop();

    diffFieldPPStan = Abs(RFieldPPStan - RFieldPPStan_save);
    realDiff = max(diffFieldPPStan);
    if (fabs(realDiff) > errorTol) {
      correct = false;
      testmsg << "fabs(realDiff) = " << fabs(realDiff) << endl;
    }
    testmsg << "CPU time used = " << timer.cpu_time() << " secs." << endl;
    timer.clear();
    //-------------------------------------------------------------------------

    testmsg << "In-place sine transform using layout with zeroth dim serial ..." << endl;
    timer.start();
    // Test sine transform (simple test: forward then inverse
    // transform, see if we get back original values.
    testmsg << "Forward transform ..." << endl;
    sinefft2.transform("forward", RFieldSPStan);
    testmsg << "Inverse transform ..." << endl;
    sinefft2.transform("inverse", RFieldSPStan);
    timer.stop();

    diffFieldSPStan = Abs(RFieldSPStan - RFieldSPStan_save);
    realDiff = max(diffFieldSPStan);
    if (fabs(realDiff) > errorTol) {
      correct = false;
      testmsg << "fabs(realDiff) = " << fabs(realDiff) << endl;
    }
    testmsg << "CPU time used = " << timer.cpu_time() << " secs." << endl;
    timer.clear();
    //-------------------------------------------------------------------------

    RFieldSPStan = RFieldSPStan_save;  // restore input field, just in case

    testmsg << "Two-field sine transform using layout with zeroth dim serial ..." << endl;
    timer.start();
    // Test sine transform (simple test: forward then inverse
    // transform, see if we get back original values.
    testmsg << "Forward transform ..." << endl;
    sinefft2.transform("forward", RFieldSPStan, RFieldSPStan, constInput);
    testmsg << "Inverse transform ..." << endl;
    sinefft2.transform("inverse", RFieldSPStan, RFieldSPStan, constInput);
    timer.stop();

    diffFieldSPStan = Abs(RFieldSPStan - RFieldSPStan_save);
    realDiff = max(diffFieldSPStan);
    if (fabs(realDiff) > errorTol) {
      correct = false;
      testmsg << "fabs(realDiff) = " << fabs(realDiff) << endl;
    }
    testmsg << "CPU time used = " << timer.cpu_time() << " secs." << endl;
    timer.clear();
adelmann's avatar
cleanup  
adelmann committed
651
    */
adelmann's avatar
adelmann committed
652 653 654 655 656 657 658 659 660
    IpplTimings::stopTimer(mainTimer);                                                    
    IpplTimings::print();
    IpplTimings::print(baseFn+std::string(".timing"));
    return 0;
}
/***************************************************************************
 * $RCSfile: TestFFT.cpp.org,v $   $Author: adelmann $
 * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:36 $
 ***************************************************************************/