优化心得
茶禅如水 2007-01-20 01:35:13 1、我的优化后的源码,比较短,所以只显示修改的部分
#include <mkl.h>
//double distx, disty, distz,dist;
main()
{
HANDLE hProcess = GetCurrentProcess();
SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS);
vmlSetMode(VML_NUM_THREADS_OMP_FIXED | VML_LA );
for()
...
}
int computePot() {
int i, j;
double temp[1000];
#pragma omp parallel num_threads(2) shared(r) private(i,j,temp)
{
#pragma omp for reduction(+:pot) schedule(static,1)
for( i=0; i<1000; i++ ) {
for( j=0; j<i-1; j++ ) {
temp[j] = pow( (r[0][j] - r[0][i]), 2 );
temp[j] += pow( (r[1][j] - r[1][i]), 2 );
temp[j] += pow( (r[2][j] - r[2][i]), 2 );
}
vdInvSqrt(j,temp,temp);
for (j= 0; j < i-1; j++)
pot += temp[j];
}
}
2、使用icc编译的参数
icl /Qopenmp /QaxP /Qipo pl.cpp mkl_c.lib
因为vc2005express版不支持openmp所以只用了linker
3、说明:程序主要使用了icc和mkl做优化,以及vtune对程序进行分析。
因为不太会汇编(要向huanyun好好学习汇编!),所以大部分主要靠工具啦。