lab4 Cache Geometries 深入理解计算机系统——高速缓存

这个实验主要是将高速缓存命中的一点东西,意在告诉我们平常多注意这方面的东西。不懂java的,所以只管C的部分。You will do this several times, making small modifications to see what differences they make—how the choice of language affects
摘要由CSDN通过智能技术生成

这个实验主要是将高速缓存命中的一点东西,意在告诉我们平常多注意这方面的东西。


不懂java的,所以只管C的部分。


You will do this several times, making small modifications to see what differences they make—how the choice of language affects performance and how effective the compiler can be at optimizing your code when you:

  • interchange the order of the i and j loops
  • uncomment the commented line
  • change the size of the array being copied from 2048 x 2048 to 4096 x 4096



#include <stdio.h>

int src[2048][2048];
int dst[2048][2048];

/* Copies the contents of one 2048-by-2048 array (src) into another (dst). */
int main(int argc, char* argv[])
{
	// declare all variables before the code (conform to an older C standard...)
	int rep;
	int i, j;

	for ( rep = 0; rep < 10; rep++ )
	{
		for ( i= 0; i < 2048;i++ )
		{
			for ( j= 0; j< 2048; j++ )
			{
				//src[i][j] = i * rep;
				dst[i][j] = src[i][j];
			}
		}
	}

	return 0;
}


要做的就是测试三种不同情况下的程序运行时间:


不优化 O2优化
原始程序 0.163 0.167
调换i,j顺序 1.332 1.305
加上src数组赋值 1.814 1.815
改变数组大小为4096 8.424 8.487

上诉结果都是在保持上一个改变的基础上得出的结果,也就是加上src数组赋值这一步骤时,i和j的顺序还是调换的。




  1. What are the source code differences among the two Java implementations?

由于不懂java,所以只能编译一下C的程序,对java的就暂时不管了。


2.Pick a single pair of results that most surprised you. What is it about the results that surprised you? (That is, from the 32 pairs of measurement results, pick one pair whose relationship is least like what you would have guessed.)<

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值