星期五, 十一月 06, 2009

[Tools]AwesomWM for Linuxer

A Window Manager for linux keyboard lovers. [link]
Just awesome!
If you are a keyboard lover. You should definitely try this out.

星期二, 十一月 03, 2009

[Tools]生成python的vim跳转文件(tags):ptags.py

也许很多人不会注意到python的发行包下Tool/scripts的文件夹。
里面的ptags.py可以用来生成vim需要的tags(eptags.py for emacs)

[1]. To build tags for all python files in a directory the usage is something like:
ptags.py *.py

Hint 2: If you want to build tags for all python scripts in a folder hierarchy (say for some project) you can use:

find -X . -name \*.py -print | xargs ptags.py
These of course assume that you moved ptags.py to somewhere in your shell's $PATH.

Reference:
http://betabug.ch/blogs/ch-athens/569
http://coverage.livinglogic.de/Tools/scripts/ptags.py.html

星期一, 十一月 02, 2009

[News]关注ROC世界车王争霸赛

昨天看了中国车王争霸赛,前两名是韩寒和董荷斌。
没看比赛的可以看看韩寒的博客新浪新闻

今天是对阵舒马赫和维特尔
昨天是7:30 CCTV5开播的。今天应该也是同一个时间吧~

看看。

[Software]Ubuntu上的英语辞典

Ubuntu, for geeks, stardict 命令行版:
(On ubuntu)
$ sudo apt-get install sdcv
$ man sdcv
http://stardict.sourceforge.net/Dictionaries_zh_CN.php下载辞典库到 ~/.stardict/dic
在.bashrc中增加一行:
    function dic() { sdcv $* | less; }
使用的时候:
$ dic <the word>
在线辞典
engkoo.cn
stardict.cn

在线辞典for geeks
在elinks的smart prefixes设置stardict的一项
$ elinks
o(Option manager) -> Protocols -> URI rewriting -> Smart Prefixes -> Add
star
http://www.stardict.cn/query.php?q=%s

windows下,推荐用lingoes和 它的词库

[Tools]Latex Tips -- Include URL and Source Code

Include a URI
To include a URI, it is recommended to use the misc type with the \url command (requires \usepackage{url} in the tex file).

@misc{Riv92b:sig,
key = {Riv92b},
author = {Ron Rivest},
title = {The MD5 Message-Digest Algorithm},
howpublished = {\url{ftp://ftp.isi.edu/in-notes/rfc1321.txt}},
year = {1992}
}

Include Source Code
\usepackage{listings}
\lstset{
        language=C++,
        %%keywordstyle=\bfseries\ttfamily\color[rgb]{0,0,1},
        identifierstyle=\ttfamily,
        %%commentstyle=\color[rgb]{0.133,0.545,0.133},
        %%stringstyle=\ttfamily\color[rgb]{0.627,0.126,0.941},
        showstringspaces=false,
        basicstyle=\small,
        numberstyle=\footnotesize,
        %numbers=left,
        stepnumber=1,
        numbersep=10pt,
        tabsize=2,
        breaklines=true,
        %%prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
        breakatwhitespace=false,
        aboveskip={1.5\baselineskip},
        columns=fixed,
        %%upquote=true,
        extendedchars=true,
        frame=single,
        %%backgroundcolor=\color{lbcolor},
}
\begin{figure}[h]
  \lstinputlisting{code/foo.cc}
  \caption{\emph{foo.cc} explained}
  \label{fig:foo.cc}
\end{figure}

References:
http://franz.kollmann.in/latex/latex.html
http://www.tjansson.dk/?p=419

星期日, 十一月 01, 2009

[Coding]A small example of embedding Python into C built with SCons

$ cat main.c
#include <Python.h>

int main(int argc, char *argv[])
{
    Py_Initialize();
    PyRun_SimpleString("from time import time,ctime\n"
               "print 'Today is',ctime(time())\n");
    Py_Finalize();
    return 0;
}

$ cat SConstruct
env = Environment(CPPPATH = ['/usr/include/python2.6/'])
env.Append(LINKFLAGS='-lpython2.6')

env.Program('main.c')

$ scons -Q
gcc -o main.o -c -I/usr/include/python2.6 main.c
gcc -o main -lpython2.6 main.o

$ ./main
Today is Mon Nov  2 14:29:41 2009

星期六, 十月 31, 2009

[Coding]Have fun with hybrid Python and C++ with SWIG & SCons

Try out the example below(example.c/i, SConstruct). Have fun!

$ scons
$ python
 >>> import example
>>> example.fact(5)
120
>>> example.my_mod(7,3)
1
>>> example.get_time()
'Sun Feb 11 23:01:07 1996'
>>>


example.c
/* File : example.c */

#include <time.h>
double My_variable = 3.0;

int fact(int n) {
    if (n <= 1) return 1;
    else return n*fact(n-1);
}

int my_mod(int x, int y) {
    return (x%y);
}

char *get_time()
{
    time_t ltime;
    time(&ltime);
    return ctime(&ltime);
}
example.i:
/* example.i */
%module example
%{
/* Put header files here or function declarations like below */
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
%}

extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();

SConstruct:
import distutils.sysconfig
env = Environment(SWIGFLAGS=['-python'],
CPPPATH=[distutils.sysconfig.get_python_inc()],
SHLIBPREFIX="")
env.SharedLibrary('_example.so', ['example.c', 'example.i'])



星期五, 十月 30, 2009

[Tools]用vim写latex的插件:Vim-latex (cont.)

visually select a word and excute a command on it:

`sf
\textsf{word}

,se
\section{section name}

,ce
\centerline{word}
`(  encloses selection in \left( and \right) `[  encloses selection in \left[ and \right] `{  encloses selection in \left\{ and \right\} `$  encloses selection in $$ or \[ \] depending on characterwise or                                       linewise selection

g:Tex_Leader

Type String
Default Value '`'

g:Tex_Leader2

Type String
Default Value ','

Reference:
http://vim-latex.sourceforge.net/documentation/latex-suite.html

Vimrc for Python Coding Style

Indenting Python with VIM
http://henry.precheur.org/2008/4/18/Indenting_Python_with_VIM.html

Python Coding Style
http://www.python.org/dev/peps/pep-0008/

indent/python.vim : An alternative indentation script for python
http://www.vim.org/scripts/script.php?script_id=974

[Tools]用vim写latex的插件:Vim-latex

最近需要用到vim来写latex,所以就下了vim-latex这 个包来用。
开始时用的还不是很顺手,因为它的文档写得很差。
而且因为是小众软件,在google上也搜不到什么资料。

用了一个下午,有一些Tips。简单记录一下。
最主要的一条:Read the f**cking source code!
比如,在其晦涩难懂的User Manual里面说到:
These maps insert LaTeX sections such as: ... Example: SSE in insert mode inserts  \section{<++>}<++>
其实,就是在你输入"SSE"的时候自动帮你替换成"\section{<++>}<++>"。 vim-latex之所以好用,是因为它提供一系列快捷键来使你编辑LaTeX更方便。但是我一开始肯定是记不住这些所谓的快捷键的,而我又查不到网上有 快捷键列表之类的文档。等到真正写latex的时候,仍然不会去使用,这个让人很烦躁。
解决方法就是:读源代码。这里特指读一下vim的plugin里面的代码。
~/.vim/ftplugin/latex-suite$ grep --color -n -r --include=* --include=*.* ./* -e SSE ./envmacros.vim:256:call s:Tex_SectionMacros('SSE', 'section') ./texrc:423:"       SSE for section ./wizardfuncs.vim:333:\."\n SSE   ".g:Tex_Leader2."se   section" 
找一下envmacros.vim,就可以看到所有的 Macros:
" Sections {{{ call s:Tex_SectionMacros('SPA', 'part') call s:Tex_SectionMacros('SCH', 'chapter') call s:Tex_SectionMacros('SSE', 'section') call s:Tex_SectionMacros('SSS', 'subsection') call s:Tex_SectionMacros('SS2', 'subsubsection') call s:Tex_SectionMacros('SPG', 'paragraph') call s:Tex_SectionMacros('SSP', 'subparagraph') " }}}
Have fun!

星期三, 十月 28, 2009

[Coding]代码风格

K&R

缩进为4格,{跟在控制语句后面
int foo(int k)
{
    if (k < 0 || k > 2) {
        printf("out of range\n");
        printf("this function requires a value of 1 or 2\n");
    } else {
        printf("Switching\n");
        switch (k) {
        case 1:
            printf("1\n");
            break;
        case 2:
            printf("2\n");
            break;
        }
    }
}
使用K&R
$ indent -kr *.c *.h
在.vimrc中添加
function! KRIndent()
        set shiftwidth=4
endfunction
au FileType c,cpp,h,hh call KRIndent()

GNU

函数类型定义另起一行。缩进为2格。{另起一行。
int
foo (int k)
{
if (k < 0 || k > 2)
{
printf ("out of range\n");
printf ("this function requires a value of 1 or 2\n");
}
else
{
printf ("Switching\n");
switch (k)
{
case 1:
printf ("1\n");
break;
case 2:
printf ("2\n");
break;
}
}
}
使用GNU
$ indent *.c *.h
在.vimrc中添加
function! GnuIndent()
        setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1
        setlocal shiftwidth=2
        setlocal tabstop=8
endfunction
au FileType c,cpp,h,hh call GnuIndent()
其他,还有Linux/BSD等等。有兴趣的话可以参考Reference

Reference
http://en.wikipedia.org/wiki/Prettyprint
http://en.wikipedia.org/wiki/Indent_style
http://www.gnu.org/software/indent/manual/indent.html

[讲座]The Future of Computing is Parallel

清华海外名师讲堂第58 Bill Dally教授清华大学演讲

 

演讲题目 The Future of Computing is Parallel

Prof.Bill Dally

Fellow of the American Academy of Arts & Sciences

Chairman of the Computer Science Department at Stanford University

Bell Professor of Engineering, Stanford University

Chief Scientist & Sr. VP of Research, NVIDIA



------------------------------------------------------------------
Moore's Law
more transistors
L^3 power scaling
no performance perdiction

Transistor-> Processor->Value
value chain broken for serial computers

Turning more transistor to values.
ILP not in programs

More power is spent moving data.
[Gordon Moore ISSCC 2003]

The energy is not limited by Floating Point Unit.
Chips are power limited.

Performance = Parallelism
Efficiency = Locality

Amdahl's Law doesn't apply to most future applications.
We need:
1. Many efficient processors
2. An exposed storage hierarchy(locality)
3. A programming system that abstract this

NASA application
domain expert: 27-169 times performance

Data Movement
scarce resource:
on-chip storage
off-chip bandwidth

Fermi - throughput computing

Avoid Denial Architect
Single thread processors
serial execution
- Denies parallelism
Flat Memory
- Denies locality
These illusions inhibit performance and efficiency

CUDA abstracts the GPU architecture

Throughput computing must evolve to meet the challenges of Exascale Computing

DARPA Study
Four challenges
Energy and Power
Memory and Storage
Concurrency and Locality
Resilliency
#1 is power

Energy
Heterogeneous architecture
(right core for right job)
Efficient processor
Agile memory system
(keep data and instruction access local)
Optimized
(minimize energy/op)
(minimize data movement)

Locality Chalelnge
automatically(as a cache) or explicitly(scratchpad)
move computation to data
-fast active messages

An NVIDIA ExaScale Machine in 2017
* GPU Node ~300W
- 2,400 throupht cores
- 40 TFLOPS(SP), 13TFLOPS(DP)
- Deep explicit on-chip storage hierarchy
* Node Memory
- 128 GB RAM
- 512 GB Phase-Change Memory for checkpoint and scratch
* Cabinet - 100KW
- Dragonfly network
* System - 10MW
- Dragonfly with optical links
* RAS
- ECC on all memory and links
- self-checking and application-level checking
- Fast local checkpoint

Conclusion
* Single thread performance is no longer scaling
* Performance = Parallelism
* Efficiency = Locality
* Application have lots of both
* Machines need lots of cores(parallelism) and exposed storage hierachy(locality)
* A programming system must abstract this
* Reaching an ExaScale requires evolving throughput computing.
- Agile memory
- Energy efficient cores and communication
- Efficient parallel mechanism

Q&A
Q: throughput
A: how many problems/time

Q(lhw):
What do you think about the future of dataflow programming model in the parallel computing era?
A:
does not explore locality well

星期五, 十月 23, 2009

A Taste of Haskell

<iframe src="http://docs.google.com/present/embed?id=d2xvwd8_337cqc93qhg&size=m" frameborder="0" width="555" height="451"></iframe>

星期一, 十月 19, 2009

[Readings]朱老师的故事

[link]

只引一句:
写到这里,不由得又感慨一次,中国从来不缺聪明人,缺的是让聪明人发挥才智的环境。我们的多少前辈学人,就算天纵奇才,生不逢时又能奈其何!今日的年轻人,若不能做出点名堂,那真是愧对前辈了。

[Readings]郎咸平:中国经济回暖与华尔街的阴谋

[link]
刚读完《中国大趋势》,又读到郎老师的阴谋论。

"如果当你和别人不一样的时候,你最 好认为你自己不正常,这样可能代表你还正常一点。但是我们从来不是这样思考问题的,我们感觉就是好得不得了,甚至这一波回暖,我们对待回暖的态度和过去是 迥然不同。"
真是犀利啊!

各位记得不记得,当时全世界有两派争论,一批是我一个人,另外一派是其他所有人

就在四月份,华尔街通过他们所操纵的中国媒体对外散步谣言,大豆要涨到七八千。所以,中国的油脂压榨工厂,在前一个月,买了八百多万吨美国大 豆,到了五月份,涨到四千四,再到下一个月,不知道是谁一声令下,华尔街开始集体抛售大豆期货,把大豆价格一下子打到两千块一吨,造成70%中国油脂压榨 企业被淘汰。我上个礼拜在山东时,有几个朋友跟我讲的嚎啕大哭,他们是山东日照油脂压榨厂的,以没有四千三百块的价格购了一船大豆,船还没有口岸就跌到两 千块,还没有生产就倒闭了,他们还没有上班银行就来查了。你知道下一步是什么吗?然后国际四大粮仓趁机进入中国,用贱价收购这些70%倒闭的油脂压榨工 厂。

  由于加入wto,09年开始,中国必须开放农产品市场。而08年年底,各位记得不记得,我们搞了一个农业改革,也是农民释放经营权,取得资本, 他可以去城市打工也,可以回到家乡替那些收购他的经营权的公司打工。国际四大粮商趁此良机收购了这些有经营权的中国农业公司进行参股,参股以后帮他做融 资,请他们去大面积收购中国的农地,所以收购中国农业公司的幕后人是是欧美四大粮商。

读《中国大趋势》,信心是要长,关键时刻还是得听郎老师的。郎老师才是自己人。

"中国很多制造业包括出 口,基本上是简单进口原材料,进口机器设备的粗加工,一月份进口原材料跌了一半,进口机器设备跌了四成,你知道这是什么可怕的意义吗?那就是在我们前面讲 的两个病没有解决的情况下,企业家不想干了,他在思考,辛苦了十几年,对不起家庭、子女和老婆,于是跑到广州买了几十万一只的名表或珠宝送给老婆,中国奢 侈品市场得以回暖;再看看自己的子女和年迈的父母,觉得特别的愧疚,这几年都是忙着做生意,干脆出去玩玩吧,然后买一个商务车,带着自己的孩子、老婆和自 己的岳父母去旅游,因此汽车销售又被带动起来。再想想自己辛苦这么多年,吃没有吃好,穿没有穿好,更重要的是住没有住好,因此江浙这一带企业家就到黄埔江 边买一个康城一品,或是到西湖边买一个别墅,中国的高端房产得以开始回暖。   这时候,摸一摸额头,你会发现已经有发烧的现象了"

手里掌握数据,同时用最幽默易懂的方式表达出来。郎老师的个人魅力真是无敌!