CMU15213_Lecture_01_Course Overview

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014485485/article/details/82690894

课程是卡耐基梅隆大学计算机课程: introduction to computer systems

课程表:http://www.cs.cmu.edu/~./213/schedule.html

主讲:Abhinav Maurya https://ahmaurya.github.io/

教材:Computer Systems: A Programmer’s Perspective, Third Edition (CS:APP3e), Pearson, 2016

中文第二版:https://book.douban.com/subject/5333562/

课程是基于C语言的。

 

这老师上课很有激情,Maurya 首先表达了一个观点:平时我们都在学习抽象(abstract)的东西,但是别忘了抽象背后的现实(reality),或者说别忘了如何实现抽象。

 

reality 1:Ints are not Intergers,Floats are not Reals.

例如整数,可以无限增长,但计算机做不到(infinite),计算机的存储是有限的(finite)。当存储的数已经很大时,如果再加1,可能就会出错(error state)。

例如浮点数,怎么表示,表示出来是精确的吗

计算机的运算里:

不要产生随机数;不要假设计算机里的运算具有所有我们熟知的数学属性;

 

伪随机数生成方法是要评估的,有时候as better as随机数,有时候worse than 随机数,有时候甚至better than随机数。

假如你的程序使用随机数,你用真正的随机数时,可能程序崩了你不知道怎么回事,但是如果你使用伪随机数(pseudo random number),相同seed产生的系列随机数是一样的,这样我们得到的也是相同系列的events,程序变的可控,适合debuging。

 

reality 2:You've got to know assembly

虽然说写程序时我们不需要做assembly的工作,交给编译器去做了,但是如果了解编译器的工作原理, 可以有效地帮我们在machine-level设计、调试程序,提高程序的效率。

注:

1.Assembly, an assembly in the Common Language Infrastructure (CLI) is a compiled code library used for deployment, versioning, and security. There are two types: process assemblies (EXE) and library assemblies (DLL).

2.Assembler (computing), a computer program which translates assembly language to an object file or machine language format

3.assembly language(汇编语言), the closest translation to machine code so humans may work on more comfortably

 

刚开始汇编的效率并不高,一是因为写编译器的技术还不够高级,二是因为计算机的速度还很慢,花大量时间去优化编译结果划不来。现在这两项已经越来越成熟了。现在只有少量的Assembly 需要人手动去完成(在操作系统或者嵌入式里),其他的几乎都开始用high-level的语言开发了。

 

但是,很多时候我们希望得到高效率的代码,实现细节对我们来说十分重要,这时候就需要我们打破抽象去阅读assembly,去了解机器怎么执行我们的代码。

 

我们这里的目的并不是要学习怎么用汇编写程序,而是要学会阅读汇编,明白汇编和c语言是怎么映射的,这样我们就知道我们的c程序会让机器做什么。例如怎样使用memory和disk(我们知道memory快,disk慢),而memory又分register、L1 cache、L2 cache,how to do it?另外,程序的效率是time和space的综合。

 

reality 3:memory matters

----Random Access Memory Is an Unphysical Abstraction

Memory是有边界的;Memory是会导致bug的而且往往是致命的;不同的Memory的performance是不同的。这里我们的目的当然不是制作memory而是优化它的使用。

C and C++ do not provide any memory protection。所以,我们要明白并预估什么样的内存访问会发生。

 

reality 4:There’s more to performance than asymptotic complexity

asymptotic complexity:时间复杂度

我们在分析程序时往往只关注O(…),却忽略了常数,实际上,在现实生活中这些常数也不能忽略,例如1 minisecond得到反馈和1second得到反馈用户体验肯定不同;即使我们一条一条操作数过去,也不一定能预测程序的性能,还要去考虑算法,数据表示,处理过程,循环等;必须了解系统才能最优化性能。

例如一个二维数字遍历,两个for,先访问行还是先访问列呢?(答案是先类列后行)

 

reality 5:Computers do more than execute programs

需要读出/写出数据(大数据集);需要通过网络进行通信(系统级);

 

作业(assignment/lab)一览:

L1 (datalab): Manipulating bits

L2 (bomblab): Defusing a binary bomb

L3 (attacklab): The basics of code injection attacks

L4 (cachelab): Building a cache simulator and optimizing for locality.

L5 (tshlab): Writing your own Unix shell.

L6 (malloclab): Writing your own malloc package

L7 (proxylab): Writing your own Web proxy

 

下载地址:http://csapp.cs.cmu.edu/3e/labs.html

最有价值的就是作业。

猜你喜欢

转载自blog.csdn.net/u014485485/article/details/82690894
今日推荐