NO IMAGE

其中有一段資料是存在依賴的,是不能向量化的,註釋掉看一下效果吧。

/*
*Name : vectorized.c
*Purpose: test the performance of intel compiler
*Author: Albert
*/
#include <stdio.h>
#include <sys/time.h>
#include <string.h>
const int MAX = 2000000;
const int ITERMAX = 20000;
int main(void) {
int i, iter,arr[MAX];
timeval start,end;
long long tPassed = 0;
memset(arr, 0, sizeof(arr));
gettimeofday(&start,0);
for (iter = 1; iter < ITERMAX; iter  ) {
//		for(i = 1; i < MAX; i  ){
//			arr[i] = arr[i-1]   1;
//		}
for(i = 1; i < MAX; i  ){
arr[i]  = 1;
}
}
gettimeofday(&end,0);
end.tv_sec -= start.tv_sec;
end.tv_usec -= start.tv_usec;
tPassed = 1000000LL * end.tv_sec   end.tv_usec; 
tPassed /= 1000;
printf("%lld ms\n",tPassed);
return 0;
}

環境:

Linux v3901 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:19 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux,32GB記憶體,Intel(R) Xeon(R) CPU           E5450  @ 3.00GHz,8核,L1-Cahce 6144 KB.

[[email protected] simple]$ icpc vectorized.c -o ivectorized 
vectorized.c(19): (col. 2) remark: PERMUTED LOOP WAS VECTORIZED.
[[email protected] simple]$ g   vectorized.c -o vectorized
[[email protected] simple]$ ./ivectorized 
3696 ms
[[email protected] simple]$ ./vectorized 
114530 ms

時間上快了30倍還要多!個人覺得這個結果超過了預期的16倍,不太靠譜,原因在於測試程式不合適,表示式過於簡單,等有功夫了再改吧