2016年5月31日 星期二

ADATA UV150 16GB, Strontium JET 16GB

失心瘋買了一堆XD

來測測ADATA UV150和新加坡力鍶的Jet


威剛的UV150外觀,蓋子可以塞在尾端防止不見,終保

ADATA UV150 16G - 1

成績不錯,比我想像的好,不過Seq Q32比Seq慢不知道發生了什麼事


Strontium JET 16GB,蓋子一樣可以塞在尾端,五年有限保固,也不知道壞了要找誰保固科科



Strontium JET 16GB成績看起來不怎麼樣,不過寫入比UV150還好一些


隨身碟不小心不見了多難過,雖然很想買CZ80,但又怕不見,還是便宜的隨便用對我來說比較合適

2015年10月19日 星期一

qsort in c library

qsort shouldn't use a compare function like
int cmp(const void* a, const void* b){
    return *(int*)a - *(int*)b;
}
it would easily cause a overflow, like 2000000000-(-2000000000), it would  overflow and become a negative number.

instead, we should use a compare function like
int cmp(const void* a, const void* b){
    if(*(int*)a > *(int*)b)return 1;
    else if(*(int*)a < *(int*)b)return -1;
    return 0;
}

2015年10月7日 星期三

SSD optimizing in linux

If your are using ext4 as file system in SSD, you may consider add discard and noatime parameter in /etc/fstab.
discard makes it trim. And noatime makes it not modify the last read time information for file.

And you can change CFS i/o scheduler to noop scheduler.
The approach is to modify the /etc/default/grub, add elevator=noop in kernel parameter.
And do
update-grub
Or if you have many storage devices not only SSD but also motion driven devices, you can  edit or create a file in
/etc/udev/rules.d/60-schedulers.rules
contains
# set noop scheduler for non-rotating disks 
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="noop" 
# set cfq scheduler for rotating disks 
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="cfq"
And use
cat /sys/block/sda/queue/scheduler
to see the scheduler status.

2015年10月3日 星期六

test disk speed

hdparm -Tt /dev/sda

mount /dev/sda at /test
dd if=/dev/zero of=/test bs=1M count=1024

iotop
iometer
iozone

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.