用CUDA进行N个物体的系统的演化仿真

参考文献

  1. NVIDIA:Fast N-Body Simulation with CUDA
  2. 知乎:快速平方根倒数算法
  3. 滑铁卢大学:Inverse Square Root
  4. Wikipedia:Fast inverse square root

英语术语

  • all-pairs:任意两点间

  • pair-wise:成对的

  • far-field:远场

  • tile:切面矩阵

  • bottom-up:自底向上

  • Multiply-add instructions:
    乘加指令;
    英文解释:Floating-point multiply-add instructions combine a multiply operation and an add operation without an intermediate rounding operation. The fractional part of the intermediate product is 106 bits wide, and all 106 bits are used in the add or subtract portion of the instruction.
    也就是说乘加指令会在一步中完成乘法和加法,这样的话原本要两步浮点运算完成的任务,现在可以一步完成,所以提速了。
    参考文献:IBM:Floating-point multiply-add instructions

  • inverse-square-root instruction:
    求平方根的倒数的指令。此种操作往往需要由好多的基本操作完成,比如快速平方根算法(Fast Inverse Square Root)中需要进行多个操作才能实现目标。有点数值分析的意思。
    参考文献:
    1.知乎:快速平方根倒数算法
    2.滑铁卢大学:Inverse Square Root
    3*.Wikipedia:Fast inverse square root

  • Loop Unrolling:循环展开

代码解释

__global__ void calculate_forces(void *devX, void *devA)
 {
 extern __shared__ float4[] shPosition;
 float4 *globalX = (float4 *)devX;
 float4 *globalA = (float4 *)devA;
 /*
 	globalX	所有物体的位置构成的数组
 	globalA	所有物体的加速度构成的数组
 */
 float4 myPosition;
 int i, tile;
 float3 acc = {0.0f, 0.0f, 0.0f};
 /*
 	blockDim.x	每个块的尺寸
 	blockIdx.x	现在是第几块
 	threadIdx.x	现在是第几个线程
 */
 int gtid = blockIdx.x * blockDim.x + threadIdx.x;
 myPosition = globalX[gtid];
 for (i = 0, tile = 0; i < N; i += p, tile++) {
 int idx = tile * blockDim.x + threadIdx.x;
 shPosition[threadIdx.x] = globalX[idx];
 __syncthreads();
 acc = tile_calculation(myPosition, acc);
 __syncthreads();
 }
 // Save the result in global memory for the integration step.
 float4 acc4 = {acc.x, acc.y, acc.z, 0.0f};
 globalA[gtid] = acc4;
 }

具有n个物体的系统

当一个系统由好多物体构成并且物体之间存在持续的相互作用时,这个系统就叫做多体系统。当用数字对这个多体系统的演化进行仿真就叫做多体仿真。常见于天体系统,蛋白质系统,涡流系统,全局照明系统。

具有n个物体的系统的演化分析

对于一个多体系统,往往是在给定初始条件的情况下,在每一步计算出系统中每个物体所受到的力进而确定该物体的加速度,从而确定多体系统中每个物体的运动轨迹,进而确定这个多体系统的演化。其中计算量比较大的就是每个物体所受到的力的计算。
所以大部分演化算法优化的目标都是:如何用最短的时间计算出所有物体各自的受力情况?

常见提升操作

loop unrolling:循环分解
分层。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值