すべて次のように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;
}
私は、Intel 13.0コンパイラでコンパイルして実行しようとしたとき、大きなループは無視され、実行がゼロタイミングが生じているように見える:
$ icc test.c
$ ./a.out
cputime_elapsed_in_sec: 0.000000e+00
realtime_elapsed_in_sec: 9.000000e-06
私は合計(コメント解除ライン26)を印刷する場合にのみ、ループがします実際にexeになるcuted:
なぜ私は合計値を出力しないとループが実行されていないようですか?
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