2012年10月4日星期四

gnuplot for fedora16

download newest version here

tar xvzf  gnuplot-4.6.1.tar.gz

./configure

make

su

make install

gnuplot
------------------------------------------------
it should say

gnuplot>

congrats! 

2012年10月2日星期二

L1 BLAS MLK

I have encountered a weird problem about ddot_() which need to be declared before use. If not, cc compiler still does not report error info.

Besides that problem, finding right link and compile option for MKL is much more time-wasting. We can obtain link and compile option from official intel website here. But make sure to check your own env to make MKL works. Highly recommend to read MKL manual if you have time.Basically, check if -L path has .a file for mkl and -lxxxx(with use libxxx.a under -L path).

this is what I got from official tool:
 -L$(MKLROOT)/lib/intel64 -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread 

For me, I changed
$MKLROOT  to $MKL
 lib/intel64 to lib/em64
-lmkl_intel_ilp64 to -lmkl_intel_lp64
add -lm

The reason I add -lm is that MKL also need math lib, otherwise you would get a error typical of not finding the math module such as:

/util/intel/mkl/10.2.2.025/lib/em64t/libmkl_core.so: undefined reference to `cos'
/util/intel/mkl/10.2.2.025/lib/em64t/libmkl_core.so: undefined reference to `sqrt'
/util/intel/mkl/10.2.2.025/lib/em64t/libmkl_sequential.so: undefined reference to `log'

------------------------------------------------------
sometimes, we need to mv files into a folder which is in the same directory with those file, with mouse, it is easy to handle this task, but in linux, it is tricky...
 My method is to name the folder start with upper case which is unique in this directory, then use this handy shell:
mv [![:upper:]]* <folder name>

similar pattern:
[![:digit:]]*
*[[:lower:]123]: start with lower case and end with digit
[abc]* : start with 'abc'

Another handy shell command is script:

script -a blas.log

2012年9月18日星期二

High Performance Computing

MPI & OpenMP are used for parallel computing. Simply saying, MPI is mainly for multi-PC but OpenMP is for multi-core/CPU, single PC.

I found a good explanation here.

I am so excited to do something practical of parallel computing rather than theoretical model... really looking forward to it.

2012年8月2日星期四

vim tips

sp [filename]

ctrl+w+j/k

for 2 files copy and paste

2012年6月21日星期四

FEDORA16 /tmp

sudo /usr/sbin/tmpwatch -afv 3 /tmp

explanation is here in chinese

2012年3月19日星期一

inline and macro difference

First let's talk about the difference between macro and function

1. macro is done before compile, that's also why it is called pre-compile. So first of all, we use macro body to replace macro name. Then we do compile.

On the other hand, function is executed after compile. Actually, it is called in the process of execution. So we can see that macro take compile time and function take execution time.

2. Because we need to "call" function, we need to pay for some resource(cost). We need to keep the state, and then go into the called function, after "call" finish, we need to go back the function which call others. Then we need to recover state.

On the other hand, all these operation above will never happen in macro. What macro do is just string replacement(string! not other type). So the argument of macro will not occupy memory space. But function argument need memory space, since argument is variable info transfer. Argument is function's local variable. Also, we do not need to do computation for macro argument. Function is give the value of argument. Here, we use value which will lead to computation.

3. As we said above, macro is string replacement. But argument of function can be any type.
-----------------

What inline do is to "embed" its code to the function which call it. So we can save cost to call it.
We need be careful about inline function must be very simple. No loop, if else, etc.

PS: some compiler will handle simple function as inline automatically. Some complex function, even you declare it is inline, compile will not do so.
---------

NO grammar examination for MACRO! Inline will have grammar exam during compiling. That is the reason why most programmer choose inline but not macro.

2012年3月17日星期六

跟着环境走 放下身段

今天看一个视频,有两段话记下:
-------------------

一段是说一个女老板在日本开牛肉面店:

人要跟着环境走,跟着环境走不是说要顺流而下,而是你要跟周围的环境取得一个和谐的关系,你做什么就要像什么。

一段是一个师傅教咏春评价徒弟:

他学拳有少许障碍,就是爱面子。学拳有时,不管学拳其他东西也一样。如果不放下身段,很难有长足的进步。你不愿服输,如何能赢?
-----------------------
想到自己最近总是怀疑自己的能力,最终还是会调试出来。既然是自己选的路,不管自己的先天条件有多少,都不应该怀疑自己,如果连自己都不相信,遇到困难就会很沮丧而退缩。

而学东西的时候总是觉得自己工作过,尽管心底知道这和现在学的关系不大,但遇到问题总是不好意思去及时问别人,失去好多学习的机会。积少成多,自然不会出色。

熟能生巧,触类旁通,这能达到这个境界是要付出时间和精力的。另外,就是要学会集中注意力,这点也很重要,注意力意味着效率。

2012年2月26日星期日

fedora16 software

Fedora16 shortcut bug:

workaround:

gconftool-2 --type=string --set "/desktop/gnome/applications/terminal/exec" "gnome-terminal"

solution:

sudo yum install libgnome-devel.i686 gnome-devel-docs.noarch

-----------------------------------------------------------------------------------------

User is not in the sudoers file

change file /etc/sudoers

su

xxxx

visudo

add command below at the end:

username ALL=(ALL)ALL

------------------------------------------------------------------------

yum install libreoffice-base libreoffice-core libreoffice-calc libreoffice-impress libreoffice-writer libreoffice-langpack-en

------------------------------------------------------------------

Flashplayer

Flash player

  64bit:

  su yum install wget cd /tmpwget http://download.macromedia.com/pub/labs/flashplayer10/flashplayer10_2_p3_64bit_linux_111710.tar.gztar xzvf flashplayer10_2_p3_64bit_linux_111710.tar.gzmv /tmp/libflashplayer.so /usr/lib64/mozilla/plugins/

  32bit:

  su

rpm -ivh http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm

  rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux

  yum update

  yum install flash-plugin

--------------------------------------

sudo yum install vlc

2012年2月25日星期六

X220 WIN7 & FEDORA 16

PRE:
A. prepare flash disk(at least 4G) to boot
and install fedora
B. need internet connection during fedora installation.
C. clear enough disk in windows
D. download
http://download.fedoraproject.org/pub/fedora/linux/releases/16/Fedora/i386/iso/Fedora-16-i386-DVD.iso
or
http://download.fedoraproject.org/pub/fedora/linux/releases/16/Fedora/x86_64/iso/Fedora-16-x86_64-DVD.iso
------------------------------------------------------------------
START:

1. download grubinst-1.1-bin-w32-2008-01-01 http://download.gna.org/grubutil/

2. download grub4dos-0.4.4 http://download.gna.org/grub4dos/

3. run grubinst_gui.exe(administrator mode), choose your flash disk, installation, u should see a window says "The MBR/BS has been successfully installed"

4. unzip grub4dos-0.4.4, copy
grldr and menu.lst to / of flash disk

5.copy
Fedora-16-Beta-i386-DVD.iso, initrd.img and vmlinux(these two are in iso, u need to extract them) to / of flash disk. So now flash disk have 5 files.

6. add commands below at the end of menu.lst:

title F16 setup

root (hd0,0)

kernel /vmlinuz root=/dev/hda1

initrd /initrd.img

----------------------------------------------------------------

ps: initrd.img might be initrd when extract from iso, do not care about that, do not add .iso.

-------------------------------------------------------------------

7. reboot, F12, choose to boot from flash disk

8.choose F16 setup

9. next, when you choose the installation storage type, I choose the last one, create blablabla, then you can cut your disk by yourself, make sure you backup your data first.

10. next next.....choose software development if you want to do some coding in fedora...

11. next.................

-------------------------------------------------------------------------------------------------------------

swap:2G

/:5G ext4

/home:30G ext4

/usr/locale:20G ext4

/tmp:1G ext4

/var:2G ext4

/boot:200M ext3

------------------------------------------------------------------------------------


Now you can go to a party or watch Big Bang Theory or White Collar(Moz is soooo cooool)

enjoy :)

2012年2月21日星期二

LOCK CV

OS161 PLATFORM

LOCK IMPLEMENTATION


CV(condition variable) is for multi thread use. wait-wakeup
eg: T1, T2, T1 need test_cond(bool type) is true to be run. And test_cond is controlled by T2. In this case, how to achieve this?

Method 1:

T1 is sleeping and wake up every 5ns (arbitrary, can be any time period) come to examine the value of test_cond,if it is false, keep sleep; otherwise, start to run.

Method2:

T1 call cond_wait and wait when test_cond is false, when the value of test_cond is changed, T2 will call cond_signal to wake up T1(which is sleep & busy waitng), tell T1: hi, the value of test_cond is changed. T1: got you, I am going to run.

We can see the scenario of the bathroom on a plane, T1(old lady)and T2(old man) are two people, T2 is in the bathroom, T1 want to use it...So T1 stand up again and again to see if the bathroom is available or not.(if there is no light to indicate that). That is a waste, it waste T1's energy , it influence the beautiful waitress to look after her, it waste other customers' energy to see her around.

So here we go,.we have a light outside the bathroom, when T2 is in the bathroom, the light is red, the lady can go back to the seat and sleep, when T2 is done with his work, he will turn the light to green, and the light will call old lady(advanced light), and old lady can use it now.

here is the chinese version.



here and here is the comparison between semaphore, mutex and cv





---------------------------------------------------


-------------------------------------


---------------------------------------------------




2012年2月19日星期日

socket select multiuser file sharing

select
fd_set
FD_SET
FD_ISSET
FD_CLR

fd_set is a fd pool which could allow us to use single thread to do stdin, listening, reading(receiveing) and writing. With stdin, we also can do writing(sending) and reading.
--------------------------------------------------------

2012年2月15日星期三

string

we can use strlen(string) > 0 to see if a string is empty or not.

strcmp
strncmp useful!!! to see whether the first n characters are the same.

strcpy
-----------------------------------------------------

how to get "download ..."
how to get the word between space

---------------------------------------------------------------
how to get a array return from a function, 3 array? Many data structures?

2012年2月13日星期一

warning

warning: backslash and newline separated by space
Solution: The backslash (\) character is used as the continuation character to continue #define statements and strings to the next line. GCC expects the backslash character to be the very last character on the line. This warning indicates that there is a space after the backslash. Delete the space and any other characters that come after the backslash.

2012年2月8日星期三

socket-----C

fprintf(out, "Hello %s\n", name);
printf
sprintf
--------------------------
perror
--------------------------------------------------
int i = 0;
while(i < 10)
{
printf(".");
sleep(1);
i ++;
}
--------------------------------------------
int i = 1;
while(i < 10)
{
fprintf(stderr,".");
sleep(1);
i ++;
}
----------------------------------------------
int i = 1;
while(i < 10)
{
printf(".");
fflush(stdout);
sleep(1);
i ++;
}
-------------------------------------------
1 gcc default path: /usr/include
2 gcc -I directory
3 do not search default

about the driver compilation, usually we do not need kernel to search for default path. enforce the kernel not to do that with a parameter
---------------------------------------------
how to get local ip in c on linux is here
-------------------------------------------------------------------
scp test.c xxxxxx@timberlake.cse.buffalo.edu:./

-----------------------------------------------------------

:133:174 co 299
----------------------------------------------

2012年2月6日星期一

MNC 2/6

HTTP & SMTP

PULL (HOST INIT TCP )

PUSH(SENDER SERVER PUSH INFO TO RECEIVER SERVER, RECEIVER SERVER INIT TCP)

ASC2 for SMTP, PERSISTENT

HTTP: OBJECT, EACH OBJ IN ITS OWN RESPONSE MSG

SMTP: EMAIL MESSAGE , MULTIPLE OBJ SENT IN MULTIPART MSG

--------------------------------------
WEB BASED EMAIL

POP3 IMAP
----------------

LOCAL DNS SERVER

13 ROOT SERVER

TLD DNS SERVER

AUTHORITATIVE DNS SERVER

------------------------------

www.google.com
google.com
just different alias which is mapped to the same IP

2012年2月5日星期日

OS&GIANTS

This semesor I take OS course under the instruction of Professor Geoffery. He is a really funny and nice guy. Because of him, I watched super bowl for the first time(no laugh pls...). And I found that it is reallllllly interesting!!!

I am glad to take this course althogh it would be very tough. But that's why I come here.

Hope I can be stronger two months later.

git

do not use Ctrl+z but Ctrl+x to exit when enter git commit help window

if you face this error:

fatal: Unable to create '/path/to/repo/.git/index.lock': File exists.

If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.

this can solve the problem

rm .git/index.lock

----------------
git status
git diff
git reset HEAD <>
git checkout -- <>
git add <>
git commit
------------------
git tag -a "asst0-start" -m "ASST0 start"

vim ./gitignore

build
.depend
/defs.mk
kern/compile/
user/testbin/randcall/calls.c

-----------------------
When you clone a repository, Git automatically sets up the
remote repository you cloned from as linked to your clone.

git remote -v

Before you perform any merge it is best to have any changes in your
working directory committed.



2012年2月4日星期六

gdb tips

#gdbinit

(gdb) target remote unix:.sockets/gdb

#when gdb initiate, it will search and execute a file named .gdbinit under current directory

#if you are in gdb debugiing, use

source /.gdbinit
-----------------------------
r
n
s
c
b ; info b; d b n; disable b n; enable n
watch
bt
f n
l
i locals
set
p i
finish
c
q

-------------------------
(gdb) p i
$21 = 101
(gdb) p/a i
$22 = 0x65
(gdb) p/c i
$23 = 101 'e'
(gdb) p/f i
$24 = 1.41531145e-43
(gdb) p/x i
$25 = 0x65
(gdb) p/t i
$26 = 1100101

2012年1月29日星期日

VirtualBox

when install the deb package of virtualbox, u might face this error:

Unpacking replacement virtualbox-4.1 ...
dpkg: dependency problems prevent configuration of virtualbox-4.1:
virtualbox-4.1 depends on libcurl3 (>= 7.16.2-1); however:
Package libcurl3 is not installed.
dpkg: error processing virtualbox-4.1 (--install):
dependency problems - leaving unconfigured

so the problem is about the dependance package libcurl3 was not successfully installed in your ubuntu.

solution:

sudo apt-get -f install

-f Attempt to correct a system with broken dependencies in place

After this operation, 553 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://us.archive.ubuntu.com/ubuntu/ natty-updates/main libcurl3 i386 7.21.3-1ubuntu1.5 [220 kB]
Fetched 220 kB in 1s (121 kB/s)
Selecting previously deselected package libcurl3.
(Reading database ... 196705 files and directories currently installed.)
Unpacking libcurl3 (from .../libcurl3_7.21.3-1ubuntu1.5_i386.deb) ...
Setting up libcurl3 (7.21.3-1ubuntu1.5) ...
Setting up virtualbox-4.1 (4.1.8-75467~Ubuntu~natty) ...
Adding group `vboxusers' (GID 123) ...
Done.
* Stopping VirtualBox kernel modules [ OK ]
* Uninstalling old VirtualBox DKMS kernel modules [ OK ]
* Trying to register the VirtualBox kernel modules using DKMS [ OK ]
* Starting VirtualBox kernel modules [ OK ]
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Processing triggers for python-central ...
-----------------------------------------------------------------------
#see version of ubuntu
cat /etc/issue
sudo lsb_release -a

-----------------------------------------------------
#fix apt-get upgrade error
sudo rm /var/lib/apt/lists/* -vf

--------------------------------------------------------
uname -a
uname -r

2012年1月26日星期四

vim: easy way to look code

gdb InsertionSort
Ctrl+x a / layout src

--------------------------------------------

/etc/vim/vimrc

set nu
set hlsearch

-------------------------------

grep -r 512 ~/src

grep -r -E -n -B1 -A1 "runnable|threads" ~/src/kern

-i skip the diff between a and A

-I skip .o

-w
DEBUG_KMEMLEAK but not DEBUG_KMEMLEAK_EARLY_LOG_SIZE

-e "-lianghong"

find ~/gnuradio -name ben*

2012年1月24日星期二

vim: two file copy&paste diff

eg:

vim execlp.c
:sp/:vsp
:e fork1.c
Ctrl+w w
v
yy
Ctrl+w w
p

----------------------------

:vert diffsplit ~/src/kern/vm/kmalloc.c

:diffthis

vim -d file1 file2/vimdiff file1 file2

2012年1月18日星期三

gnuradio code for USRP2 TX/RX

#pkt.py(define send_pkt function, send the payload, according to eof to tell whether to send more packets or not)

#packet_utils.py(make packet, build a packet, given access code, payload, and whitener offset)
#packet will have access code at the beginning, followed by length, payload and finally CRC32

self.connect(self._pkt_input, self._modulator, self)

self.connect(self, self._demodulator, self.correlator, self.framer_sink)

-----------------------------------------------------------------------------
dbpsk.py

"differential BPSK modulation and demodulation"

"input is a byte stream (unsigned char) and the output is the complex modulated signal at baseband"

#function bits_per_symbol will return 1, so arity is 2
arity = powe(2, self.bits_per_symbol())

self.symbol_mapper = gr.map_bb(psk.binary_to_ungray[arity])

--------------------------------------------
psk.py

# identity mapping, range(2) is start from 0(default), the end is 2, so it means [0, 1, 2]
binary_to_ungray = {
2 : range(2),
4 : range(4),
8 : range(8)
}

-----------------------------------------
//how the actual symbol mapping to constellations is done
gr_map_bb.cc

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include
#include

gr_map_bb_sptr
gr_make_map_bb (const std::vector &map)
{
return gnuradio::get_initial_sptr(new gr_map_bb (map));
}

gr_map_bb::gr_map_bb (const std::vector &map)
: gr_sync_block ("map_bb",
gr_make_io_signature (1, 1, sizeof (unsigned char)),
gr_make_io_signature (1, 1, sizeof (unsigned char)))
{
for (int i = 0; i < 0x100; i++)
d_map[i] = i;

unsigned int size = std::min((size_t) 0x100, map.size());
for (unsigned int i = 0; i < size; i++)
d_map[i] = map[i];
}

int
gr_map_bb::work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const unsigned char *in = (const unsigned char *) input_items[0];
unsigned char *out = (unsigned char *) output_items[0];

for (int i = 0; i < noutput_items; i++)
out[i] = d_map[in[i]];

return noutput_items;
}
-------------------------------------------

dbpsk.py

#symbol clock recovery

self.receiver=gr.mpsk_receiver_cc(arity, 0,
self._costas_alpha, self._costas_beta,
fmin, fmax,
self._mm_mu, self._mm_gain_mu,
self._mm_omega, self._mm_gain_omega,
self._mm_omega_relative_limit)

-----------------------------------

//Basically M-PSK modulations in GNU Radio utilize the function

gr_mpsk_receiver_cc.cc

------------------------------------------------------

use gr.file_sink() to dump all kinds of data in GNU Radio
The dumped data can be read from Matlab using some conversion codes

---------------------------------------------------------

you need to make and make install when debugging, otherwise you don't add your new modifications to the library and install the library for the python code to access.

eg:
change gr_mpsk_receiver_cc.cc in gnuradio-core/src/lib/general/
change pkt.py in gnuradio-core/src/python/gnuradio/blks2impl

---------------------------------------------------------
benchmark_tx.py
benchmark_rx.py
usrp_transmit_path.py
usrp_receive_path.py
transmit_path.py
receive_path.py
pkt.py
packet_utils.py
dbpsk.py
dqpsk.py
gr_map_bb.cc


-------------------------------
tmr

1 trace dbpsk.py for connection with pkt.py

2 try code below

#!/usr/bin/env python

from gnuradio import gr, eng_notation, gru, window, blks2
from gnuradio import audio
from gnuradio import usrp
from gnuradio.eng_option import eng_option
from optparse import OptionParser
from gnuradio import gr_unittest


class my_top_block(gr.top_block):
def __init__(self):
gr.top_block.__init__(self)
self.data = (1+2j, 3+4j, 5+6j)
self.src = gr.vector_source_c (self.data)
self.converte = gr.complex_to_float()
self.re_sink = gr.vector_sink_f ()
self.im_sink = gr.vector_sink_f ()
self.connect (self.src, (self.converte,0))
self.connect ((self.converte,0), self.re_sink)
self.connect((self.converte,1), self.im_sink)

if __name__ == '__main__' :
tb = my_top_block()
try:
tb.run()
except KeyboardInterrupt:
pass

print "src data: ", tb.data
print "real: ", tb.re_sink.data()
print "imag: ", tb.im_sink.data()

3 use --log of benchmark to see what .dat file can get

4 Q: if I have made one DQPSK transmission for image transfer and now I want to check the transmission and reception of the image at different SNR values. I am unable to find any signal block where i can change the SNR value .

A:
You will want to add a Gaussian noise source and a add block to add
AWGN, or you can use the channel_model block. To set the SNR, you will
first have to calculate the signal power in your simulation and from
their, determine the noise power for your desired SNR. The convert the
noise power to an amplitude, which is what the noise source block
takes. Look in gnuradio-examples/python/digital/benchmark_loopback.py
to see an example of these calculations.

discussion is from here
------------------------------------------------------------------