high perfermance computer usage

简单记一下hpc的使用:

hpc就是一些科研机构或者大学建立的服务器中心。我这大学的每一位学生,可以轻松使用hpc批量跑数据,也可以新建自己的server跑一些local data,后者每个学生账号最大是32核512G的运行内存,体验非常好,只不过只能使用jupyternote book或者R登录,也可以跑bash,总之非常nice。

新建自己的server跑jupyternote book就比较容易,例如:

bash 复制代码
from concurrent.futures import ProcessPoolExecutor
from tqdm import tqdm
# python
def my_func(x):
    return x**2
def run(f, this_iter):
    with ProcessPoolExecutor(max_wokers=32) a executor:
        results = list(tqdm(executor.map(f. this_iter), total=len(this_iter))
    return results
if name == '__main__':
    this_iter = [1,2,3,4,4,5,6]
    results = run(my_func, this_iter)

# ipynb
from multiprocessing import Pool
from tqdm import tqdm
def my_func(x):
    return x**2
def run(f, this_iter):
    with Pool(max_wokers=32) a p:
        results = list(tqdm(p.imap(f. this_iter), total=len(this_iter))
    return results
if name == '__main__':
    this_iter = [1,2,3,4,4,5,6]
    results = run(my_func, this_iter)

两者区别就在于使用ProcessPoolExecutor 还是 Pool,还有map 和imap。其他都是一样的使用。

完全免费的32核512G云服务器,还可以加载2080Ti等显卡,我觉得这个科研资源算是非常好了,至少节省了自己2万左右资金。

第二个就是hpc节点的使用

hpc的集群节点主要是用来批量跑数据预处理,我主要是跑fmriprep和xcp-d。

首先是定义变量:

bash 复制代码
#!/bin/bash

#$ -N sub-${subject}_fmriprep
#$ -pe smp 10
#$ -q UI
#$ -j y
#$ -o /Data/test/logs
#$ -t 1-29:1

这些是hpc的定义,例如-o表示output,-pe表示需求的核心数,-q是请求的节点端口等等。

然后可以自己自定义一些环境变量:

bash 复制代码
singularityDir=/Data/test
export TEMPLATEFLOW_HOME=${singularityDir}/TemplateFlow
export SINGULARITYENV_TEMPLATEFLOW_HOME=/templateflow

然后就可以使用fmriprep的脚本:

bash 复制代码
singularity run --cleanenv \
-B /Users/work:/work \
-B ${TEMPLATEFLOW_HOME:-$HOME/.cache/templateflow}:/templateflow \
${singularityDir}/fmriprep.sif \
/Data/test/BIDS/ /Data/test/fmriprep/ participant --participant-label ${subject} \
--skip_bids_validation \
--nprocs 8 --omp-nthreads 8 --mem 32000 \
-t rest \
-w work \
........
......

然后保存脚本,在服务器端口敲命令: qsub fmriprep_run.sh 即可。

可以用 qstat | grep ID 查看提交的作业是否正常在运行。

等运行结束以后,可以使用qacct -j {job_id} 查看fmriprep的运行过程。

以我这个为例,我的test脚本调用了8个核跑了一个被试,运行细节如下:

一个rest-state bold输出到2个空间,做体空间和皮层空间,cpu时间是84831s,最大内存是5.8G,运行时间是8小时30分钟。

一般来说,fmriprep只有几个步骤能跑满cpu,比如ants,还有一些步骤是跑不满的,所以假设同样8个被试,使用8个核心,一个一个跑,跟使用1个核心,8个一起跑,后者的时间应该是要短很多。

一种方法是,使用python脚本,建立Pool池,调用多个kernel,然后每个kernel去跑一个singularity。

bash 复制代码
## multiple subjects
#!/bin/bash
#$ -N sub-batchArray_fmriprep
#$ -pe smp 10
#$ -q PINC, CCOM, UI
#$ -j y
#$ -o /data/logs
#$ -t 1-27:1
OMP_NUM_THREADS=30
subject='cat /data/test/sublist | head -n+${SGE_TASK_ID} | tail -n-1'

singularityDir=/data/test
...
...
相关推荐
可观测性用观测云40 分钟前
Cloudflare 日志采集和分析最佳实践
数据分析
真智AI2 小时前
AI智能体时代来临:数据分析的变革与自动化之路
人工智能·数据分析·自动化
程序员阿超的博客3 小时前
Python 数据分析与机器学习入门 (五):Matplotlib 数据可视化基础
python·信息可视化·数据分析·matplotlib·数据可视化·python教程·pyplot
蓝婷儿9 小时前
Python 数据分析与可视化 Day 14 - 建模复盘 + 多模型评估对比(逻辑回归 vs 决策树)
python·数据分析·逻辑回归
好开心啊没烦恼10 小时前
Python:线性代数,向量内积谐音记忆。
开发语言·python·线性代数·数据挖掘·数据分析
过期的秋刀鱼!10 小时前
用“做饭”理解数据分析流程(Excel三件套实战)
数据挖掘·数据分析·excel·powerbi·数据分析入门
大数据CLUB13 小时前
基于spark的航班价格分析预测及可视化
大数据·hadoop·分布式·数据分析·spark·数据可视化
程序员阿超的博客14 小时前
Python 数据分析与机器学习入门 (八):用 Scikit-Learn 跑通第一个机器学习模型
python·机器学习·数据分析·scikit-learn·入门教程·python教程
蓝婷儿10 天前
Python 数据分析与可视化 Day 2 - 数据清洗基础
开发语言·python·数据分析
蓝婷儿10 天前
Python 数据分析与可视化 Day 5 - 数据可视化入门(Matplotlib & Seaborn)
python·信息可视化·数据分析