2015-10-04
WordPress Replication
FTP Replication
H0
L3 ~ L6: 因為 web root 權限需要,所以使用 sudo 提高權限。
L8: H0 & H1 透過 ssh 加密傳輸,得事先加信任公鑰。 L14 ~ L15: inotifywait 排除掉不想監控的檔案 ([Tt]hunms.db),接著只監控特定事件 (delete, moved_to, close_write, create)。為了記錄過程我把時間戳一並寫出,log 的樣子會長這樣:
15/10/04 21:37:05 CREATE /var/www/example.com/index.html
L21: 移除前綴字,避免同步路徑錯誤。
L24: 移除檔案名稱,讓 rsync 同步資料夾,而非單一檔案。
L26: rsync + ssh 同步資料夾到 H1。
H1
L3 ~ L6: 因為要寫入到 web root,要求得是 root 。
L13 ~ L26: 做的事情和 H0 一樣,只是來源和目的互換。
已知問題
刪除
inotifywait 遇到刪除檔案或目錄,只會出現 OPEN,ISDIR,接著就沒了,所以也無法偵測到 DELETE 事件。rsync 直到下個時間才會把上個未刪除的工作做完。2015-10-02
GoDaddy 註冊系統有安全疑慮
緣由
我在 GoDaddy 註冊了一個帳號,我的 Email local-part 有 30 個字,因為某個原因我需要重新登錄網站,結果就無法登錄。查了 Whois 發現 GoDaddy 把我的 Email 縮短了,而且是沒有規則。客服
0. 官網沒有文字客服
1. 英譯證件
0. 試著聯繫 Whois 上面錯誤的 Email。
1. 透過 ICANN 投訴。
2. 法院傳票要回。
2. 將錯就錯
安全疑慮
I was not able to duplicate this in another account. You may want to try using an alternate email address.
這種回答讓我對 GoDaddy 灰心,工程文化沒落實完全,如此簡單的註冊瑕疵能用這麼簡單的方式拿回權限,如果今天我就是壞人呢?
2015-09-01
2014-10-08
iOS 安裝 in-house app 需要的網站
- 17-courier.push.apple.com
- 1-courier.push.apple.com
- 26-courier.push.apple.com
- 2-courier.push.apple.com
- 31-courier.push.apple.com
- 36-courier.push.apple.com
- 40-courier.push.apple.com
- 9-courier.push.apple.com
- a1441.g4.akamai.net
- a97.gi3.akamai.net
- apple.com
- apple-finance.query.yahoo.com
- cl4.apple.com
- e2842.e9.akamaiedge.net
- init-p01st.push.apple.com
- local
- mesu.apple.com
- p24-keyvalueservice.icloud.com
- p24-keyvalueservice.icloud.com.akadns.net
- setup.icloud.com
- www.apple.com
- www.isg-apple.com.akadns.net
- xp.apple.com
2014-08-08
2014-05-14
CoreImage & GPUImage performance
Specs
iPhone 5siOS 7.1.1
GPUImage 0.1.4
Still images
CPU 181.51msCore Image 37.08ms
GPUImage 49.62ms
Live video
CPU 15.77msCore Image 3.20ms
GPUImage 2.36ms
2014-04-03
xcodebuild
Let says, I need release with a enterprise provision file, so here is the script,
2014-02-07
iOS 免加 UUID 發佈方式
2013-12-18
IRC 紀錄即時推送
Irssi
/log open -autoopen -targets #tcffm ~/irclogs/Freenode/#tcffm-%Y-%m-%d
Git init
cd ~/irclogs/Freenodegit init
touch README
git add README
git commit -am "First commit."
git remote add origin git@github.com:OOO/tcffm.git
git push -u origin master
腳本
1. daily.sh此腳本使用 crontab 每天 0:00 啟動,內容如下:
#!/bin/bash2. onchange.sh
killall -9 inotifywait
cd '/home/OOO/irclogs/Freenode'
today=$(date +%Y-%m-%d)
git add \#tcffm-$today
inotifywait -qme modify --format "sh onchange.sh %w" \#tcffm-$today | sh
#!/bin/bash將兩個腳本權限設定為 755
git commit -am "log"
git push
啟動
執行 ~/irclogs/Freenode/daily.sh後記
2013-11-28
Concurrency
以 Computer Memory Hierarchy 解釋,CPU 以外的 I/O 都是很慢的,讓 CPU 等待是罪過,此決定掌握在 programmer 手上。
使用 aio 方式我用過幾種:
1) Object-C delegate
初體驗,也是啟發的框架。
2) go goroutine + channel
新語言的設計。
3) JavaScript ajax + callback
常見的方式。
自從開始有這些體驗,盡量落實每個動作都是 async,朝 C10M 邁進。
2013-10-22
德國電信商保護境內資料
這個草案表現出一個態度,德國人不喜歡被監聽,可能不選擇美國服務,且自身加強保護。如此一來,德國民眾可能會有更多自己國家的服務,形成特殊現象。
2013-08-08
使用 rsync & git 建立每日備份
災難是:
前人建立某個帳戶,家目錄在 /,用 userdel -r 清理舊帳戶,時間過久才發現災難已經造成。兩個月前閒來無事,有做系統總備份,httpd 和 mysql 是兩個月前的紀錄,客戶難免唉唉叫。救災完畢後,使用 git 建立每日備份。
主機特性是代管客戶網頁資料,包含圖片和資料庫。
概略步驟是:
1. rsync 初始,git init
2. 每日 rsync 同步,git commit
3. 每日產生 git bundle
Webpages
接著每天做備份
最後每天產生 git bundle
MySQL
和 webpages 相似的步驟,先初始接著每天備份,產生 git bundle
最後產生 git bundles
還原
後記
災難後尋找備份方案時,見到有人每日、每週、每月做不同程度的備份。記得將每日的動作放進 crontab 定時執行,放在離峰時間比較不影響服務品質。資料搞失或資料復原都需要付出慘痛的代價,如果能做成自動化,可以降低很多反應時間和損失。
2013-05-29
Notification 掉包
只送最後一則。
GCM will usually deliver messages immediately after they are sent. However, this might not always be possible. For example, the device could be turned off, offline, or otherwise unavailable. In other cases, the sender itself might request that messages not be delivered until the device becomes active by using the delay_while_idleflag. Finally, GCM might intentionally delay messages to prevent an application from consuming excessive resources and negatively impacting battery life.
GCM Advanced Topics, Setting an Expiration Date for a Message
If APNs attempts to deliver a notification but the device is offline, the notification is stored for a limited period of time, and delivered to the device when it becomes available.
Only one recent notification for a particular application is stored. If multiple notifications are sent while the device is offline, each new notification causes the prior notification to be discarded. This behavior of keeping only the newest notification is referred to as coalescing notifications.
If the device remains offline for a long time, any notifications that were being stored for it are discarded.
Local and Push Notification Programming Guide, Quality of Service
比較 Naver LINE Android 和 iOS 版本對於離線訊息的處理,一旦接上網路,離線訊息一併收到數則。猜測可能的作法是:
1. Device offline
2. Send #1 msg, server enqueue 1 msg
3. Send #2 msg, server enqueue 2 msgs
4. Device online
5. Server send queue
6. Device splits msgs and local notificate one-by-one.
2013-03-28
DDoS attacking
比較有趣的是下面幾篇文章:
- Deep Inside a DNS Amplification DDoS Attack
- How to Launch a 65Gbps DDoS, and How to Stop One
- Build your own botnet with open source software
2013-01-09
MD5 使用注意事項
若要在迴圈裡做上面的事情,可能會有這樣的寫法:
跑出來的結果是:
f1() 和 f2() 會有不同的結果是因為 io.WriteString 在 md5.go 實作細節, WriteString 會找 Writer 的實作,而在 md5.go 的實作如下:
看見 += 就可以猜的出來是附加的方式,所以每次非得使用新的 instance,目前還沒發現能清除 digest 內容的方法。
2012-11-08
Go
這篇記錄最近一個多月學習 Go 的心得。Go 的語法相對於 Object-C 簡潔,後置的資料型態變數宣告,可以懶惰省去資料型態宣告。
有兩件事情是我碰壁許久:
json.Marshal
執行結果會得到:
p1 is: {"FirstName":"John","LastName":"Doe"}.
p2 is: {}.
要輸出的成員變數必須大寫開頭才行,下面的 package 方法同樣套用。
Exported Functions
隨意撰碼都需要模組分割,追問題容易,讀碼速度快。Go 使用資料夾結構定義 package 封裝,捨棄 Makefile。How to Write Go Code 闡述如何做到模組化,所有細節皆有提到就是 Function name 首字要大寫沒提到[1],所以一直看到
./main.go:10: cannot refer to unexported name foo.foo1
程式碼如下:
foo.go
main.go
這是最近的心得。
Updated:
1. 在 The Go Programming Language Specification 的 Exported identifiers 有提到這些細節。
2012-05-09
Toggle network for iOS Simulator
The firewall rule can help me do that smart, just block the site and port you would. You can use the below script:
You can change the host you want block in line 3 banHost.
2012-04-24
Git hooks Xcode version
Since Xcode 4.0 starting to support git version control, so that we could bind git tag and commit hash text with Xcode field. The steps in the pseudo-code are below:
- $ git commit -am "COMMIT LOG"
- trigger post-commit hooking
- Setting the tag number and new commit hash to plist.
In the real code is like below:
Put the code in a file to PROJECT_FOLDER/.git/hooks/post-commit, and make it executable.
2012-04-19
TEPopUp uses resizableImageWithCapInsets
TEPopUp show a pop-up view that stands on a translucent view, it can add something in the dialog view easily.
TEPopUp dialog use the api, UIImage resizableImageWithCapInsets:, it needs not a full size picture as its background picture, instead of a 28x28 pixel small picture. Obviously, this technical can reduce the who app size. The main core code cuts the area of pattern image, from the center point to right-bottom corner by UIEdgeInsetsMake. Then, the UIImage returns a new instance thats already expand image to appropriate size.
2012-01-10
UIScrollView 卡關排解
若要做成兩頁,則 contentSize 要涵蓋兩頁寬度。
2011-11-18
Owned scan screen in ZBar
UIView, then, show the scanned image and text, that's all.
All I need is to use ZBarReaderView and ZBarImageScanner, the mainly code snippet as below:
The screen result like below:
Check out the full sample from github.
2011-11-16
2010-04-14
2009-11-16
Installing XP: ***STOP: 0x0000007B (0xF78D2524,0xC0000034,0x00000000,0x00000000)
When installing Windows XP, during the booting procedure, it shows up the BSOD screen, "Installing XP: ***STOP: 0x0000007B (0xF78D2524,0xC0000034,0x00000000,0x00000000)". After run the complete memtest86+, it occurs again.
The solution is here, disable HD drive from ACHI to Compatibility.
2009-08-04
Converting integer to string in ANSI C
const char *base = "BLAH BLAH BLAH";
unsigned int idx = 0;
char *buf = NULL;
buf = (char *) malloc (strlen (base) + sizeof (unsigned int));
sprintf (buf, "%s%d", buf, idx);
printf ("buf: %s\n", buf);
Output
BLAH BLAH BLAH0
2009-05-29
Compaq CQ60-201AU downgrade
This downgrade makes me understand that, some vendors combine some components of their product whole only supports vista drivers, it's really sucks. Fortunately, many geeks turn it works fine. So we can search their great solution and study its experiences.
2009-05-22
Why was your message broken?
My Nokia 1650 cellphone supports SMS, EMS and Instant Messaging, spec page said that supports length up to 250 characters, not as long as wikipedia SMS page said, 160 characters.
I have not yet find anything solves it problem to normal message.
2009-05-21
Abortion
glibc 25.6.4 Aborting a Program
Future Change Warning: Proposed Federal censorship regulations may prohibit us from giving you information about the possibility of calling this function. We would be required to say that this is not an acceptable way of terminating a program. |
Explanation: Re: Federal censorship regulations
The warning may be tongue in cheek. Anyone living in the US is
aware of the extreme sensitivity of the abortion issue (as it
applies to human foetuses, not computer programs).
Allin Cottrell.
2009-02-27
Compilin SQLite from source code
Steps
1. Setting current path as $TOP variable.
export TOP=`pwd`2. Getting source code tarball from official web site, and save it to $TOP.
wget http://www.sqlite.org/sqlite-3.6.11.tar.gz -O $TOP/sqlite-3.6.11.tar.gz3. Extracting
cd $TOP; gzip -dc sqlite-3.6.11.tar.gz | tar -xf - ; cd sqlite-3.6.114. Detecting something in system environment.
./configure5. Executing make if previous step successful. Doing debug with err.txt if errors occurs during makeing.
make 1> /dev/null 2> err.txt6. Installing files to system (/usr/local/), need root permission.
# make install
2009-02-13
tmux - terminal multiplexer
1. Downloading all packages, assume you're in bash shell.
wget -c http://mentors.debian.net/debian/pool/main/t/tmux/tmux_0.5{-1.d{iff.gz,sc},.orig.tar.gz}2. Unpacking and patch, then compie it.
$ gzip -d tmux_0.5-1.diff.gz
$ tar -zxf tmux_0.5.orig.tar.gz; cd tmux-0.5
$ patch -Np1 < ../tmux_0.5-1.diff
# make 1> /dev/null 2> err.txt && make install
3. Tuning it
.tmux.conf
set prefix ^\
set status on
set status-bg yellow
set status-fg block
set status-right " "
# For 0.7
unbind ^b
set -g prefix ^\
send-prefix
set -g status on
set -g status-bg yellow
set -g status-fg black
set -g utf8 off
.bashrc
alias t='tmux attach -d'
Drawbacks
under testing...
Really runs faster than GNU Screen!!
References
OSNews, Stayin' Alive with GNU Screen, http://osnews.com/comments/20962
mentors.debian.net, http://mentors.debian.net/debian/pool/main/t/tmux/
2009-02-12
SSH Tunnel memo
ssh -CND ${OUTDOOR_PORT} ${USER}@${REMOTE_SERVER}Specifies a port ${OUTDOOR_PORT} forwarding (-D) to ${REMOTE_SERVER} with ${USER}, that without executing the remote commands (-N), and requests all data compressed (-C).
Firefox
Changing its SOCKS Host to localhost and Port to ${OUTDOOR_PORT}.
Opera
Installing the tsocks, do manipulate with links article.
References:
1. code in the ruins, Opera 9/SOCKS hack, http://code.mogrify.org/2006/07/05/opera-9socks-hack/
2. polishlinux.org, SSH Tunnels: Bypass (Almost) Any Firewall, http://polishlinux.org/apps/ssh-tunneling-to-bypass-corporate-firewalls/
2009-01-01
Why didn't Plan 9 take over the world?
Reasons:
*scanty documentation, much confusion and stumbling over fees and licensing.
* In 2003 it looks like Plan 9 failed simply because it fell short of being a compelling enough improvement on Unix to displace its ancestor.
* Some Plan 9 ideas have been absorbed into modern Unixes, particularly the more innovative open-source versions. FreeBSD has a /proc file system modeled exactly on that of Plan 9 that can be used to query or control running processes.
* Experimental 2003 versions of Linux are implementing per-process mount points, a long step toward Plan 9's private namespaces.
* The various open-source Unixes are all moving toward systemwide support for UTF-8, an encoding actually invented for Plan 9.
Conclusion:
Plan 9 is not good enough to take over to the various unix world.
2008-10-18
Modulus accepts floating type ?
float a, b;
a = 10.5;
b = a % 2;
First ball, there is a statement error, "2" is a integer data-type, and b is a lvalue expression as a floating type, so that they doesn't match in type manner. The line sould be modify to this:
b = a % 2.0f;
Second, modulus (%) only accept the integral computing, refer from the C++ Standard draft, Sec. 5.6, p. 124.
The conclusion is, modulus doesn't accept the floating data.
The next question is, how to get the remainder as like the modulus does?
2008-06-14
2008-02-03
2008-02-01
2007-12-06
SPARC: What to Do if You Forgot Root Password
(Use keyboard abort sequence--Press Stop A keys to stop the system)
ok boot net -s
# mount /dev/dsk/c0t3d0s0 /a
# cd /a/etc
# TERM=vt100
# export TERM
# vi shadow
(Remove root's encrypted password string)
# cd /
# umount /a
# init 6
2007-12-05
Quota setting of Linux & BSD
對於 Linux,是我最熟悉的系統,之前有設定過一次,可是出現錯誤,當下沒有立即排除,造成這次閱讀的時候釐清了一些原本誤解的觀念。例如,Quota 是 kernel mode 的功能,我有一種感覺一直以為要 dependence on HW;要怎樣的 quota limit 就得割一個 partition 給設定檔,一時腦筋轉不過來。既然都是軟體實做了,這些硬體的問題都會克服的。
接著,Venus 是跑 GNU/Debian Linux,大約花了三個小時設定,釐清觀念,事後很開心,翻起 FreeBSD Handbook 接著看。
FreeBSD 是 CoreDure Quad 的壯壯機,fBSD 對於我來說是個新系統,先前的成功經驗,加上對 fBSD 的新鮮感,所以猛看手冊。上次的進度停留在 Ch.4,今天大約花了五個小時,一直看到完。我沒那麼神,中間有些東西我不感興趣,例如 printer setting 還有 networking setting,所以就 skip into next lol。早上開始逐章讀,興致全開,竟然編起 FreeBSD Kernel,我真的很開心,因為學到不少新東西。之前見到 afoofa 說 Linux 的 make menuconfig is such friendy to her, but the interface FreeBSD is a little bit bored and monolithic. 但是我反而覺得 Handbook 教的很詳細,我很感謝 maintainer 把文件寫的那麼清楚,一一介紹,讓我觀念清楚明瞭,可以放心地跟著進度走。
今天編 kernel 都沒有 booting failure,真開心。不過還沒很確定是否要這麼做 make clean cleandepend depend buildkernel installkernel,前面三個步驟是我比較不清楚的。Durning making the source tree, I've found a interesting function, had before in Linux, that is -j, menas make "make" to does something in parallel. And my best argument is "16", not "32". It earns more and more time-saving and performance.
中午吃完飯,一度沉迷在 SMP 的 option。先說的,這篇 Installing the FreeBSD SMP Kernel 已經過期了,裡面的
APIC_IO, NCPU, NBUS, NAPIC 都已經在 6.2 kernel 失效了,只需要指定 SMP 就行了。接著,我又病發了,開始找 SMP 的實做時比較早,心中一直有個感覺,逐漸推翻 FreeBSD 優於 Linux 的看法。Linux 很多人送 code & patch,FreeBSD 則是人數沒有那麼多,而且 Linux 有不少商業公司背書,燒錢改善 Linux。不過,現在下定論還太早,因為各有可取之處。謂之:「量才適性,學而不倦」。
我現在找到最早的 Linux SMP 是 2.0 加入的,1996。而 FreeBSD 是 5.0, in 2003 推出。不過,我也有看見 1986 就在寫的,不知道正確與否。
後來,有個疑問:如果 OS kernel has no SMP supports, can program run as parallel, as like MP? 後來想到,如果 OS 沒有 SMP,四隻 folding@home process 會平分一個 CPU 資源,而有 SMP 的話,每隻都是跑到 99.8% 左右。哈哈~ 可是這又不是純 MP,如果用 icc 編的話,應該也會得到同樣的結果。
好奇 kernel 怎麼知道是 SMP-type cpu,用 asm does detect?
另一支 BSD Family 就是 Solaris,我一直覺得上面的 utilities 功能都不健全,Linux 算是最健全的,fBSD 其次,Solaris 最少。我看,說不定 AIX, IRIX, HP-UP 更少呢~ 可是,也必須承認,因為硬體特性的關係,這些大廠都寫了很多東西支援,是一般 i386 OS (Linux, fBSD) 不會去實做的。
光是 Solaris 要設定 quota 的手冊就翻了兩本,因為要 refer,加上我也對它不熟,所以今天眼睛累,手指也酸了,就先暫擱吧。
2007-10-22
Howto: Use tar command through network over ssh session
tar cf - /foo1 | ssh ffoo@192.168.1.201 "cat > /backup/wwwdata.tar.gz"
2007-10-15
2007-09-24
Ptt 的功能未來可能性
*Other reasons might include:
**Overcoming memory constraints - single computers have very finite memory resources. For large problems, using the memories of multiple computers may overcome this obstacle.
用 MPI 實做應該可行,不用特地買一台 20,000 NT 的 quad cores 機器。
2007-09-16
MVC - Model-view-controller
Model-view-controller (MVC) is an architectural pattern used in software engineering. In complex computer applications that present a large amount of data to the user, a developer often wishes to separate data (model) and user interface (view) concerns, so that changes to the user interface will not affect data handling, and that the data can be reorganized without changing the user interface. The model-view-controller solves this problem by decoupling data access and business logic from data presentation and user interaction, by introducing an intermediate component: the controller.
Perl::Catalyst
Perl::Jifty
PHP::CakePHP
PHP::Zend Framework
The brief is a good brief of wikipedia, I love its style forever.
cd2iso
/* This program has been compiled with VC6 and tested under Windows XP SP2 */
#include
#include
int main ( int argc, char ** argv )
{
FILE * f, * out;
char buf[512];
unsigned len;
if (argc != 2)
{
fprintf( stderr, "Syntax: rdiso filename\n" );
return 1;
}
if ( (f = _fsopen( "\\\\?\\CdRom0", "rb", _SH_DENYNO )) == NULL)
{
fprintf( stderr, "Can't open CdRom0\n" );
return 1;
}
if ( (out = fopen( argv[1], "wb" )) == NULL)
{
fprintf( stderr, "Can't open %s\n", argv[1] );
return 1;
}
do
{
len = fread( buf, 1, sizeof(buf), f );
if (len)
fwrite( buf, 1, len, out );
}
while (len == sizeof(buf));
fclose( f );
fclose( out );
return 0;
}
2007-09-14

In the book, "The Complete FreeBSD", wrote,
“Those Linux books hve over1000 pages! This looks like nothing. What can you do? We need something yesterday!”
Haha~~
2007-09-07
2007-09-06
ssh-copy-id
ssh-copy-id - install your identity.pub in a remote machine’s authorized_keys
ssh-copy-id [-i [identity_file]] [user@]machine
2007-09-05
Never have it again!!!
int** ptr = malloc( sizeof(int) * SIZE );
char** ptr = malloc( sizeof(char) * SIZE );
WRONG
int** ptr = malloc( sizeof(int**) * SIZE );
char** ptr = malloc( sizeof(char**) * SIZE );
RIGHT
2007-08-30
2007-08-25
2007-08-22
You cannot modify the Hosts file or the Lmhosts file in Windows Vista
WORKAROUND
To work around this issue, follow these steps:
1. Click Start Start button , click All Programs, click Accessories, right-click Notepad, and then click Run as administrator.
User Account Control permission If you are prompted for an administrator password or for a confirmation, type the password, or click Allow.
2. Open the Hosts file or the Lmhosts file, make the necessary changes, and then click Save on the Edit menu.
2007-08-21
libmtsk.so
libmtsk.so,isinstalled on the running system.
How can I find out the libmtsk.so. :(
Haha~~ have the patch for old-school. :D
SunOS 5.9: Microtasking libraries (libmtsk) patch
2007-08-20
Algorithm for square matrix multiplication
The Strassen: O(n^2.807)
The fastest*: O(n^2.376)
As the Strassen algorithm [ http://0rz.tw/bf2Xo ] mentioned:
The reduction in the number of multiplications however comes at the price of a somewhat reduced numeric stability.
* Coppersmith–Winograd algorithm
Reference:
*The Simultaneous Triple Product Property and Group-theoretic Results for the Exponent of Matrix Multiplication, arXiv:cs.CS/0703145
2007-08-19
Links in Today
2.1.1.8 Multi-Threaded malloc
malloc and free are single-threaded operations and are among the bottlenecks for multi-threaded applications. A multi-threaded malloc scales with multi-threaded requests and can improve multi-threaded application performance. The Solaris OS has two types of multi-threaded malloc libraries, mt-malloc and umem.
2.1.1.8.1 Usage
a. Using mt-malloc:
LD_PRELOAD=libmtmalloc.so
b. Using libumem:
LD_PRELOAD=libumem.so
cc [ flag... ] file... -lumem [ library... ]
跟我的想法是一樣的,因為開矩陣還是需要很多時間的。
2007-08-16
gen()
#include
#include
#define N1 5000
#define N2 5000
void gen( int** a, int** b)
{
int i, j;
for (i = 0; i < N1; i++) {
for (j = 0; j < N2; j++) {
srand( 0 );
a[i][j] = rand() % 5 + 1;
srand( 1 );
b[i][j] = rand() % 5 + 1;
}
//printf("i: %d\n", i);
}
pthread_exit(NULL);
}
void mul( int** a, int** b)
{
int i, j, k;
int c[N1][N2];
for (i = 0; i < N1; i++) {
for (j = 0;j < N2; j++) {
c[i][j] = 0;
for (k = 0; k < N1; k++)
c[i][j] += a[i][k] * b[k][j];
//printf("%d\t", c[i][j]);
}
//printf("\n");
}
}
int main(int argc, char *argv[])
{
int** a = NULL;
int** b = NULL;
int** c = NULL;
a = (int**) malloc( sizeof(int) * N1 * N2);
b = (int**) malloc( sizeof(int) * N1 * N2);
c = (int**) malloc( sizeof(int) * N1 * N2);
pthread_t* thread = NULL;
thread = (pthread_t*) malloc( sizeof(pthread_t) * N1);
int result;
int i;
for (i = 0; i < N1; i++) {
a[i] = (int *) malloc( sizeof(int) * N2);
b[i] = (int *) malloc( sizeof(int) * N2);
c[i] = (int *) malloc( sizeof(int) * N2);
}
gen(a, b);
return 0;
}
$ gcc m1.c && time ./a.out
real 3m55.660s
user 3m55.391s
sys 0m0.184s
This result without threading.
2007-08-13
2007-08-12
#include <pthread.h>
#include <stdio.h>
#define N 10
void *test(void *c)
{
printf("\tI am thread: %d\n", (int)c);
pthread_exit(NULL);
}
int main()
{
int i, result;
pthread_t t[N];
for(i = 0; i < N; i++) {
result = pthread_create(&t[i], NULL, test, (void *)(i));
if (result)
printf("Cannot do create.\n");
}
return 0;
}
出來每次結果都不同。 :( 需要明確地等待
Cluster Building
研討會資料, HP 64bit Cluster
硬體資料
NCHC PC Cluster
國家高速網路與計算中心-PC Cluster 討論區
HIGH PERFORMANCE COMPUTING LAB. // 高效能計算實驗室 //, 東海大學
Reaching the Goal with the Regensburg Marathon-Cluster, Hubert Feyrer
High Performance Computing Training
Books,
*Beowulf Cluster Computing with Linux

*Parallel Programming: Techniques and Applications Using Networked Workstations and Parallel Computers

*An Introduction to Parallel Computing: Design and Analysis of Algorithms
Passing Multidimensional Arrays
#include <iostream>
using std::cout;
void print_m35(int m[3][5]);
void print_mi5(int m[][5], int dim1);
//void print_mij_(int m[][], int dim1, int dim2);
void print_mij(int* m, int dim1, int dim2);
void print_m35(int m[3][5])
{
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 5; j++) cout << m[i][j] << '\t';
cout << '\n';
}
}
void print_mi5(int m[][5], int dim1)
{
for (int i = 0; i < dim1; i++)
for (int j = 0; j < 5; j++) cout << m[i][j] << '\t';
cout << '\n';
}
/*
void print_mij_(int m[][], int dim1, int dim2)
{
for (int i = 0; i < dim1; i++) {
for (int j = 0; j < dim2; j++) cout << [i][j] << '\t';
cout << '\n';
}
}
*/
void print_mij(int* m, int dim1, int dim2)
{
for (int i = 0; i < dim1; i++) {
for (int j = 0; j < dim2; j++) cout << m[i * dim2 + j] << '\t';
cout << '\n';
}
}
int main()
{
int v[3][5];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
v[i][j] = j;
print_m35(v);
print_mi5(v, 3);
print_mij(&v[0][0], 3, 5);
return 0;
}
2007-08-11
libc-dev
Failed to read a valid object file image from memory
When I run it during debug process.
As the "file" results:
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.4.1, dynamically linked (uses shared libs), for GNU/Linux 2.4.1, not stripped
But actually, it should be like below,
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), not stripped
I'm not dare to remove the _big_base_ libc6, but I reinstall the "libc-dev" then it returns back to my hoping status. :D
SunFire 15K (Solaris & Debian)
Platform Group: sun4u
Current Status, Debian on SPARC platform
Supported are Sun4m and Sun4u machines (with a 32-bit userland).
UltraLinux
gprof
Linux Performance Analysis Tools
[Author], David Mosberger
---
Useful Tools tutorial
gprof TIPS:
* Don't optimize before profiling
* Be careful not to optimize before profiling!
* Profile before you optimize.
hahaha~~~ :D I compiled it with -O3 options of icc and gcc. :D
2007-08-07
Linux to Power Google GPhone
Sent to you by Alan via Google Reader:
"Google's first mobile phone reportedly will run a Linux operating system on a Texas Instruments "Edge" chipset, and will likely ship to T-Mobile and Orange customers in the Spring of 2008. "GPhone" call minutes and text messages will apparently be funded by mobile advertising, according to reports." The report found at the popular embedded systems Linux news site LinuxDevices.
Things you can do from here:
- on OSNews
- Subscribe to OSNews using Google Reader
- Get started using Google Reader to easily keep up with all your favorite sites
2007-08-06
Matrix Transpose
yrchen tole me a hint yesterday afternoon, that, the matrices should be tramsposed before did a huge compute. In today's experiment, I wrote two version codes, one doesn't has any transpose loop (called m1), the other does (called m1_t). Both them compiled with gcc, with -O3 optimization. The result is:
m1_t:
real 5m31.300s
user 5m31.245s
sys 0m0.020s
m1:
real 5m30.802s
user 5m30.265s
sys 0m0.008s
It looks like that -O3 did the transpose before has the huge matrices multiplication.
#include
#include
#define DIE 800
void gen( int a[][DIE]);
void mul( int a[][DIE], int b[][DIE]);
int main(int argc, char *argv[])
{
int a[DIE][DIE];
int b[DIE][DIE];
int i;
for (i = 0; i < 10000; i++) {
srand(0);
gen(a);
srand(1);
gen(b);
mul(a, b);
}
return 0;
}
void gen( int a[][DIE] )
{
int i, j;
for (i = 0; i < DIE; i++)
for (j = 0; j < DIE; j++)
a[i][j] = random() % 5 + 1;
}
void mul( int a[][DIE], int b[][DIE])
{
int i, j, k;
int c[DIE][DIE];
//Transpose
for (i = 0; i < DIE; i++)
for (j = 0; j < DIE; j++)
mul[i][j] = b[j][i];
for (i = 0; i < DIE; i++) {
for (j = 0;j < DIE; j++) {
c[i][j] = 0;
for (k = 0; k < DIE; k++)
c[i][j] += a[i][k] * mul[i][k];
//printf("%d\t", c[i][j]);
}
//printf("\n");
}
}
2007-08-04
Matrix Mutiplication Hint
因為 CPU 會一次 fetch 1byte in each row, 而 matrix mul 是 col * row,所以可以直接把做一次 det(row) -> col,就能直接 fetch det(row) -> col。速度較快!
不要使用 recursive,因為 OS 要 handle 很多 stacks is a heavy-loading job。直接改用多個 whilie 把 huge-matrix 展開,開 threads 去分割成 strsen algo smaller-matrix.
這是 yrchen 給的 common hint.
2007-08-03
2007-08-02
2007-07-31
Parallel Programming
Parallel Programming: Techniques and Applications Using Networked Workstations and Parallel Computers
Barry Wilkinson
Parallel Computers
Concurrency vs. Parallelism
2007-07-27
Linux: The 0.01 Release
Sent to you by Alan via Google Reader:
"This is a free minix-like kernel for i386(+) based AT-machines," began the Linux version 0.01 release notes in September of 1991 for the first release of the Linux kernel. "As the version number (0.01) suggests this is not a mature product. Currently only a subset of AT-hardware is supported (hard-disk, screen, keyboard and serial lines), and some of the system calls are not yet fully implemented (notably mount/umount aren't even implemented)." Booting the original 0.01 Linux kernel required bootstrapping it with minix, and the keyboard driver was written in assembly and hard-wired for a Finnish keyboard. The listed features were mostly presented as a comparison to minix and included, efficiently using the 386 chip rather than the older 8088, use of system calls rather than message passing, a fully multithreaded FS, minimal task switching, and visible interrupts. Linus Torvalds noted, "the guiding line when implementing linux was: get it working fast. I wanted the kernel simple, yet powerful enough to run most unix software." In a section titled "Apologies :-)" he noted:
"This isn't yet the 'mother of all operating systems', and anyone who hoped for that will have to wait for the first real release (1.0), and even then you might not want to change from minix. This is a source release for those that are interested in seeing what linux looks like, and it's not really supported yet."
Things you can do from here:
- on KernelTrap - Linux news, FreeBSD news, OpenBSD news, NetBSD news, GNU/Hurd news, BeOS news, MacOS news, Tools, Windows news, Other news
- Subscribe to KernelTrap - Linux news, FreeBSD news, OpenBSD news, NetBSD news, GNU/Hurd news, BeOS news, MacOS news, Tools, Windows news, Other news using Google Reader
- Get started using Google Reader to easily keep up with all your favorite sites
2007-07-26
Schedule
2. 1 + 2 + 3 + ... + 999999 with pthreads method
3. Dividing the huge matrices into small parts
4. Redo last step with pthreads
5. Knowing how to manipulate icc
pthread
Native POSIX Thread Library (NPTL), getconf GNU_LIBPTHREAD_VERSION, NPTL 2.3.6
NPTL Trace Tool
IBM Linux Technology Library, Linux threading models compared: LinuxThreads and NPTL
2007-07-14
2007-07-13
2007-07-06
HPC Links
Z RESEARCH enables System Integrators, with little or no experience in clustering, to build Clustered File Storage, HPC Clusters and Supercomputers from Commodity off the Shelf Components (COTS) using Clustered architecture and Z RESEARCH'S software stack 'Gluster'.
amar, 可愛的網域。 :) 是一位印裔工程師。
白爛的圖片Computer cluster
2007-07-05
e1000_request_irq: Unable to allocate MSI interrupt Error: -22
Links:
google://
dmesg eth0 e1000_request_irq Unable to allocate MSI interrupt Error: 22
wired ethernet interface missing
e1000 high latency problem, msi error on boot.
2007-06-22
OpenMP
HPCxTR0411 "OpenMP Microbenchmarks Version 2.0", Fiona Reid, Mark Bull
OpenMP Microbenchmarks page
Zahir, IBM eServer p690, p690+ et p655 (Regatta Power4)
Sparc 64 cross compiler
Jun 20 13:59:59 stutb genunix: [ID 540533 kern.notice] ^MSunOS Release 5.9 Version Generic_112233-08 64-bit
Jun 20 13:59:59 stutb genunix: [ID 943905 kern.notice] Copyright 1983-2003 Sun Microsystems, Inc. All rights reserved.
Crosstool build results
So that all failed!
2007-06-21
人家只是轉圖檔而已...
for i in `ls -1 *.jpg`;do (convert -quality 48 -crop +0-1000 "$i" tmp/"$i" &); done
如此而已就 :(
寫信來去論壇問看看
2007-06-20
Perldoc, Day 1
Using my in combination with a use strict; at the top of your Perl scripts means that the interpreter will pick up certain common programming errors. For instance, in the example above, the final print $b would cause a compile-time error and prevent you from running the program. Using strict is highly recommended.
類似 gcc -Wall
unless ( condition )
if (!condition)
Note that the braces are required in Perl, even if you've only got one line in the block.
Too bad
print "LA LA LA\n" while 1; # loops forever
Cool!!
A list of them is given at the start of perlfunc and you can easily read about any given function by using perldoc -f functionname .
You can read from an open filehandle using the <> operator. In scalar context it reads a single line from the filehandle, and in list context it reads the whole file in, assigning each line to an element of the list:
Reading in the whole file at one time is called slurping. It can be useful but it may be a memory hog.
寫的真傳神! hog *grin* :P
When you're done with your filehandles, you should close() them (though to be honest, Perl will clean up after you if you forget):
哈! 好笑! though to e honest. :P
if ($a =~ /foo/) { ... } # true if $a contains "foo"The // matching operator is documented in perlop. It operates on $_ by default, or can be bound to another variable using the =~ binding operator (also documented in perlop).
In [perlop.html],
Binary "=~" binds a scalar expression to a pattern match. Certain operations search or modify the string $_ by default. This operator makes that kind of operation work on some other string. The right argument is a search pattern, substitution, or transliteration. The left argument is what is supposed to be searched, substituted, or transliterated instead of the default $_. When used in scalar context, the return value generally indicates the success of the operation. Behavior in list context depends on the particular operator. See "Regexp Quote-Like Operators" for details and perlretut for examples using these operators.
If the right argument is an expression rather than a search pattern, substitution, or transliteration, it is interpreted as a search pattern at run time.
Binary "!~" is just like "=~" except the return value is negated in the logical sense.
These are documented at great length in perlre, but for the meantime, here's a quick cheat sheet:
XDDD 快速騙人小抄 (quick cheat sheet)
while (<>) {
next if /^$/;
print;
}
我覺得寫的很美!
while ((c = get()) != NULL) {
printf ("%s\n", c);
}
http://cpan.stu.edu.tw/
第一次嘗試 CPAN install Bundle::CPAN 跑出一大堆鬼東西,看起來這個系統寫的很完整,也很大!
2007-06-19
PCMan, Day 1
Advice from the creator of C++
A Tour of C++
Procedural Programming
Decide which procedures you want; use the best algorithms you can find.
Modular Programming
Decide which modules you want; partition the program so that data is hidden within modules.
IBM Blade Center
Bjarne Stroustrup's homepage
Separate compilation is an issue in all real programs. It is not simply a concern in programs that present facilities, such as a Stack, as modules. Strictly speaking, using separate compilation isn't a language issue; it is an issue of how best to take advantage of a particular language implementation. However, it is of great practical importance. The best approach is to maximize modularity, represent that modularity logically through language features, and then exploit the modularity physically through files for effective separate compilation.




