找回密码
 注册
Simdroid-非首页
查看: 497|回复: 3

[H. 有限元编程] 提高运算速度的有限元编程技巧

[复制链接]
发表于 2004-12-23 03:40:10 | 显示全部楼层 |阅读模式 来自 加拿大
我们编写的有限元计算程序,解决具体问题往往需要大量运算时间。如果说计算一分种和计算两分钟相差不大,那么计算半天时间和计算五天时间就差别很大了。
在许多论文里看到,以下这些技巧,综合起来可以使原本五天完成的任务加快到一天内完成,并且实现起来也很容易,且一般不破坏程序的可读性。因此对于编程者来说是有必要了解的。
Real time programming approaches:
1)  avoid floating point numbers as much as possible:

x*y takes almost ten time longer if a and y are floating point numbers than if they are integers. If a parameter has float value, we can use scale-up integer to represent it as much as possible.

2)  avoid function calls as much as possible

calling a function takes extra computing resources because stack pop and push of the function parameters and returns. Short functions can be implemented using predefined macros. If function is necessary, we can reduce the parameter list at the cost of less safety when using more global variables.

3)  define a union for 2D array

union in C defines alias of data type. We define a union of a 2D array and a 1D array with the same size.

union TackUnion
{   
int array_2D[Width][Height];
int array_1D[Width*Height];
}  TackName;

This is very useful in reducing computing time when clearing the 2D array.
for (int m=0;m<Width*Height;m++)
{  array_1D[m] = 0;}

Another way is to get the address of a 2D array, which is an integer multiplication and summation.

4)  Use time efficient operator:

Less efficient            Time efficient
m+1    m++
2*x                           x<<2
5*x    x<<2+x
a*x*x+b*x+c  (a*x+b)*x+c
x=x+y    x+=y

5)  define register integer variables as array index

We can use register integers as array index; however we can not declare all integers as register integers because of the very limited number of CPU registers.

6)  the unrolling technique (矩阵运算的循环展开技术, 参考:    http://www.simwe.com/forum/viewthread.php?tid=35643

评分

1

查看全部评分

发表于 2004-12-23 09:17:35 | 显示全部楼层 来自 上海长宁区

Re:提高运算速度的有限元编程技巧

Simdroid开发平台
对cpu运算的认识有一定境界!顶!
发表于 2004-12-23 14:31:54 | 显示全部楼层 来自 江苏南京

Re:提高运算速度的有限元编程技巧

几个小技巧:
1. 能用乘的时候不要用除。例如:a[100]/100.0,可采用0.01*a[100]。
2. 能用加的时候不用用乘。例如:a[100]*2.0,可采用a[100]+a[100]。
3. 像switch to和if,else if,...,else语句编程时,计算次数多的应排在判断的前面。
4. 如斑竹所说,多采用迭代,而不要展开计算,例:x*x*x+x*x+x+1,改为((x+1)*x+1)*x+1,进行计算。
5. C和C++语言中多采用指针。
个人愚见,请多指教。
发表于 2012-1-3 09:36:58 | 显示全部楼层 来自 北京
非常好,可惜刚看见!顶!
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-9-25 13:26 , Processed in 0.043405 second(s), 15 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表