Archive for September, 2006

Matlab 的内存管理

Sunday, September 24th, 2006

  

用 Matlab 进行大规模科学计算或仿真时,内存是一个需要时常注意的问题。当你写的 Matlab 程序跳出“Out of Memory” 时,以下几点措施是需要优先考虑的解决方法: 

1. 确保内存的连续性 

Matlab 中数组必须占用连续分配的内存段,当无法为新建的数组分配连续的内存段的时候,”Out of Memory” 就会出现。由于反复分配和释放数组会使可用的连续内存段减少,因此当 Matlab 刚刚启动时其连续内存最多,此时往往可以新建非常大的数组,这一点可以用命令 feature(’memstats’)(在 7.0 版本以上)看出。如果现实的最大连续内存段很小,但实际可用内存(非连续的)仍旧很多,则表明内存中碎片太多了。此时可以考虑用 pack 命令,pack 命令的作用就是将所有内存中的数组写入硬盘,然后重新建立这些数组,以减少内存碎片。此外,在命令行或者程序中都可以使用 clear 命令,随时减少不必要的内存。 

2. 3GB 开关 

由于32位 Windows 操作系统的限制,每个进程只能使用最多 2GB 的虚拟内存地址空间,因此 Matlab 的可分配内存也受到相应的限制。Matlab 7.0.1 引进了新的内存管理机制,可以利用 Windows 的 3GB 开关,使用 3GB 开关启动的 Windows 每个进程可以在多分配 1 GB 的虚拟地址空间,具体的操作方法可见:http://www.mathworks.com/support/tech-notes/1100/1106.html 

3. 减少使用双浮点数 

Matlab 默认的数字类型是双精度浮点数 (double),每个双浮点数占用 8 个字节。对于一些整数操作来说,使用双浮点数显得很浪费。在 Matlab 中可以在预先分配数组时指定使用的数字类型如以下命令:zero(10, 10, ‘uint8′) 。对于浮点数,在很多精度要求不高的情况下,可以使用4个字节的单浮点数 (single),可以减少一半的内存。关于单、双浮点数的精度对照如下,以便根据需要选择使用: 

single: 精度 (1.1921e-007) 最大数 (3.4028e+038)
double: 精度 (2.2204e-016) 最大数 (1.7977e+308)

Phys.Rev.B, 74, 125404

Sunday, September 17th, 2006

I am reading this paper, and will write review here a week later.

Title :

Spin-dependent electronic structure of transition-metal atom chain adsorbed on single-wall carbon nanotubes

molecular junction

Sunday, September 3rd, 2006

Metal/molecule/metal transport junctions can transport charge in the elastic scattering (Landauer) regime if the injection gap is large and the molecule is relatively short. Stochastic switching and broading conduction peak distributions have been observed in such junction. Ratner et al examed the effect of altering interface geometry on transport, using density functional calculations. for most structures, variations in conductance of order 0-300% are found, but when an atomic wire of Au binds to the molecule, symmetry changes can modify currents by a factor of $10^3$.