2010年7月28日 星期三

swap two variable

For Interger
x ^= y;
y ^= x;
x ^= y;

For Float numberx=x+y;
y=x-y;
x=x-y;





2010年5月26日 星期三

安裝 GLU lib 於CentOS 5.3

    於CentOS 上使用 CUDA 時常會遇到缺少 cannot find -lGLU or cannot find -lXi  和 cannot find -lXmu 的編譯錯誤.

這時只要安裝以下的函式庫就可以解決

yum install freeglut freeglut-devel libXi-devel libXmu-devel

2010年4月27日 星期二

CUDA programming under Compute-Exclusive Mode

How can I tell my programs to choose the available device automatically

It is very simple to make your program automatically choose the right device: DO NOT use cudaSetDevice().
When you don't explicitly specify to use which device, your CUDA program will first try to set up context on device0. If device0 is not available, it will try device1.

What will happen if I choose a device which is being used by another program.

Since all GPU devices have been configured as compute-exclusive mode, the second thread which tries to contact with GPU device will be denied. If you insist using this device by using cudaSetDevice() in your code, you will receive an error when running a CUDA API function.

2010年4月19日 星期一

How to Step TAB for SCREEN

#編輯 .screenrc

vi ~/.screenrc
caption always "%{= bK} %{= bG} [%n]%t @ %H %{-} %= %{= bR} %l %{-} | %{= bG} %Y-%m-%d %{-}"
hardstatus alwayslastline " %-Lw%{= BW}%n%f %t%{-}%+Lw %=| %0c:%s "
 
# Ctrl + left  : last page
# Ctrl + right : next page
bindkey "^[[1;5C" next
bindkey "^[O5C" next
bindkey "^[[C" next
bindkey "^[[1;5D" prev
bindkey "^[O5D" prev
bindkey "^[[D" prev


SCREEN 熱鍵

1) Ctrl+a c:建立一個新分頁
2) Ctrl+a a:分頁往返
3) Ctrl+a [1...9]:切換到第 n 分頁
4) Ctrl+a d:Detach 將工作放到背景執行
5) Ctrl+a S:分割上下畫面
6) Ctrl+a [TAB]:在分割畫面中往返

References:
http://en.gentoo-wiki.com/wiki/Screen
http://blog.cwke.net/2008x06/screen
screen
screen 常用教學筆記

2010年4月8日 星期四

strtok 應用

char* strtok(char* str, const char* delimiters)

用途:將字串切割成tokens


用法:

#include <iostream>
#include <string.h>

using namespace std;

int main()

{
    char c[20] ="Hello World!"
    char *s;
    
    s = strtok(c, " ");

    while(s!= NULL){
      cout >> s >> endl;

      s = strtok(NULL, " ");
    }
}