apt使用系统代理

使用ubuntu的一些第三方源的时候apt update有可能遇到Could not connect to 错误,如果这是因为apt没有使用系统代理,则可以用如下解决方法

sudo visudo

在打开的文本编辑器中添加设置条目

Defaults env_keep = "http_proxy https_proxy ftp_proxy DISPLAY XAUTHORITY"

reference:

发表在 积少成多 | 留下评论

把主机作为git服务器

把主机当做git服务器使用非常容易

  1. remote主机创建git服务的用户,这里假设叫gituser
    sudo useradd -m gituser
  2. remote主机设置ssh公钥
    su gituser
    cd ~
    mkdir .ssh
    vim .ssh/authorized_keys # 复制公钥内容
    chmod 700 .ssh
    chmod 600 .ssh/authorized_keys
  3. remote主机初始化空想要同步的repo(使用--bare flag)
    mkdir -p ~/path_to/some_test_repo.git
    cd ~/path_to/some_test_repo.git
    git init --bare
  4. 本地电脑添加remote信息并push
    cd some_local/repo_path
    git remote add origin gituser@remote-server-url:/path_to/some_test_repo.git
    git push

参考材料:

发表在 积少成多 | 留下评论

获取python module的路径

每个module都会有__file__属性记录它的路径,以numpy为例

import numpy as np
import os
path = os.path.abspath(np.__file__)

Reference:
https://stackoverflow.com/questions/247770/how-to-retrieve-a-modules-path

发表在 积少成多 | 留下评论

MPI跨节点跑多GPU任务

需要确保资源正确分配,mpirun可以用如下命令,$ngpu$ 是跨节点的总GPU数,$ngpu_per_node是每个节点的GPU数量

mpirun -np $ngpu -npernode $ngpu_per_node \
    --map-by slot:pe=1 \
    --rank-by slot \
    --bind-to core \
    --report-bindings \
    <commond to run>

作业脚本为了跨节点GPU申请也需要使用额外的设置,这里以slurm为例,应该写成

#!/bin/bash
#SBATCH -N 4 # 节点数
#SBATCH --gres=gpu:8 # 每个节点的GPU个数,对应$ngpu_per_nod
#SBATCH --qos=<gpu资源名称> # 这部分需要参考服务器的说明
发表在 积少成多 | 留下评论

[Linux]指定程序运行的cpu id

在HPC上跑计算时,有时需要指定程序运行的CPU id以便获得更好的性能,下列linux命令可以达到这个目的:

taskset -c 0-5 <command> [arguments for command]

Reference:https://unix.stackexchange.com/a/635992

发表在 积少成多 | [Linux]指定程序运行的cpu id已关闭评论

macOS Quantum espresso编译hdf5支持

使用macports直接编译QE,会找不到macports的hdf5库,尝试各种flag设置无果后,改用手工编译HDF5解决

编译安装hdf5

./configure --prefix=$HOME/opt/hdf5 --enable-fortran --enable-parallel  --enable-hl 
make && make install

注意configure时需要添加fortran支持等flag

编译安装QE

configure

F90=gfortran CC=gcc \
BLAS_LIBS="-L/opt/local/lib -lopenblas" \
LAPACK_LIBS="-L/opt/local/lib -lopenblas" \
./configure --enable-openmp --disable-parallel --enable-debug \
            --with-hdf5=$HOME/opt/hdf5

删除不支持的编译flag

生成的makefile会包含一个不支持的flag,-lrt,需要从make.inc中删除

make and test

make pw # only pw.x and related modules
cd test-suite
make run-tests-pw
发表在 笔记 | 留下评论