In my scientific work, I mostly deal with embarrassingly parallel problems like parameters sweep which consists of many independent problems that doesn't have to communicate with each other. MATLAB's parfor is an easy way to handle these. But this got me interested in learning about different way to do parallel computing. Having a new quad-core laptop also helps (Thinkpad x201-tablet). Since I am also brushing up on the subject stochastic process, so I decide to play with some simple code for something akin to throwing a dice many times . There are many way to do parallel computing. I start with POSIX Thread since it seems ubiquitous to all platform and compilers.
$#*! I Jot On Napkins
Short notes kept by a devotee to the study of nature, computing, and mathematics.
Saturday, November 05, 2011
Sunday, October 09, 2011
Slinky
Check out this video:
Seems like a nice textbook problem to establish a simple model for the slinky. This is one I came up with: Suppose the slinky consists of \( N + 1 \) identical masses of mass \( m \) connected to their neighbor by a spring of spring constant \( k \). Suppose the position of mass \( j \) is \( x_j(t) \) and \( x_0(0) = 0 \). For convenience, let \( \Omega^2 = \frac{k}{m} \).
Tuesday, October 04, 2011
$#*! I unlearned #2: causality and antiparticle
In the $#*! I unlearned #1, we saw that the propagator for a real Klein-Gordon scalar field is finite for two space-like separated points, which seems to violate causality. But not really. In the question of causality, we should not ask whether particles can propagate over space like intervals, but whether a measurement performed in one point can affect a measurement at another space-like separated point.
\[ \begin{aligned} [\phi(x), \phi(y)] &= \int \frac{d^3p}{(2\pi)^3} \frac{1}{\sqrt{2 p^0}} \int \frac{d^3q}{(2\pi)^3} \frac{1}{\sqrt{2 q^0}} \left[a_{\mathbf{p}} e^{-i p \cdot x} + a_{\mathbf{p}}^{\dagger} e^{i p \cdot x} ,\; a_{\mathbf{q}} e^{-i q \cdot y} + a_{\mathbf{q}}^{\dagger} e^{i q \cdot y} \right] \\ &= \int \frac{d^3p}{(2\pi)^3} \frac{1}{2 p^0} \left( e^{-ip(x-y)} - e^{ip(x-y)} \right) = D(x-y) - D(y-x) \end{aligned} \]
When \( (x - y)^2 < 0 \), we can perform a Lorentz transformation from \( (x-y) \) to \( - (x-y) \)--going around the light cone--so that the two propagators are actually equal and therefore exactly cancel; causality if preserved. When \( (x - y)^2 > 0 \), there is no such Lorentz transformation. In this case, the amplitude is nonzero, and roughly \( ( e^{-imt} - c.c ) \) for the special case \( \mathbf{x} - \mathbf{y} = 0 \), which we also calculated. Therefore: no measurement in the Klein-Gordon theory can affect another measurement outside the light-cone.
Saturday, October 01, 2011
$#*! I unlearned #1: scalar field theory
The Hamiltonian:
\[ H = \frac12 \int d^3 x \left[ \pi^2 + (\nabla \phi)^2 + m^2\phi^2 \right] \]where \( \pi(\mathbf{x}) \) is the conjugate momentum density of field \( \phi(\mathbf{x}) \) is quadratic. In particular by going to momentum space with:
\begin{align} \phi(\mathbf{x}) &= \int \frac{d^3p}{(2\pi)^3} \sqrt{\frac{1}{2\omega_{\mathbf{p}}}} \left(a_{\mathbf{p}} + a_{-\mathbf{p}}^{\dagger} \right) e^{i \mathbf{p} \cdot \mathbf{x}} \\ \pi(\mathbf{x}) &= \int \frac{d^3p}{(2\pi)^3} (-i) \sqrt{\frac{\omega_{\mathbf{p}}}{2}} \left(a_{\mathbf{p}} - a_{-\mathbf{p}}^{\dagger} \right) e^{i \mathbf{p} \cdot \mathbf{x}} \end{align}\( H \) become just sum of uncouple oscillators:
\[ H = \int \frac{d^3p}{(2\pi)^3} \omega_{\mathbf{p}} \left( a_{\mathbf{p}}^{\dagger} a_{\mathbf{p}} + \frac12 [a_{\mathbf{p}}, a_{\mathbf{p}}^{\dagger} ] \right) \]with well-known spectrum and stuff. More important are these commutation relations:
\[ [ H, a_{\mathbf{p}} ] = - \omega_{\mathbf{p}} a_{\mathbf{p}} \,,\quad [ H, a_{\mathbf{p}}^{\dagger} ] = \omega_{\mathbf{p}} a_{\mathbf{p}}^{\dagger} \]
Monday, September 26, 2011
Bad Memory
我的舊台機最近跑emerge的時候只要遇到compile很久的包(e.g. www-client/chromium)就會出現随機的segmentation fault或internal compiler error。因為每次出錯地方都不同,很明顯是舊電腦的硬體問題。检查硬碟後發現正常。跑memtest發現有一根RAM壞了。内存地址0x1AE501B8到0x1AFD3FE3出現錯誤。嗯,Gentoo真的可能比較傷硬體。
發現了問題就好解决。把壞掉的RAM拔掉(四根RAM唯一一根generic brand的。這教訓我硬體還是買名牌的好)。但這樣我就少了1GB了。買新的?這電腦舊到不想再化錢了。(我很吝啬)。Google一下發現GRUB2原來有很強的功能:
badram addr,mask[,addr,mask...]只要那OS的kernel由GRUB2手上拿取memory map,GRUB可以告訴启動的OS不要用某段内存。(像Windows這用chainload的OS應該不行吧?)badram接受和memtest的address/mask一樣的參數對。address是第一個内存地址。mask的定義是1指固定數位、0指可改變數位。
Sunday, September 25, 2011
Time to upgrade libpng
1316989305: === (1 of 1) Compiling/Merging (sys-apps/portage-2.2.0_alpha59::/gentoo/portage/sys-apps/portage/portage-2.2.0_alpha59.ebuild) 1316989348: ::: completed emerge (1 of 1) sys-apps/portage-2.2.0_alpha59 to / 1316989374: === (1 of 3) Compiling/Merging (sys-libs/zlib-1.2.5.1-r2::/gentoo/portage/sys-libs/zlib/zlib-1.2.5.1-r2.ebuild) 1316989497: ::: completed emerge (1 of 3) sys-libs/zlib-1.2.5.1-r2 to / 1316989498: === (2 of 3) Compiling/Merging (media-libs/libpng-1.5.5::/gentoo/portage/media-libs/libpng/libpng-1.5.5.ebuild) 1316989563: ::: completed emerge (2 of 3) media-libs/libpng-1.5.5 to / 1316989564: === (3 of 3) Compiling/Merging (media-libs/libpng-1.2.46::/gentoo/portage/media-libs/libpng/libpng-1.2.46.ebuild) 1316989612: ::: completed emerge (3 of 3) media-libs/libpng-1.2.46 to /成功後重建鏈接media-libs/libpng包的長跑開始。
Tuesday, July 19, 2011
Relativistic rocket
Well, not exactly. I am not accounting for loss of mass for propulsion. Here I am just writing down the relativistic motion with constant proper acceleration. So Alice is riding a rocket that has some kind of propulsion such that she experiences a constant force. Her acceleration is: \(\alpha^{\prime\nu}=(0,\alpha)\), where \(\alpha\) that does not depends on proper time \( \tau \), which is a faithful parameter for the motion in all reference frame.
Let \( \beta \) be Alice's instantaneous velocity with respect to an observer Bob. The acceleration in Bob's frame is:
\[ \alpha^{\mu} = \Lambda_{\nu}^{\mu} \alpha^{\prime \nu} = \gamma \begin{pmatrix} 1 & \beta \\ \beta & 1 \end{pmatrix} \begin{pmatrix} 0 \\ \alpha \end{pmatrix} =\begin{pmatrix} \alpha \sinh w \\ \alpha \cosh w \end{pmatrix}\]where \( \beta = \tanh w \) and \( w \) is the rapidity.