谷歌浏览器插件
订阅小程序
在清言上使用

2 Shared Memory Implementation

semanticscholar(2009)

引用 0|浏览1
暂无评分
摘要
For n particles, the original code requiresO(n) time because at each time step, the apply force function is called for each particle (to be updated) with each other particle. Since interactions are local, one particle is influenced by a few nearby particles. Thus, most of the time, the apply force function is computing a distance and returning after finding this distance to be greater than the local force cutoff. Since the density is constant (the size of the domain grows with n), the total number of local interactions is O(n). To run the simulation in O(n) time, the apply force function should be called only Cn times, for some constant C. We created a data structure to index particles by their location within the domain. In this way, given a particle at location (x, y), we can use the index to find which other particles are close to (x, y) and only try to apply forces from the nearby particles (rather than all particles). We partitioned the domain into a 2-D array of square “bins” with size equal to the local interaction cutoff, so that a particle can only possibly interact with particles in one of the 8 neighboring bins (or in its own bin). We used an array of the STL vector data structures to store pointers to particles in each bin. Since the size s (one side) of the domain is proportional to √ n and the number of bins B is proportional to s, B is proportional to n (the constant turns out to be about 5, depending on the fringe). Only pointers to particles need be stored (rather than copies) because the apply force function reads the position of particles and writes the acceleration components. Thus, as long as no particles are moved before all particles’ accelerations are computed, no data copying is necessary. Thus, for each time step, our serial algorithm does four things: clear the bins, assign particles (i.e. pointers to particles) to bins, compute forces (only those in neighboring bins), and move the particles. Clearing the bins requires B calls to the constant-time vector function empty(), assigning the particles to bins requires n calls to the constant-time vector function push back(), computing forces requires αn calls to apply force (where α is the average number of particles in neighboring bins), and moving the particles requires n calls to the move function. Thus, as long as α is a constant (about 2.2 with the given density and cutoff constants), the algorithm runs in O(n) time. Figure 1 shows the original code runs in O(n) time and our serial (and parallel) code runs in O(n) time.
更多
查看译文
AI 理解论文
溯源树
样例
生成溯源树,研究论文发展脉络
Chat Paper
正在生成论文摘要