Arbitrary precision arithmetics packages

In some cases when high precision is needed, long int , long double may be not precise enough.  The following packages performing arbitrary precision arithmetics may be considered :

GMP ,   MPFR ,   arprec .

Posted in reserarch | Leave a comment

installing PETSc and SLEPc

SLEPc depends on PETSc. So install PETSc first. I download sletc-3.1-p6.tgz and it needs PETSc 3.1 with pathlevel > 4. I tried petsc-3.2-p2 and it turns out version 3.2 is too new with slepc-3.1-p6: the configuration for slepc can not be successful. So I turn to petsc-3.1-p8.

The source code of petsc is unzipped in ~/tmp/petsc-3.1-p8, then execute the following cmds:

PETSC_DIR=$PWD; export PETSC_DIR
./configure --prefix=/home/wzhang/local/petsc-3.1-p8 --with-blas-lapack-dir=/home/wzhang/local/lib/ --with-mpi-dir=/home/wzhang/local/bin/
make PETSC_DIR=/home/wzhang/tmp/petsc-3.1-p8 PETSC_ARCH=linux-gnu-c-debug all
make PETSC_DIR=/home/wzhang/tmp/petsc-3.1-p8 PETSC_ARCH=linux-gnu-c-debug install
make PETSC_DIR=/home/wzhang/local/petsc-3.1-p8 test

Notice I have already installed blas, lapack, and mpi in the directory /home/wzhang/local/lib , after the above steps, the petsc library is installed in /home/wzhang/local/petsc-3.1-p8. then add the following line in the .bashrc files.

PETSC_DIR=/home/wzhang/local/petsc-3.1-p8; export PETSC_DIR

after the petsc is installed, unzip the source code of slepc in /home/wzhang/tmp directory, execute the following cmds:

  source ~/.bashrc
  SLEPC_DIR=$PWD; export SLEPC_DIR
  ./configure --prefix=/home/wzhang/local/slepc-3.1-p6
  make PETSC_ARCH=installed-petsc
  make PETSC_ARCH=installed-petsc install
  SLEPC_DIR=/home/wzhang/local/slepc-3.1-p6; export SLEPC_DIR
  make test

again, add

SLEPC_DIR=/home/wzhang/local/slepc-3.1-p6; export SLEPC_DIR

in ~/.bashrc.

When using petsc-3.2-p2, the configure file of slepc will complain about the version of petsc and the INSTALL_DIR variable is not defined in $(PETSC_DIR)/conf/petscvariables. It seems that petsc change a lot from 3.1 to 3.2.

Posted in Computer science | Leave a comment

使用 hypre 的经历

我的并行程序需要调用 hypre 求解一个三维的 Poisson 方程。总体的感觉 hypre 还是挺方便的,当然 hypre 本身提供了结构网格(Struct)和半结构 (SStruct) 网格,以及有限元的界面,我只用到了结构网格。但我的程序和通常有点不同, 我自身的程序就是并行的, 已经将网格分片存储在各个进程上,而要求解的物理量是定义在结点上的,调用 hypre 时首先也要定义网格,而 hypre 只支持定义在网格中心的量的求解。这就导致我自身程序的网格和 hypre 的网格有区别(中心是结点,结点是中心),程序为了得到 Poisson 方程的解,我需要利用 hypre 解向量中影像区的值 …

我写了个简单的例子测试了一下,网格是2维 2×2 的网格,结点只有4个: (0,0), (0,1), (1,0), (1,1).
代码如下:

    if (rank == 0) {
    ilower[0] = 0;    ilower[1] = 0;
    iupper[0] = 0;    iupper[1] = 0;
    HYPRE_StructGridSetExtents(poisson_grid, ilower, iupper);
    ilower[0] = 0;    ilower[1] = 1;
    iupper[0] = 0;    iupper[1] = 1;
    HYPRE_StructGridSetExtents(poisson_grid, ilower, iupper);
  }   else {
   ilower[0] = 1;    ilower[1] = 0;
   iupper[0] = 1;    iupper[1] = 0;
   HYPRE_StructGridSetExtents(poisson_grid, ilower, iupper);
   ilower[0] = 1;    ilower[1] = 1;
   iupper[0] = 1;    iupper[1] = 1;
   HYPRE_StructGridSetExtents(poisson_grid, ilower, iupper);
 }

将网格分在两个进程上,每个上面两个结点,每个结点是一个 box. 计算发现对 (0,0) 这个box, hypre 会自动填充影像区中(0,1) 和 (1,0) 两个结点的值,而不会填充 (1,1) 的值。其他 box 也有类似的问题。

说清楚这个问题真不容易, 网上搜索也找不到有用的东西。就决定骚扰一下 hypre 作者,发信问他该如何填充影像区,可能是没表达清楚,对方回答成了另一个问题: 要打印影像区的值该如何如何 … 折腾了几天,突然想到可能 hypre 并不会填充影像区所有值,而只会填充需要的,而哪些是需要的是由用户由 hypre 中的 stencil 指定的。对上例, 我定义的 stencil 由五点组成,即每个点和周围的四个点有关:

  int offsets[5][2] = {{-1,0}, {1,0}, {0,0},{0,-1},{0,1}};
  HYPRE_StructStencil  stencil;
  HYPRE_StructStencilCreate(2, 5, &stencil);
  for (s = 0; s < 5; s++)
    {
      HYPRE_StructStencilSetElement(stencil, s, offsets[s]);
    }

(0,0) 和 (1,1) 并没有关系, 所以 hypre 不会填充影像区中 (1,1) 和这个点的值。于是把 stencil 改成和周围 8 个点有关(不知道为什么 stencil 并不能任意改, 改的不对程序就会报错),正像我想的一样,(1,1) 也被填充了。

虽然只是猜测,并不知道 hypre 内部具体怎么实现的, 但经测试和所想的一样,并且三维的也对,就先这么用了.

Posted in Computer science, reserarch | Leave a comment

g++ 版本问题

上次在笔记本上安装 petsc 时,忘了什么原因, 把机器上的 g++ 从 g++32 改成 g++40, 以前能够通过编译的程序重新编译时在链接库文件时报错如下, google 之发现可能是由于程序调用了一些库文件,这些库文件是用旧版本的编译器编译的, 这次重新编译时由于 g++ 该成 g++40 , 导致新旧版本的.o 文件链接而出错, 试着在 /usr/bin 目录下:

rm -f g++
ln -s g++32 g++

重新编译成功!

开始的错误:

MCModel.o(.gnu.linkonce.r._ZTC7MCModel8_N6JASMIN4algs30StandardComponentPatchStrategyILi3EEE[vtable for MCModel]+0x70): 
     undefined reference to `non-virtual thunk to JASMIN::algs::StandardComponentPatchStrategy::~StandardComponentPatchStrategy()'
MCModel.o(.gnu.linkonce.r._ZTC7MCModel8_N6JASMIN4algs30StandardComponentPatchStrategyILi3EEE[vtable for MCModel]+0x74): 
     undefined reference to `non-virtual thunk to JASMIN::algs::StandardComponentPatchStrategy::~StandardComponentPatchStrategy()'
/usr/local/jasmin-1.1/lib/libJASMIN3d_adpt.a(AsyncBergerRigoutsos-NDIM3.o)
....
Posted in Computer science | Leave a comment

修改头文件后一定要重新编译 !

写了一个 makefile 来管理编译,修改代码时发现有几个变量定义了却从来没有使用过,就随手将头文件中的变量定义删除了, 但我没有意识到这一点,重新 make 后通过,运行时却开始出各种各样的错误。 调试了一个多小时也找不到原因。 折腾半天才发现 makefile 写的有问题,导致有的 .o 文件不依赖于修改了的 .h , 所以每次 make 时这些.o 文件并没有被冲新编译。抱着试一试的想法, 输入 make clean 全部重编,再运行时正常。

教训: 一定要把 makefile 中的依赖关系写全!

Posted in Computer science | Leave a comment

和经济有关的一些视频

总结一些看过的不错的视频:

中国股市记忆 —  资本市场 20 多年大大小小的故事,每一集很短,可以了解一下过去.

激荡 30 年 —- 根据书改编的记录片,讲述改革开放以来经济发展过程 (1978-2008),每一集记录一年中的典型事件.   强烈推荐.

大国崛起 —- 从世界范围内记录国家发展的历程.

财经面对面 —– 新浪的一个人物采访节目.

Posted in 经济 | Leave a comment

reinstall ubuntu 10.04

Since my system is hacked, I decide to reinstall it. my /home and / directory is in different disk partition /dev/sda8, /dev/sda7. so I format /dev/sda7 and reinstall the system on it, leaving /dev/sda8 unchanged. I forgot to mount the /dev/sda8 to /home during install, so /dev/sda8 (where the old /home directory stay) is not mounted. and my /etc/fstab is

#   proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda7 during installation
UUID=b97a938c-7855-48c3-8425-1ba17daacf3b /               ext3    errors=remount-ro 0       1
# swap was on /dev/sda9 during installation
UUID=f75d0145-9bbb-4bec-8e9b-c3f52bce7af1 none            swap    sw              0       0

I added the uuid of /dev/sda8 to /home mount point, so that it can be mounted to /home every time when the system is booting. Other disk partition (of windows system) can be mounted similarly. Then I install the common soft package: svn, git, mplayer, etc. using apt-get, following my previous post.
What I need to do is to start some services on my machine: ftp, www, svn. I already have the home directory for ftp, www, svn : /home/ftp , /home/www , /home/svn.

  1. for svn service, first add a user named svn : adduser svn. To start the svn service , install openbsd-inetd first:
    sudo apt-get install openbsd-inetd

    then add a line

    svn stream tcp nowait svn /usr/bin/svnserve svnserve -i -r /home/svn

    in /etc/inetd.conf , after restart the openbsd-inetd server:

    sudo /etc/init.d/openbsd-inetd restart

    the svn server works.

  2. for www service, install apache2 first:
    sudo apt-get install apache2

    then using website browser to check localhost, it should work. php module can be install simply:

    sudo apt-get install libapache2-mod-php5

    the configure file of apache server /etc/apache2/sites-enabled/000-default needs to been modified. In my example, the document root in this file is changed from /var/www to /home/www. To enable mysql, install it first,

    sudo apt-get install mysql-server-5.1
    sudo apt-get install libapache2-mod-auth-mysql
    sudo apt-get install php5-mysql
    sudo apt-get install php5-gd

    add

    extension=mysql.so
    extension=gd.so

    in file /etc/php5/apache2/php.ini. Generally speaking, phpmyadmin needs to be install and configured. In my case, it is already there in my /home/www/phpmyadmin. I have build a blog using wordpress on my machine, and the database is gone, so I need to restore it. This will be talked in another place. Anyway, after the above configuration, the apache server works with php and mysql modules enabled.

  3. for the ftp service, it is a little bit complicated. All I did is following one post 
    <<Vsftpd虚拟用户设置 >>

My own libraries, such as mpi, lapack, blas, are installed in my home directory /home/wzhang/local, hence I do not need to reinstall them.

Posted in Computer science | Leave a comment

my ubuntu system is hacked

my system in my lab was hacked yesterday. At the beginning, when I type ls command in terminal, it return

ls: unrecognized prefix: rs
ls: unparsable value for LS_COLORS environment variable

and the Chinese character was not correctly displayed. I didn’t find other peculiar problem with my system and think it is not serious. Later, when I try to fix the above problem, I login from another PC using ssh , I found the login shell is changed! I check the $BASH environment variable: echo $BASH, it return /lib/libsh.so/bash, not /bin/bash. then I check the login information using last command

wzhang@wzhang-lab:~$ last
wzhang   pts/7        :0.0             Sun Feb 13 20:21 - 20:27  (00:06)
wzhang   pts/8        :0.0             Sun Feb 13 20:16 - 20:28  (00:12)
wzhang   pts/8        :0.0             Sun Feb 13 20:03 - 20:03  (00:00)
root     pts/8        124.162.56.217   Sun Feb 13 07:40 - 07:46  (00:05)
root     pts/8        124.162.56.217   Sun Feb 13 07:33 - 07:35  (00:01)
root     pts/8        211.65.8.214     Sun Feb 13 05:20 - 05:20  (00:00)
root     pts/8        tu131075.ip.tsin Sun Feb 13 04:11 - 04:13  (00:02)

the last four login record using user root is abnormal: the ip address is unknown and is logged in when I was sleep, damned! So I was sure that someone attacked my system!
several changes have been made by the hacker:

  1. wzhang@wzhang-lab:/bin$ ls -la | grep hal
    -rwxr-xr-x   1 122      haldaemo    39696 Mar  5  2010 ls
    -rwxr-xr-x   1 122      haldaemo    54152 Feb 12  2010 netstat
    -rwxr-xr-x   1 122      haldaemo    62920 Dec 17  2009 ps
    

    the group user of the above three command has been changed to haldaemo. and in /usr/bin/

    wzhang@wzhang-lab:/usr/bin$ ls -la | grep hald
    -rwxr-xr-x   1 122      haldaemo    59536 Mar  9  2010 find
    -rwxr-xr-x   1 122      haldaemo    31452 Mar  5  2010 md5sum
    -rwxr-xr-x   1 122      haldaemo    12340 Jan 18  2010 pstree
    -rwxr-xr-x   1 122      haldaemo    33992 Dec 17  2009 top
    

    and in /sbin/

    wzhang@wzhang-lab:/sbin$ ls -la | grep hald
    -rwxr-xr-x   1 122      haldaemo    31504 Feb 12  2010 ifconfig
    -rwxr-xr-x   1 122      haldaemo   212747 Mar  5  2010 ttyload
    -rwxrwxr-x   1 122      haldaemo    93476 Mar  5  2010 ttymon
    
  2. a directory named libsh has been setup.

    wzhang@wzhang-lab:/usr/lib/libsh$ ls -la
    ls: unrecognized prefix: rs
    ls: unparsable value for LS_COLORS environment variable
    total 100
    drwxr-xr-x   6 root     root         4096 Feb 13 07:41 .
    drwxr-xr-x 221 root     root        69632 Feb 13 07:41 ..
    drwxr-xr-x   2 root     root         4096 Feb 14 00:19 .backup
    -rwxr-xr-x   1 122      haldaemo     1206 Apr 18  2003 .bashrc
    drwxr-xr-x   2 root     root         4096 Feb 13 07:41 .owned
    drwxr-xr-x   2 root     root         4096 Feb 13 07:41 .sniff
    -rwxr-xr-x   1 122      haldaemo     2000 Mar  5  2010 hide
    drwxr-xr-x   2 500      500          4096 Mar  5  2010 utilz
    

    in .backup, I found

    wzhang@wzhang-lab:/usr/lib/libsh/.backup$ ls -l
    ls: unrecognized prefix: rs
    ls: unparsable value for LS_COLORS environment variable
    total 540
    -rwxr-xr-x   1 root     root       141980 Feb 13 07:41 find
    -rwxr-xr-x   1 root     root        65708 Feb 13 07:41 ifconfig
    -rwxr-xr-x   1 root     root        38508 Feb 13 07:41 md5sum
    -rwxr-xr-x   1 root     root       110088 Feb 13 07:41 netstat
    -rwxr-xr-x   1 root     root        75600 Feb 13 07:41 ps
    -rwxr-xr-x   1 root     root        18052 Feb 13 07:41 pstree
    -rwxr-xr-x   1 root     root        68524 Feb 13 07:41 top
    

    hence, the daily used commands have been substituted!

  3. in directory /usr/include/, four strange files appeared:

    wzhang@wzhang-lab:/usr/include$ ls -l | grep 501
    -rwxr-xr-x   1 501      501            56 Mar  5  2010 file.h
    -rwxr-xr-x   1 501      501            84 Mar  5  2010 hosts.h
    -rwxr-xr-x   1 501      501            28 Mar  5  2010 log.h
    -rwxr-xr-x   1 501      501            89 Mar  5  2010 proc.h
    

I don’t know how to fix this modification, since the hacker changed a lot. What is more, I do not know the reason why the system is unsafe. All I can do is: reinstall the system, change the password of root and my login user, deny remote login as root by modifying /etc/ssh/sshd_config as follow:

PermitRootLogin no
Posted in Computer science | Leave a comment

netlib 上的 c 语言随机数发生器 ranlib

  1. 源代码可以从
    http://www.netlib.org/random/ 下载: ranlib.c.tar.gz .
  2. 安装, 代码中没有 makefile , 我自己写了一个.
    install_dir=/home/wzhang/local/
    CC=g++
    
    libranlib.a: com.o ranlib.o linpack.o
    	ar crs $@ $^
    com.o: com.c
    	$(CC) -c $^ -o $@
    ranlib.o: ranlib.c
    	$(CC) -c $^ -o $@
    linpack.o: ../linpack/linpack.c
    	$(CC) -c $^ -o $@
    install:
    	cp libranlib.a $(install_dir)/lib/
    	cp ranlib.h $(install_dir)/include/
    
    clean:
    	rm -f *.o *.a
    

    make install 后会安装在我家目录中的 lib 和 include 下.

  3. 使用时只需在 makefile 中指定头文件和库文件的位置即可. 下面是一个例子.
    LOCAL_DIR=/home/wzhang/local
    
    LDFLAGS=-lm -L$(LOCAL_DIR)/lib -lranlib -llapack -lblas 
    
    INCLUDES=-I$(LOCAL_DIR)/include
    
  4. 程序中使用时需要先初始化随机种子(否则每次产生的随机数相同).

     #include "ranlib.h"
      long is1, is2;
      char phrase[100];
      sprintf(phrase, "%ld", time(NULL));
      phrtsd(phrase, &is1, &is2);
      setall(is1, is2);
    

    然后即可调用相关的随机数函数,例如产生 0 到 n 之间的均匀分布 (整数):

     i = ignuin(0, n);
    

    其他可参考软件包的 README 和源码注释.

Posted in Computer science | Leave a comment

ubuntu 下安装配置 transmission 支持 ipv6

从源上安装的 transmission 好像无法下载. 大概是对 IPV6 的支持有问题. 按照网上帖子的建议从源码安装. 安装前首先卸载之前安装的 transmission :

sudo apt-get remove transmission

我无法登录官网, 所以从源上下载 transmission 代码

sudo apt-get source transmission

我下到的版本是 1.93. 解压后修改 libtransmission/web.c 文件,将文件中

if(( addr = tr_sessionGetPublicAddress( s, TR_AF_INET )))
curl_easy_setopt( e, CURLOPT_INTERFACE, tr_ntop_non_ts( addr ) );

两行删掉, 再进行编译. 编译源码需要安装一些其他包 libssl-dev, libcurl4-dev, intltool, libgtk2.0-dev, 源上都有. 编译时指定

    ./configure -enable-gtk

来支持图形界面. 装好以后可以使用 Ubuntu Software Center 将 transmission 添加到 “桌面快捷方式”. 之后可以进行下载,速度很快!

ps: 修改代码的风险比较大, 但改了确实管用, 没有遇到其他问题. 更详细的过程可以参考 ubuntu系统下Transmission下载六维空间bt文件的教程

Posted in Computer science | Leave a comment