说明 算法说明详见 TAOCP 4.6.3 Evaluation of Powers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 package main import "fmt" func power(x, n uint64) uint64 { var total uint64 = 1 if n == 0 { return 1 } else if n == 1 { return x } else { for n > 0 { if n & 1 == 1 { total *= x } x *= x n = n >> 1 } } return total } func main() { var x, n, result uint64 fmt.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 package main import ( "fmt" "time" "math/rand" ) func sort(arr [10]int) [10]int { var temp int length := len(arr) i := 1 for i < length { j := i - 1 temp = arr[i] for j > -1 && arr[j] > temp { arr[j+1] = arr[j] j-- } arr[j+1] = temp i++ } return arr } func main() { var arr [10]int var temp, i int i = 0 temp = len(arr) for i < temp { rand.
说明 之前在Ubuntu下可以用qemu-nbd挂载出来,现在换成CentOS, CentOS默认的内核没有开启NBD,用不了qemu-nbd, 于是用libguestfs挂载。 安装相关的包 yum install libguestfs libguestfs-tools -y 如果挂载的是windows系统,如果安装 libguestfs-winsupport yum install libguestfs-winsupport -y 挂载 guestmount --rw -a /var/lib/nova/instances/62bfb922-45ca-4440-a545-532bd8ce8748/disk -m /dev/sda1 /mnt/tmp/ 解除挂载 umount /mnt/tmp
更新源 vim /etc/apt/sources.list deb http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse apt-get update 安装依赖包 apt-get install pkg-config libapr1-dev zlib1g-dev libconfuse-dev libexpat1-dev libpcre3-dev daemon sysv-rc-conf 安装Ganglia gmond http://ganglia.
检查是否有modpython.so ls -alh /usr/local/ganglia-3.6.0/lib64/ganglia/ | grep modpython ganglia 默认是开启mod_python ./configure --help | grep python --disable-python exclude mod_python and support for metric modules written in python --with-python=PATH Specify prefix for python or full path to interpreter 如果安装发现没有modpython.so, 说明找不到Python.h, 需要安装python-devel,这个在configure.ac有做test more ./configure.ac | grep Python # check for Python executable AC_MSG_CHECKING(Python version) if test -f "$PyEXEC_INSTALLDIR/include/python/Python.h"; then if test -f "$PyEXEC_INSTALLDIR/include/python$PyVERSION/Python.h"; then AC_MSG_CHECKING(Python support) 下载gmond_python_modules mkdir -p /usr/local/src cd /usr/local/src git clone https://github.
在 CentOS 6.5 使用 KVM 检查是否开启CPU虚拟化 cat /proc/cpuinfo | egrep "(vmx|svm)" --color=always 禁用selinux vim /etc/selinux/config SELINUX=disabled setenforce 0 设置转发 sed -i 's/^\(net.ipv4.ip_forward =\).*/\1 1/' /etc/sysctl.conf; sysctl -p 安装KVM yum -y install @virt* dejavu-lgc-* xorg-x11-xauth tigervnc libguestfs-tools policycoreutils-python bridge-utils 设置libvirt自动开启并重启 chkconfig libvirtd on;reboot 验证是否加载KVM模块 lsmod | grep kvm 设置桥接网络 chkconfig network on service network restart yum -y erase NetworkManager cp -p /etc/sysconfig/network-scripts/ifcfg-{eth0,br0} sed -i -e'/HWADDR/d' -e'/UUID/d' -e's/eth0/br0/' -e's/Ethernet/Bridge/' /etc/sysconfig/network-scripts/ifcfg-br0 echo DELAY=0 >> /etc/sysconfig/network-scripts/ifcfg-br0 echo 'BOOTPROTO="none"' >> /etc/sysconfig/network-scripts/ifcfg-eth0 echo BRIDGE=br0 >> /etc/sysconfig/network-scripts/ifcfg-eth0 service network restart brctl show 创建虚拟机 查看可选用的操作系统