Skip to content

Welcome!

My flagship website has moved to the new address. This site is only for documentation purpose.

 

Publish Sage Notebook Sheet

Sage is an amazingly powerful computer algebra system (CAS), an open-source alternative of Matlab, Mathematica, Maple etc.. Among its numerous awesome features is the publication ability through sage notebook.

假期回国科研必备利器

  • Ubuntu/Linux Mint软件源

以LM14(Nadia) 为例,默认的软件源(/etc/apt/sources.list)是

deb http://packages.linuxmint.com/ nadia main upstream import
deb http://archive.ubuntu.com/ubuntu/ quantal main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ quantal-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ quantal-security main restricted universe multiverse
deb http://archive.canonical.com/ubuntu/ quantal partner
deb http://packages.medibuntu.org/ quantal free non-free

# deb http://archive.getdeb.net/ubuntu quantal-getdeb apps
# deb http://archive.getdeb.net/ubuntu quantal-getdeb games

从默认软件源下载texlive和auctex可以用龟速来形容。可以看出,http://packages.linuxmint.com/ 是LM默认的软件源, http://archive.ubuntu.com/ubuntu/等是Ubuntu的默认软件源。替代以相对应的国内软件源可以极大提高软件下载速度:

可以选择的LM的国内软件源

http://mirrors.ustc.edu.cn/linuxmint/(中科大)

http://jx.tju.zyrj.org/linuxmint/(天大)

Ubuntu的软件源

http://mirrors.163.com/ubuntu(速度还不错)

http://tw.archive.ubuntu.com/ubuntu/

http://mirror.bjtu.edu.cn/ubuntu/

http://ftp.sjtu.edu.cn/ubuntu/

http://mirror9.net9.org/ubuntu/

http://ubuntu.csie.ntu.edu.tw/ubuntu/

http://ubuntu.xjtuns.cn/ubuntu/

  • Lehigh的VPN配置

Lehigh的VPN对访问学校资源很必要,无奈http://sslvpn.lehigh.edu/不稳定,浏览器安装cisco的AnyConnectVPN经常失败。Alternative方法是安装 openconnect 和 network-manager-openconnect

sudo apt-get install openconnect network-manager-openconnect

比AnyConnectVPN好用太多了。安装完即可在Network Setting中设置VPN,好处不必多说,访问Lehigh的Hdrive和系里的Server是肯定没问题了,上Gmail也不再掉线了。

  • Dropbox配置

安装客户端的话需要按这里下载一个东西替代/home文件夹下的.dropbox-dist文件夹,更简单的做法是找个Dropbox的替代品,云诺貌似模仿的最好支持的操作系统最多,32位系统需要先安装ia32-libs。

  • Google加速

需要下载一个list(google.go), 添加到host中:

cat google.go >> /etc/hosts

详见暗度陈仓:修改Hosts改善谷歌浏览速度

AUCTex and RefTex in Emacs

AUCTex has many awesome features in editing LaTex files within Emacs: preview, outline, folding display, among others. RefTex is a nice tool to manage cross references, in an elegant way. The price we pay for those conveniences is simply a configuration of the .emacs file. The following is my awkward example by revision from many other resources but it works well enough for me:

(setq Tex-PDF-mode t)
(load "auctex.el" nil t t)
(require 'tex-mik)
(load "preview-latex.el" nil t t)

(setq Tex-save-query nil)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
(setq Tex-electric-sub-and-superscript 1)
(setq reftex-plug-into-AUCTeX t)

(add-hook 'LaTeX-mode-hook 'visual-line-mode)
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(add-hook 'LaTeX-mode-hook
          (lambda ()
            (LaTeX-add-environments
              '("theorem" LaTeX-env-label)
              '("lemma" LaTeX-env-label)
              '("proof" LaTeX-env-label))))

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(preview-gs-options (quote ("-q" "-dNOPAUSE" "-DNOPLATFONTS" "-dPrinted" "-dTextAlphaBits=4" "-dGraphicsAlphaBits=4"))))

Outline:
This feature allows you to view the big picture of the article by only displaying the sections, subsections etc.. To enable outline, turn on outline mode:

M-x outline-minor-mode

Next, C-c @ C-t outlines all sections and subsections:

Move cursor to the section/subsection to be edited, C-c @ C-e displays the section/subsection:

Additionally, C-c C-p C-b preview all math formulas in the buffer:

Move closer to the citation, C-c ] guides to search for a desired reference:

A reference card should help a lot for quick start.

Manage Multiple Versions of C/C++ Compiler

Only GCC4.7 or later provides experimental support for C++11 features, however the default compiler on my Linux Mint 13(Maya) is gcc-4.6. I need both gcc-4.6 to compile legacy code and gcc-4.7 to prepare for C++11 codes. This can be elegantly managed by Debian’s update-alternatives command. A step-by-step illustration:

Verify current edition:

zheng@T410 ~ $ gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

Since gcc-4.7 is not on my machine so install gcc-4.7:

zheng@T410 ~ $ sudo apt-get install gccgo-4.7 gcc-4.7-base

Now create symbolic links:

zheng@T410 ~ $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 10
zheng@T410 ~ $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 20

Configure gcc version:

zheng@T410 ~ $ sudo update-alternatives --config gcc
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path              Priority   Status
------------------------------------------------------------
  0            /usr/bin/gcc-4.7   20        auto mode
* 1            /usr/bin/gcc-4.6   10        manual mode
  2            /usr/bin/gcc-4.7   20        manual mode

Press enter to keep the current choice[*], or type selection number:

So update-alternatives command makes switching among different versions trivial work.

Above commands almost suffice but more options were discussed at askubuntu.

Parallel Loop in Matlab

Matlab is often looked down upon for its slowness. The parfor syntax can somehow remedy Matlab’s deficiency when calling for loops. I made a comparison on polyp12 in CORAL lab by solving 160 Quadratic Optimization Problems(QPs) with thousands of variables.

Original vignettes of Matlab code(sequential):

for i = 1:160

  % Solve the i'th problem

  output = solveQP(i);

end

It takes 5 days to solve all problems. I can barely wait for 5 days for each run.

Revised vignettes of Matlab code(parallel):

% Necessary for calling parfor

matlabpool

parfor i = 1:160

  % Solve the i'th problem

  output = solveQP(i);

end

There are 12 processors running simultaneously on polyp12:

>> >> >> Warning: Found 3 pre-existing parallel job(s) created by matlabpool that are
running.
You can use   'matlabpool close force local'    or create a configuration for
the distcomp.localscheduler object and use   'matlabpool close force
<configurationName>'    to remove all jobs created by matlabpool.
> In distcomp.interactiveclient.pRemoveOldJobs at 55
  In distcomp.interactiveclient.start at 58
  In MatlabpoolHelper>MatlabpoolHelper.doOpen at 250
  In MatlabpoolHelper>MatlabpoolHelper.doMatlabpool at 102
  In matlabpool at 131
Starting matlabpool using the 'local' configuration ... connected to 12 labs.

and the test completes  in 12 hours. The speedup is more than 5×24/12=10!

A more detailed description and tips are available here. My experience is: use as much as parfor as possible for computational intensive yet separable jobs.