모든 다음과 같이intel 컴파일러에서 큰 루프가 무시 되었습니까?
내가 부동 소수점 연산을위한 큰 루프에 대한 몇 가지 타이밍을 할 인텔 컴파일러를 사용하여 매우 간단한 C 테스트 코드를 코드 (test.c
)입니다 : 그러나
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <omp.h>
int main(char *argc, char **argv) {
const long N = 1000000000;
double t0, t1, t2, t3;
double sum=0.0;
clock_t start, end;
struct timeval r_start, r_end;
long i;
gettimeofday(&r_start, NULL);
start = clock();
for (i=0;i<N;i++)
sum += i*2.0+i/2.0; // doing some floating point operations
end = clock();
gettimeofday(&r_end, NULL);
double cputime_elapsed_in_seconds = (end - start)/(double)CLOCKS_PER_SEC;
double realtime_elapsed_in_seconds = ((r_end.tv_sec * 1000000 + r_end.tv_usec)
- (r_start.tv_sec * 1000000 + r_start.tv_usec))/1000000.0;
printf("cputime_elapsed_in_sec: %e\n", cputime_elapsed_in_seconds);
printf("realtime_elapsed_in_sec: %e\n", realtime_elapsed_in_seconds);
//printf("sum= %4.3e\n", sum);
return 0;
}
내가 컴파일하고 인텔과 13.0 컴파일러를 실행하려고 할 때, 큰 루프는 무시 될 것으로 보인다 및 실행은 제로 타이밍 결과 :
$ icc test.c
$ ./a.out
cputime_elapsed_in_sec: 0.000000e+00
realtime_elapsed_in_sec: 9.000000e-06
나는 (주석 라인 (26)), 루프 것 합계를 인쇄 할 경우에만 실제로 exe가 되라. cuted :
$ icc test.c
$ ./a.out
cputime_elapsed_in_sec: 2.730000e+00
realtime_elapsed_in_sec: 2.736198e+00
sum= 1.250e+18
질문 : 왜 합계 값을 인쇄하지 않으면 루프가 실행되지 않는 것입니까?
동일한 문제가 gcc-4.4.7 컴파일러에서 발생하지 않습니다. 인텔 컴파일러가 변수를 참조하지 않으면 루프가 무시되는 일부 최적화를 수행했을 수도 있습니다. 다음과 같이
시스템 정보는 다음과 같습니다 어떤 제안에 대한
$ uname -a
Linux node001 2.6.32-642.11.1.el6.x86_64 #1 SMP Wed Oct 26 10:25:23 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux
$ icc -v
icc version 13.0.0 (gcc version 4.4.7 compatibility)
$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
감사합니다!
로이
무엇이 당신의 질문입니까? – immibis
최적화 기능을 사용하지 않도록 설정하고 합계를 인쇄 할 때 결과를 제공하는지 확인하십시오. http://stackoverflow.com/questions/5765899/how-to-disable-compiler-optimizations-in-gcc –
한 가지 옵션은 ' 합계가 휘발성이다. – paddy