#include #include #include #define N 2048 double A[N][N], B[N][N], C[N][N]; double get_dtime(void){ struct timeval tv; gettimeofday(&tv, NULL); return ((double)(tv.tv_sec) + (double)(tv.tv_usec) * 0.001 * 0.001); } int main() { int i, j, k, count = 0; double sum, d1, d2; while(count < 12){ /* 行列の初期化と要素の追加 */ for(i = 0; i < N; i++) { for(j = 0; j < N; j++){ if(i != j){ A[i][j] = 0.0; B[i][j] = 0.0; } else{ A[i][j] = 10.0; B[i][j] = 0.1; } C[i][j]=0.0; } } d1 = get_dtime(); /* 掛け算の計算 */ for(i = 0; i < N; i++) { for(j = 0; j < N; j++) { for(k = 0; k < N; k++) { C[i][j] += A[i][k] * B[k][j]; } } } d2 = get_dtime(); printf("time= %f[秒]\n", d2-d1); for(i = 0, sum = 0.0; i < N; i++){ for(j = 0; j < N; j++){ sum += C[i][j]; } } printf("sum = %f\n", sum); count++; } return 0; }