提高運算速度的有限元編程技巧

我們編寫的有限元計算程序,解決具體問題往往需要大量運算時間。如果說計算一分種和計算兩分鐘相差不大,那么計算半天時間和計算五天時間就差別很大了。
在許多論文里看到,以下這些技巧,綜合起來可以使原本五天完成的任務加快到一天內完成,并且實現起來也很容易,且一般不破壞程序的可讀性。因此對于編程者來說是有必要了解的。
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.
2 j+ U+ ]" l0 G, f( n: i6 w
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
登錄后免費查看全文
立即登錄
App下載
技術鄰APP
工程師必備
  • 項目客服
  • 培訓客服
  • 平臺客服

TOP