2015年9月25日 星期五

An easy way to parallel your c code by using openmp

if your code has low dependencies between each others, you can just use openmp to parallelize your code.
In ubuntu, openmp is installed defaultly, so we don't need to install anything.
In your code, add
#include <omp.h>
in headers.
And add
#pragma omp parallel for
before your for loop.
like

And compile with flag -fopenmp.
gcc ctest.c -fopenmp .....
Then it would run like this.

2015年9月18日 星期五

using tmpfs

We have big memory in nowadays computers, so we can use it to accelerate. But sometimes we have to deal with data which may larger than our memory, then I did a little test whether the tmpfs can larger than our memory size. One can mount a tmpfs bigger than free space, but when it is filled with data, it would cause error. And the answer to deal with data larger than memory is having a big swap space to increasing the free space, which is composed by main memory and swap space.  So the scheme is having big swap space, then you can use tmpfs happily every time, but notice that if the power failed, all your results would be gone.

2015年9月13日 星期日

To change job scheduling policy in Linux.

To change job scheduling policy (job scheduler) in Linux, we can use "chrt" to achieve our goal.

Scheduling policies: 
-b | --batch set policy to SCHED_BATCH
-f | --fifo set policy to SCHED_FIFO
-i | --idle set policy to SCHED_IDLE
-o | --other set policy to SCHED_OTHER
-r | --rr set policy to SCHED_RR (default)

2015年7月24日 星期五

inline vs define

inline通常用於作為小而短的function的修飾字,用來提示compiler這段code很少,可以考慮直接在call它的地方作展開而不用真的作為function,作為function會有functions間跳轉之stack opeartions的overhead,直接在被call的地方展開就不用這些overhead,但會造成code體積變大,或許會造成cahce hit rate下降,所以交由compiler去安排

define的話就是直接展開了

Use tar and pigz to compress things in multithread



install pigz first

and then
tar -c --use-compress-program=pigz -f <tar.filename> <dir_to_zip>

2015年7月22日 星期三

make a big file

fallocate -l 10g filename
只有分配空間

dd if=/dev/zero of=fiename bs=1M count=10240
填零填到10GB後結束