Commits

Rio Yokota committed a321638

Detach macro.h and logger.h.

Comments (0)

Files changed (11)

examples/serial.cxx

   Cells cells, jcells;
   Dataset DATA;
   SerialFMM FMM;
-  FMM.NCRIT = args->ncrit;
-  FMM.NSPAWN = args->nspawn;
-  FMM.IMAGES = args->images;
-  FMM.THETA = args->theta;
+  FMM.NCRIT = args->NCRIT;
+  FMM.NSPAWN = args->NSPAWN;
+  FMM.IMAGES = args->IMAGES;
+  FMM.THETA = args->THETA;
   FMM.printNow = true;
 #if AUTO
   FMM.timeKernels();

include/evaluator.h

 #ifndef evaluator_h
 #define evaluator_h
 #include "kernel.h"
+#include "logger.h"
 #include "thread.h"
 #if COUNT
 #define count(N) N++
 #define count(N)
 #endif
 
-class Evaluator : public Kernel {
+class Evaluator : public Kernel, public Logger {
 private:
   real_t timeP2P;                                               //!< P2P execution time
   real_t timeM2L;                                               //!< M2L execution time
 #ifndef kernel_h
 #define kernel_h
 #include <cmath>
-#include "sort.h"
+#include "types.h"
 
-class Kernel : public Sort, public Parameters {
+class Kernel : public Parameters {
 protected:
+  vec3 Xperiodic;
   C_iter Ci0;
   C_iter Cj0;
 
 #include <fstream>
 #include <iomanip>
 #include <iostream>
+#include <map>
+#include <pthread.h>
+#include <queue>
+#include <string>
 #include <sys/time.h>
 #include "types.h"
 
+#if PAPI
+#include <papi.h>
+#endif
+
+//! Structure for pthread based trace
+struct Trace {
+  pthread_t thread;                                             //!< pthread id
+  double    begin;                                              //!< Begin timer of trace
+  double    end;                                                //!< End timer of trace
+  int       color;                                              //!< Color of trace
+};
+typedef std::map<pthread_t,double>             ThreadTrace;     //!< Map of pthread id to traced value
+typedef std::map<pthread_t,int>                ThreadMap;       //!< Map of pthread id to thread id
+typedef std::queue<Trace>                      Traces;          //!< Queue of traces
+typedef std::map<std::string,double>           Timer;           //!< Map of timer event name to timed value
+typedef std::map<std::string,double>::iterator TI_iter;         //!< Iterator of timer event name map
+
 //! Timer and Trace logger
 class Logger {
 private:
   Timer           timer;                                        //!< Stores timings for all events
   Traces          traces;                                       //!< Stores traces for all events
   pthread_mutex_t mutex;                                        //!< Pthread communicator
+#if PAPI
+  int PAPIEVENT;                                                //!< PAPI event handle
+#endif
 
 //! Timer function
   double get_time() const {
 //! Constructor
   Logger() : timerFile("time.dat"),                             // Open timer log file
              beginTimer(), timer(), traces(), mutex(),          // Initializing class variables (empty)
+#if PAPI
+             PAPIEVENT(PAPI_NULL),                              // PAPI event handle
+#endif
              stringLength(20),                                  // Max length of event name
              printNow(false) {                                  // Don't print timings by default
     pthread_mutex_init(&mutex,NULL);                            // Initialize pthread communicator
+#ifndef macros_h
+#define macros_h
+
+// Intel compiler warning disable
+#ifdef __INTEL_COMPILER
+#pragma warning(disable:193 383 444 981 1572 2259)
+#endif
+
+// Override assertion
+#if ASSERT
+#include <cassert>
+#else
+#define assert(x)
+#endif
+
+#endif
 
 public:
   int MPIRANK;                                                  //!< Rank of MPI communicator
-  int MPISIZE:                                                  //!< Size of MPI communicator
+  int MPISIZE;                                                  //!< Size of MPI communicator
 
 public:
 //! Constructor, initialize WAIT time

include/options.h

 struct Args {
   int numBodies;
   int numTarget;
-  int ncrit;
-  int nspawn;
-  int images;
-  double theta;
+  int NCRIT;
+  int NSPAWN;
+  int IMAGES;
+  double THETA;
   int buildOnly;
   int mutual;
   const char * distribution;
 static void showArgs(Args * args) {
   printf("numBodies: %d\n", args->numBodies);
   printf("numTarget: %d\n", args->numTarget);
-  printf("ncrit: %d\n", args->ncrit);
-  printf("nspawn: %d\n", args->nspawn);
-  printf("images: %d\n", args->images);
-  printf("theta: %f\n", args->theta);
+  printf("ncrit: %d\n", args->NCRIT);
+  printf("nspawn: %d\n", args->NSPAWN);
+  printf("images: %d\n", args->IMAGES);
+  printf("theta: %f\n", args->THETA);
   printf("buildOnly: %d\n", args->buildOnly);
   printf("mutual: %d\n", args->mutual);
   printf("distribution: %s\n", args->distribution);
   Args args;
   args.numBodies = 1000000;
   args.numTarget = 100;
-  args.ncrit = 10;
-  args.nspawn = 1000;
-  args.images = 0;
-  args.theta = 0.6;
+  args.NCRIT = 10;
+  args.NSPAWN = 1000;
+  args.IMAGES = 0;
+  args.THETA = 0.6;
   args.buildOnly = 0;
   args.mutual = 1;
   args.distribution = "cube";
           name,
           args.numBodies,
           args.numTarget,
-          args.ncrit,
-          args.nspawn,
-          args.images,
-          args.theta,
+          args.NCRIT,
+          args.NSPAWN,
+          args.IMAGES,
+          args.THETA,
           args.buildOnly,
           args.mutual,
           args.distribution);
       args->numTarget = atoi(optarg);
       break;
     case 'c':
-      args->ncrit = atoi(optarg);
+      args->NCRIT = atoi(optarg);
       break;
     case 's':
-      args->nspawn = atoi(optarg);
+      args->NSPAWN = atoi(optarg);
       break;
     case 'i':
-      args->images = atoi(optarg);
+      args->IMAGES = atoi(optarg);
       break;
     case 'h':
-      args->theta = atof(optarg);
+      args->THETA = atof(optarg);
       break;
     case 'b':
       args->buildOnly = atoi(optarg);

include/parameters.h

 #define parameters_h
 
 // Compile-time parameters
-static const int P = 3;                                         //!< Order of expansions
+const int P = 3;                                                //!< Order of expansions
+const float EPS2 = .0;                                          //!< Softening parameter (squared)
 
 // Runtime parameters
 struct Parameters {
   int NSPAWN;                                                   //!< Threshold of NDLEAF for spawning new threads
   int IMAGES;                                                   //!< Number of periodic image sublevels
   float THETA;                                                  //!< Multipole acceptance criteria
-  float EPS2;                                                   //!< Softening parameter (squared)
-  Parameters() : NCRIT(10), NSPAWN(1000), IMAGES(0), THETA(.6), EPS2(.0) {}
+  Parameters() : NCRIT(10), NSPAWN(1000), IMAGES(0), THETA(.6) {}
 };
 
 #endif
 #ifndef sort_h
 #define sort_h
-#include "logger.h"
+#include "types.h"
 
 //! Custom bucket sort for body and cell structures
-class Sort : public Logger {
+class Sort {
 private:
   std::vector<int> bucket;                                      //!< Bucket for sorting
 
   template<typename T>
   void sortICELL(T &values, T &buffer, int Imin,
                  int numBucket, bool ascend, int begin, int end) {
-    startTimer("Fill bucket");                                  // Start timer
     for (int i=0; i<numBucket; i++) bucket[i] = 0;              // Initialize bucket
     for (int i=begin; i<end; i++) bucket[values[i].ICELL-Imin]++;// Fill bucket
     for (int i=1; i<numBucket; i++) bucket[i] += bucket[i-1];   // Scan bucket
-    stopTimer("Fill bucket");                                   // Stop timer
-    startTimer("Empty bucket");                                 // Start timer
     for (int i=end-1; i>=begin; i--) {                          // Loop over data backwards
       bucket[values[i].ICELL-Imin]--;                           //  Empty bucket
       int inew = bucket[values[i].ICELL-Imin]+begin;            //  Permutation index
       buffer[inew] = values[i];                                 //  Fill buffer
     }                                                           // End loop over data
-    stopTimer("Empty bucket");                                  // Stop timer
-    startTimer("Copy value");                                   // Start timer
     if (ascend) {                                               // If sorting in ascending order
       for (int i=begin; i<end; i++) values[i] = buffer[i];      //  Copy back bodiess in order
     } else {                                                    // If sorting in descending order
       for (int i=begin; i<end; i++) values[end-i+begin-1] = buffer[i];// Copy back bodiess in reverse order
     }                                                           // Endif for sorting order
-    stopTimer("Copy value");                                    // Stop timer
   }
 
 public:
-//! Constructor
-  Sort() : bucket() {}
-//! Destructor
-  ~Sort() {}
-
 //! Sort bodies accoring to cell index
   void sortBodies(Bodies &bodies, Bodies &buffer, bool ascend=true, int begin=0, int end=0) {
-    startTimer("Sort bodies");                                  // Start timer
     if (bodies.size() == 0) return;                             // Don't do anything if vector is empty
     if (end == 0) end = bodies.size();                          // Default range is the whole vector
     int numBucket = 0;                                          // Initialize bucket size
     int Imin = 0;                                               // Initialize minimum index
     getBucketSize(bodies,begin,end,Imin,numBucket);             // Get bucket size for sorting
-    stopTimer("Sort bodies");                                   // Stop timer
     sortICELL(bodies,buffer,Imin,numBucket,ascend,begin,end);   // Call bucket sort for small indices
   }
-
-//! Sort cells according to cell index
-  void sortCells(Cells &cells, Cells &buffer, bool ascend=true, int begin=0, int end=0) {
-    startTimer("Sort cells");                                   // Start timer
-    if (cells.size() == 0) return;                              // Don't do anything if vector is empty
-    if (end == 0) end = cells.size();                           // Default rage is the whole vector
-    int numBucket = 0;                                          // Initialize bucket size
-    int Imin = 0;                                               // Initialize minimum index
-    getBucketSize(cells,begin,end,Imin,numBucket);              // Get bucket size for sorting
-    stopTimer("Sort cells");                                    // Stop timer
-    if (buffer.size() < cells.size()) buffer.resize(cells.size());// Resize sort buffer if necessary
-    sortICELL(cells,buffer,Imin,numBucket,ascend,begin,end);    // Call bucket sort for small indices
-  }
 };
 
 #endif
 #ifndef thread_h
 #define thread_h
+
+// Thread model
 #if TBB
 #include <tbb/task_group.h>
 #define TASKS 1
 
 #endif
 
+// Task based threading macros
 #if TASKS
 
 #define __init_tasks__                task_group tg
 #ifndef types_h
 #define types_h
-#ifdef __INTEL_COMPILER
-#pragma warning(disable:193 383 444 981 1572 2259)
-#endif
-
-#include <map>
+#include "macros.h"
 #include "parameters.h"
-#include <pthread.h>
 #include <queue>
-#include <string>
 #include <utility>
 #include <vector>
 #include "vec.h"
 
-#if PAPI
-#include <papi.h>
-#endif
-
-#if ASSERT
-#include <cassert>
-#else
-#define assert(x)
-#endif
-
 typedef float         real_t;                                   //!< Floating point type
 typedef vec<3,real_t> vec3;                                     //!< Vector of 3 floating point types
 typedef vec<4,real_t> vec4;                                     //!< Vector of 4 floating point types
 typedef vec<8,int>    ivec8;                                    //!< Vector of 8 integer types
 typedef std::pair<vec3,vec3> vec3Pair;                          //!< Pair of vec3
 
-//#ifndef KERNEL
-namespace {
-vec3 Xperiodic = .0;                                            //!< Coordinate offset of periodic image
-#if PAPI
-int PAPIEVENT  = PAPI_NULL;                                     //!< PAPI event handle
-#endif
-}
-
 #if COMkernel
 const int MTERM = P*(P+1)*(P+2)/6-3;                            //!< Number of Cartesian mutlipole terms
 #else
 typedef vec<MTERM,real_t>  vecM;                                //!< Multipole coefficient type for Cartesian
 typedef vec<LTERM,real_t>  vecL;                                //!< Local coefficient type for Cartesian
 
-//! Structure for pthread based trace
-struct Trace {
-  pthread_t thread;                                             //!< pthread id
-  double    begin;                                              //!< Begin timer of trace
-  double    end;                                                //!< End timer of trace
-  int       color;                                              //!< Color of trace
-};
-typedef std::map<pthread_t,double>             ThreadTrace;     //!< Map of pthread id to traced value
-typedef std::map<pthread_t,int>                ThreadMap;       //!< Map of pthread id to thread id
-typedef std::queue<Trace>                      Traces;          //!< Queue of traces
-typedef std::map<std::string,double>           Timer;           //!< Map of timer event name to timed value
-typedef std::map<std::string,double>::iterator TI_iter;         //!< Iterator of timer event name map
-
 //! Structure of bodies
 struct Body {
   int    IBODY;                                                 //!< Initial body numbering for sorting back