| 1 | /* |
| 2 | * vector_dist_performance_util.hpp |
| 3 | * |
| 4 | * Created on: Jun 17, 2016 |
| 5 | * Author: Yaroslav Zaluzhnyi |
| 6 | */ |
| 7 | |
| 8 | #ifndef SRC_VECTOR_VECTOR_DIST_PERFORMANCE_UTIL_HPP_ |
| 9 | #define SRC_VECTOR_VECTOR_DIST_PERFORMANCE_UTIL_HPP_ |
| 10 | |
| 11 | #include <boost/property_tree/ptree.hpp> |
| 12 | #include "Plot/GoogleChart.hpp" |
| 13 | #include "vector_dist_performance_common.hpp" |
| 14 | |
| 15 | // Number of tests |
| 16 | #define N_VERLET_TEST 3 |
| 17 | #define N_STAT_TEST 30 |
| 18 | |
| 19 | |
| 20 | /*! \brief Benchmark particles' forces time |
| 21 | * |
| 22 | * \param NN Cell list |
| 23 | * \param vd Distributed vector |
| 24 | * \param r_cut Cut-off radius |
| 25 | * |
| 26 | * \return real time |
| 27 | */ |
| 28 | template<unsigned int dim, size_t prp = 0, typename T, typename V> double benchmark_calc_forces(T & NN, V & vd, float r_cut) |
| 29 | { |
| 30 | //Timer |
| 31 | timer t; |
| 32 | t.start(); |
| 33 | |
| 34 | calc_forces<dim,prp>(NN,vd,r_cut); |
| 35 | |
| 36 | t.stop(); |
| 37 | |
| 38 | return t.getwct(); |
| 39 | } |
| 40 | |
| 41 | /*! \brief Benchmark reordering time |
| 42 | * |
| 43 | * \param vd Distributed vector |
| 44 | * \param m Order of an Hilbert curve |
| 45 | * |
| 46 | * \return real time |
| 47 | */ |
| 48 | template<typename V> double benchmark_reorder(V & vd, size_t m) |
| 49 | { |
| 50 | //Timer |
| 51 | timer t; |
| 52 | t.start(); |
| 53 | |
| 54 | //Reorder |
| 55 | vd.reorder(m); |
| 56 | |
| 57 | t.stop(); |
| 58 | |
| 59 | return t.getwct(); |
| 60 | } |
| 61 | |
| 62 | /*! \brief Benchmark celllist getting time |
| 63 | * |
| 64 | * \param NN Cell list |
| 65 | * \param vd Distributed vector |
| 66 | * \param r_cut Cut-off radius |
| 67 | * |
| 68 | * \return real time |
| 69 | */ |
| 70 | template<typename T, typename V> |
| 71 | double benchmark_get_celllist(T & NN, V & vd, float r_cut) |
| 72 | { |
| 73 | // Cell list timer |
| 74 | timer t; |
| 75 | t.start(); |
| 76 | |
| 77 | //get cell list |
| 78 | NN = vd.getCellList(r_cut); |
| 79 | |
| 80 | t.stop(); |
| 81 | |
| 82 | return t.getwct(); |
| 83 | } |
| 84 | |
| 85 | /*! \brief Benchmark verlet getting time |
| 86 | * |
| 87 | * \param vd Distributed vector |
| 88 | * \param r_cut Cut-off radius |
| 89 | * |
| 90 | * \return real time |
| 91 | */ |
| 92 | template<typename V> double benchmark_get_verlet(V & vd, float r_cut) |
| 93 | { |
| 94 | openfpm::vector<openfpm::vector<size_t>> verlet; |
| 95 | //Timer |
| 96 | timer t; |
| 97 | t.start(); |
| 98 | |
| 99 | //get verlet |
| 100 | auto vr = vd.getVerlet(r_cut); |
| 101 | |
| 102 | t.stop(); |
| 103 | |
| 104 | return t.getwct(); |
| 105 | } |
| 106 | |
| 107 | |
| 108 | |
| 109 | /*! \brief Benchmark particles' forces time |
| 110 | * |
| 111 | * \param NN Cell list hilbert |
| 112 | * \param vd Distributed vector |
| 113 | * \param r_cut Cut-off radius |
| 114 | * |
| 115 | * \return real time |
| 116 | */ |
| 117 | template<unsigned int dim, size_t prp = 0, typename T, typename V> double benchmark_calc_forces_hilb(T & NN, V & vd, float r_cut) |
| 118 | { |
| 119 | //Forces timer |
| 120 | timer t; |
| 121 | t.start(); |
| 122 | |
| 123 | calc_forces_hilb<dim,prp>(NN,vd,r_cut); |
| 124 | |
| 125 | t.stop(); |
| 126 | |
| 127 | return t.getwct(); |
| 128 | } |
| 129 | |
| 130 | /*! \brief Benchmark celllist hilbert getting time |
| 131 | * |
| 132 | * \param NN Cell list hilbert |
| 133 | * \param vd Distributed vector |
| 134 | * \param r_cut Cut-off radius |
| 135 | * |
| 136 | * \return real time |
| 137 | */ |
| 138 | template<typename T, typename V> double benchmark_get_celllist_hilb(T & NN, V & vd, float r_cut) |
| 139 | { |
| 140 | // Cell list timer |
| 141 | timer t; |
| 142 | t.start(); |
| 143 | |
| 144 | //get cell list |
| 145 | NN = vd.getCellList_hilb(r_cut); |
| 146 | |
| 147 | t.stop(); |
| 148 | |
| 149 | return t.getwct(); |
| 150 | } |
| 151 | |
| 152 | /*! \brief Move particles in random direction but the same distance |
| 153 | * |
| 154 | * \param vd Distributed vector |
| 155 | * \param dist Distance for which the particles are moved (note that the direction is random) |
| 156 | * |
| 157 | */ |
| 158 | template<unsigned int dim, typename v_dist> void move_particles(v_dist & vd, double dist) |
| 159 | { |
| 160 | double phi; |
| 161 | double theta; |
| 162 | const double pi = 3.14159; |
| 163 | |
| 164 | auto it = vd.getDomainIterator(); |
| 165 | |
| 166 | while (it.isNext()) |
| 167 | { |
| 168 | phi = rand()/double(RAND_MAX); |
| 169 | theta = rand()/double(RAND_MAX); |
| 170 | phi *= 2.0*pi; |
| 171 | theta *= pi; |
| 172 | |
| 173 | auto key = it.get(); |
| 174 | |
| 175 | if(dim == 1) |
| 176 | vd.getPos(key)[0] += dist*sin(theta)*cos(phi); |
| 177 | else if(dim == 2) |
| 178 | { |
| 179 | vd.getPos(key)[0] += dist*sin(theta)*cos(phi); |
| 180 | vd.getPos(key)[1] += dist*sin(theta)*sin(phi); |
| 181 | } |
| 182 | else if(dim == 3) |
| 183 | { |
| 184 | vd.getPos(key)[0] += dist*sin(theta)*cos(phi); |
| 185 | vd.getPos(key)[1] += dist*sin(theta)*sin(phi); |
| 186 | vd.getPos(key)[2] += dist*cos(phi); |
| 187 | } |
| 188 | |
| 189 | ++it; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | ///////////////////////////// CONSTRUCT GRAPH ////////////////////////////// |
| 194 | |
| 195 | /*! \brief Draw a standard performance graph |
| 196 | * |
| 197 | * \param file_mean |
| 198 | * |
| 199 | * |
| 200 | */ |
| 201 | extern void StandardPerformanceGraph(std::string file_mean, |
| 202 | std::string file_var, |
| 203 | std::string file_mean_save, |
| 204 | std::string file_var_save, |
| 205 | GoogleChart & cg, |
| 206 | openfpm::vector<size_t> & xp, |
| 207 | openfpm::vector<openfpm::vector<openfpm::vector<double>>> & yp_mean, |
| 208 | openfpm::vector<openfpm::vector<openfpm::vector<double>>> & yp_dev, |
| 209 | openfpm::vector<std::string> & names, |
| 210 | openfpm::vector<std::string> & gnames, |
| 211 | std::string x_string, |
| 212 | std::string y_string, |
| 213 | bool use_log); |
| 214 | |
| 215 | #endif /* SRC_VECTOR_VECTOR_DIST_PERFORMANCE_UTIL_HPP_ */ |
| 216 | |