粒子之间的距离 (distance)
比 、norm2 和 hypot 更快
所以在密集计算中,应该避免使用 norm2 和 hypot 。
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=rk), | intent(in), | dimension(2) | :: | x |
两点坐标 |
|
| real(kind=rk), | intent(in), | dimension(2) | :: | y |
两点坐标 |
|
| real(kind=rk), | intent(out), | dimension(2) | :: | d |
坐标轴距离 |
|
| real(kind=rk), | intent(out) | :: | r |
欧式距离 |
pure subroutine get_distance(x, y, d, r)
real(rk), intent(in), dimension(2) :: x, y !! 两点坐标
real(rk), intent(out), dimension(2) :: d !! 坐标轴距离
real(rk), intent(out) :: r !! 欧式距离
d = x - y; r = sqrt(d(1)*d(1) + d(2)*d(2))
end subroutine get_distance