ExaFMM 1
Fast-multipole Method for exascale systems
|
00001 /* 00002 Copyright (C) 2011 by Rio Yokota, Simon Layton, Lorena Barba 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 00011 The above copyright notice and this permission notice shall be included in 00012 all copies or substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 THE SOFTWARE. 00021 */ 00022 #ifndef types_h 00023 #define types_h 00024 #include <algorithm> 00025 #include <assert.h> 00026 #include <cmath> 00027 #include <complex> 00028 #include <cstdlib> 00029 #include <cstring> 00030 #include <fstream> 00031 #include <iomanip> 00032 #include <iostream> 00033 #include <list> 00034 #include <map> 00035 #include <omp.h> 00036 #include <queue> 00037 #include <stack> 00038 #include <string> 00039 #include <utility> 00040 #include <vector> 00041 #include "vec.h" //!< My vector type with operator overloading 00042 #if QUARK 00043 #include "quark.h" 00044 #endif 00045 00046 typedef unsigned bigint; //!< Big integer type 00047 typedef double real; //!< Real number type on CPU 00048 typedef float gpureal; //!< Real number type on GPU 00049 typedef std::complex<real> complex; //!< Complex number type 00050 typedef vec<3,real> vect; //!< 3-D vector type 00051 00052 00053 #ifndef KERNEL 00054 int MPIRANK = 0; //!< MPI comm rank 00055 int MPISIZE = 1; //!< MPI comm size 00056 int DEVICE = 0; //!< GPU device ID 00057 int IMAGES = 0; //!< Number of periodic image sublevels 00058 real THETA = .5; //!< Multipole acceptance criteria 00059 vect Xperiodic = 0; //!< Coordinate offset of periodic image 00060 #else 00061 extern int MPIRANK; //!< MPI comm rank 00062 extern int MPISIZE; //!< MPI comm size 00063 extern int DEVICE; //!< GPU device ID 00064 extern int IMAGES; //!< Number of periodic image sublevels 00065 extern real THETA; //!< Multipole acceptance criteria 00066 extern vect Xperiodic; //!< Coordinate offset of periodic image 00067 #endif 00068 00069 const int P = 6; //!< Order of expansions 00070 const int NCRIT = 30; //!< Number of bodies per cell 00071 const int MAXBODY = 200000; //!< Maximum number of bodies per GPU kernel 00072 const int MAXCELL = 10000000; //!< Maximum number of bodies/coefs in cell per GPU kernel 00073 const real CLET = 2; //!< LET opening critetia 00074 const real EPS = 1e-6; //!< Single precision epsilon 00075 const real EPS2 = 0; //!< Softening parameter (squared) 00076 const real R2MIN = 0.25; //!< Minimum value for L-J R^2 00077 const real R2MAX = 64; //!< Maximum value for L-J R^2 00078 const int GPUS = 3; //!< Number of GPUs per node 00079 const int THREADS = 64; //!< Number of threads per thread-block 00080 const int PTHREADS = 4; //!< Number of pthreads in quark 00081 00082 const int MTERM = P*(P+1)*(P+2)/6; //!< Number of Cartesian mutlipole terms 00083 const int LTERM = (P+1)*(P+2)*(P+3)/6; //!< Number of Cartesian local terms 00084 const int NTERM = P*(P+1)/2; //!< Number of Spherical multipole/local terms 00085 00086 #if Cartesian 00087 typedef vec<MTERM,real> Mset; //!< Multipole coefficient type for Cartesian 00088 typedef vec<LTERM,real> Lset; //!< Local coefficient type for Cartesian 00089 #elif Spherical 00090 typedef vec<NTERM,complex> Mset; //!< Multipole coefficient type for spherical 00091 typedef vec<NTERM,complex> Lset; //!< Local coefficient type for spherical 00092 #endif 00093 typedef std::vector<bigint> Bigints; //!< Vector of big integer types 00094 00095 //! Structure for pthread based trace 00096 struct Trace { 00097 pthread_t thread; 00098 double begin; 00099 double end; 00100 int color; 00101 }; 00102 typedef std::map<pthread_t,double> ThreadTrace; //!< Map of pthread id to traced value 00103 typedef std::map<pthread_t,int> ThreadMap; //!< Map of pthread id to thread id 00104 typedef std::queue<Trace> Traces; //!< Queue of traces 00105 typedef std::map<std::string,double> Timer; //!< Map of timer event name to timed value 00106 typedef std::map<std::string,double>::iterator TI_iter; //!< Iterator for timer event name map 00107 00108 enum Equation { //!< Equation type enumeration 00109 Laplace, //!< Laplace potential + force 00110 VanDerWaals //!< Van der Walls potential + force 00111 }; 00112 00113 //! Structure of source bodies (stuff to send) 00114 struct JBody { 00115 int IBODY; //!< Initial body numbering for sorting back 00116 int IPROC; //!< Initial process numbering for partitioning back 00117 unsigned ICELL; //!< Cell index 00118 vect X; //!< Position 00119 real SRC; //!< Scalar source values 00120 }; 00121 typedef std::vector<JBody> JBodies; //!< Vector of source bodies 00122 typedef std::vector<JBody>::iterator JB_iter; //!< Iterator for source body vector 00123 00124 //! Structure of bodies 00125 struct Body : JBody { 00126 vec<4,real> TRG; //!< Scalar+vector target values 00127 bool operator<(const Body &rhs) const { //!< Overload operator for comparing body index 00128 return this->IBODY < rhs.IBODY; //!< Comparison function for body index 00129 } 00130 }; 00131 typedef std::vector<Body> Bodies; //!< Vector of bodies 00132 typedef std::vector<Body>::iterator B_iter; //!< Iterator for body vector 00133 00134 //! Linked list of leafs (only used in fast/topdown.h) 00135 struct Leaf { 00136 int I; //!< Unique index for every leaf 00137 vect X; //!< Coordinate of leaf 00138 Leaf *NEXT; //!< Pointer to next leaf 00139 }; 00140 typedef std::vector<Leaf> Leafs; //!< Vector of leafs 00141 typedef std::vector<Leaf>::iterator L_iter; //!< Iterator for leaf vector 00142 00143 //! Structure of nodes (only used in fast/topdown.h) 00144 struct Node { 00145 bool NOCHILD; //!< Flag for twig nodes 00146 int LEVEL; //!< Level in the tree structure 00147 int NLEAF; //!< Number of descendant leafs 00148 int CHILD[8]; //!< Index of child node 00149 vect X; //!< Coordinate at center 00150 Leaf *LEAF; //!< Pointer to first leaf 00151 }; 00152 typedef std::vector<Node> Nodes; //!< Vector of nodes 00153 typedef std::vector<Node>::iterator N_iter; //!< Iterator for node vector 00154 00155 //! Structure of source cells (stuff to send) 00156 struct JCell { 00157 unsigned ICELL; //!< Cell index 00158 Mset M; //!< Multipole coefficients 00159 }; 00160 typedef std::vector<JCell> JCells; //!< Vector of source cells 00161 typedef std::vector<JCell>::iterator JC_iter; //!< Iterator for source cell vector 00162 00163 //! Structure of cells 00164 struct Cell { 00165 unsigned ICELL; //!< Cell index 00166 int NCHILD; //!< Number of child cells 00167 int NCLEAF; //!< Number of child leafs 00168 int NDLEAF; //!< Number of descendant leafs 00169 int PARENT; //!< Iterator offset of parent cell 00170 int CHILD; //!< Iterator offset of child cells 00171 B_iter LEAF; //!< Iterator of first leaf 00172 vect X; //!< Cell center 00173 real R; //!< Cell radius 00174 real RCRIT; //!< Critical cell radius 00175 Mset M; //!< Multipole coefficients 00176 Lset L; //!< Local coefficients 00177 }; 00178 typedef std::vector<Cell> Cells; //!< Vector of cells 00179 typedef std::vector<Cell>::iterator C_iter; //!< Iterator for cell vector 00180 typedef std::queue<C_iter> CellQueue; //!< Queue of cell iterators 00181 typedef std::stack<C_iter> CellStack; //!< Stack of cell iterators 00182 typedef std::pair<C_iter,C_iter> Pair; //!< Pair of interacting cells 00183 typedef std::queue<Pair> PairQueue; //!< Queue of interacting cell pairs 00184 typedef std::stack<Pair> PairStack; //!< Stack of interacting cell pairs 00185 typedef std::list<C_iter> List; //!< Interaction list 00186 typedef std::list<C_iter>::iterator LC_iter; //!< Iterator for interaction list 00187 typedef std::vector<List> Lists; //!< Vector of interaction lists 00188 typedef std::map<C_iter,int> Map; //!< Map of interaction lists 00189 typedef std::map<C_iter,int>::iterator MC_iter; //!< Iterator for interation list map 00190 typedef std::vector<Map> Maps; //!< Vector of map of interaction lists 00191 00192 //! Structure for Ewald summation 00193 struct Ewald { 00194 vect K; //!< 3-D wave number vector 00195 real REAL; //!< real part of wave 00196 real IMAG; //!< imaginary part of wave 00197 }; 00198 typedef std::vector<Ewald> Ewalds; //!< Vector of Ewald summation types 00199 typedef std::vector<Ewald>::iterator E_iter; //!< Iterator for Ewald summation types 00200 00201 #endif