From b70c7b4652ed07d72425fa859450667a41b6de2b Mon Sep 17 00:00:00 2001 From: bowling233 Date: Wed, 3 Apr 2024 14:37:23 +0800 Subject: [PATCH] update --- docs/javascripts/mathjax.js | 11 +- .../d2l.md" | 85 +++++++++ .../index.md" | 39 ++++ .../pytorch.md" | 0 ...36\347\273\217\347\275\221\347\273\234.md" | 0 .../\350\215\211\347\250\277.md" | 25 +++ ...66\345\222\214\346\216\245\345\217\243.md" | 2 +- .../lec4.md" | 31 ++++ .../lec5.md" | 19 ++ .../lec6.md" | 5 + .../temp.md" | 4 + .../\346\240\221\344\270\216\345\240\206.md" | 147 ++++++++++++++-- ...27\346\234\272\347\273\204\346\210\220.md" | 36 ++++ .../C++.md" | 89 +++++++++- .../MPI/index.md" | 22 +-- .../MPI/oneapi.md" | 29 --- .../MPI/openmpi.md" | 39 ---- .../MPI/optimization.md" | 49 ++++++ .../MPI/profiling.md" | 1 + .../MPI/usage.md" | 166 ++++++++++++++++++ .../Profiler/POP.md" | 28 +++ .../Profiler/oneapi_profilers.md" | 0 .../index.md" | 25 +++ .../\350\277\220\347\273\264/hardware.md" | 1 + .../hardware_port.md" | 13 -- .../\350\277\220\347\273\264/index.md" | 5 +- .../system_config.md" | 4 +- .../\350\215\211\347\250\277.md" | 166 ++++++++++++++++++ mkdocs.yml | 9 +- requirements.txt | 2 +- 30 files changed, 926 insertions(+), 126 deletions(-) create mode 100644 "docs/\344\272\272\345\267\245\346\231\272\350\203\275/d2l.md" create mode 100644 "docs/\344\272\272\345\267\245\346\231\272\350\203\275/index.md" rename "docs/\344\272\272\345\267\245\346\231\272\350\203\275\344\270\216\346\234\272\345\231\250\345\255\246\344\271\240/pytorch.md" => "docs/\344\272\272\345\267\245\346\231\272\350\203\275/pytorch.md" (100%) rename "docs/\344\272\272\345\267\245\346\231\272\350\203\275\344\270\216\346\234\272\345\231\250\345\255\246\344\271\240/\347\245\236\347\273\217\347\275\221\347\273\234.md" => "docs/\344\272\272\345\267\245\346\231\272\350\203\275/\347\245\236\347\273\217\347\275\221\347\273\234.md" (100%) create mode 100644 "docs/\347\247\221\347\240\224/\350\215\211\347\250\277.md" create mode 100644 "docs/\350\215\211\347\250\277/\351\207\217\345\255\220\344\277\241\346\201\257\345\237\272\347\241\200/lec4.md" create mode 100644 "docs/\350\215\211\347\250\277/\351\207\217\345\255\220\344\277\241\346\201\257\345\237\272\347\241\200/lec5.md" create mode 100644 "docs/\350\215\211\347\250\277/\351\207\217\345\255\220\344\277\241\346\201\257\345\237\272\347\241\200/lec6.md" create mode 100644 "docs/\350\215\211\347\250\277/\351\253\230\347\272\247\346\225\260\346\215\256\347\273\223\346\236\204/temp.md" rename "docs/\350\215\211\347\250\277/\351\253\230\347\272\247\346\225\260\346\215\256\347\273\223\346\236\204/\346\240\221.md" => "docs/\350\215\211\347\250\277/\351\253\230\347\272\247\346\225\260\346\215\256\347\273\223\346\236\204/\346\240\221\344\270\216\345\240\206.md" (76%) create mode 100644 "docs/\350\257\276\347\250\213\347\254\224\350\256\260/\350\256\241\347\256\227\346\234\272\347\273\204\346\210\220.md" delete mode 100644 "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/oneapi.md" delete mode 100644 "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/openmpi.md" create mode 100644 "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/optimization.md" create mode 100644 "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/profiling.md" create mode 100644 "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/usage.md" create mode 100644 "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/Profiler/POP.md" rename "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/oneapi_profilers.md" => "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/Profiler/oneapi_profilers.md" (100%) create mode 100644 "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/hardware.md" rename "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/basic_config.md" => "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/system_config.md" (92%) create mode 100644 "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\347\274\226\350\257\221\347\263\273\347\273\237/\350\215\211\347\250\277.md" diff --git a/docs/javascripts/mathjax.js b/docs/javascripts/mathjax.js index 5613f46e..3b95e959 100644 --- a/docs/javascripts/mathjax.js +++ b/docs/javascripts/mathjax.js @@ -1,10 +1,11 @@ window.MathJax = { loader: { load: ["[tex]/physics"] }, tex: { + packages: { "[+]": ["physics"] }, inlineMath: [["\\(", "\\)"]], displayMath: [["\\[", "\\]"]], processEscapes: true, - processEnvironments: true + processEnvironments: true, }, options: { ignoreHtmlClass: ".*|", @@ -13,8 +14,8 @@ window.MathJax = { }; document$.subscribe(() => { - MathJax.startup.output.clearCache(); - MathJax.typesetClear(); - MathJax.texReset(); - MathJax.typesetPromise(); + MathJax.startup.output.clearCache(); + MathJax.typesetClear(); + MathJax.texReset(); + MathJax.typesetPromise(); }); diff --git "a/docs/\344\272\272\345\267\245\346\231\272\350\203\275/d2l.md" "b/docs/\344\272\272\345\267\245\346\231\272\350\203\275/d2l.md" new file mode 100644 index 00000000..6968e196 --- /dev/null +++ "b/docs/\344\272\272\345\267\245\346\231\272\350\203\275/d2l.md" @@ -0,0 +1,85 @@ +# Dive into deep learning + +## 0. Installation + +- Python 3.12 安装 NumPy 有 Bug,降级到 3.11。 + +## 1. Intro + +- 机器学习是从经验中学习的算法。 + +需要明白以下概念的含义: + +- 监督、无监督、自监督、强化学习 +- 监督学习所解决的:回归、分类、标注、搜索、推荐、序列学习问题 + +本章还介绍了最新的人工智能发展趋势,如深度学习、自然语言处理、计算机视觉、强化学习、生成对抗网络等。 + +!!! note "交叉:计算机体系结构" + + 本章也对人工智能和计算机计算能力的发展进行了比较。值得注意的是,RAM 的增长速度落后于数据集和计算能力的增长速度,因此现在的统计模型应当更加内存高效,也就是在访存期间做更多计算。作者提到,这也是多层感知机、CNN 等模型在上个世纪就已经被提出,但进来才得以广泛应用的原因之一。 + +## 2. Preliminaries + +### Data Manipulation + +!!! note "`tensor`" + + 创建 + + ```python + torch.arange(12, dtype=torch.float32) + torch.zeros((2, 3, 4)) + torch.ones((2, 3, 4)) + torch.randn(3, 4) + torch.tensor([[2, 1, 4, 3], [1, 2, 3, 4], [4, 3, 2, 1]]) + ``` + + 属性: + + ```python + x.shape + ``` + + 方法: + + ```python + x.reshape(3, 4) + x.reshape(-1, 4) # auto infer + ``` + + 操作: + + ```python + # 一元、二元运算都是 element-wise 的。 + torch.exp(x) + x + y, x - y, x * y, x / y, x ** y + x == y, x < y, x > y + # 其他 + torch.cat((x, y), dim=0) + x.sum() + ``` + + 广播: + + - 对于长度为 1 的维度,拷贝使得两个张量的维度相同。 + - 执行 element-wise 运算。 + + +!!! note "其他" + + ```python + id() + ``` + +## 3. Linear Neural Networks + +### Data Preprocessing + +### Linear Algebra + +### Calculus + +### Automatic Differentiation + +### Probability and Statistics diff --git "a/docs/\344\272\272\345\267\245\346\231\272\350\203\275/index.md" "b/docs/\344\272\272\345\267\245\346\231\272\350\203\275/index.md" new file mode 100644 index 00000000..83de3aa0 --- /dev/null +++ "b/docs/\344\272\272\345\267\245\346\231\272\350\203\275/index.md" @@ -0,0 +1,39 @@ +# 人工智能综述 + +[AI Expert Roadmap](https://github.com/AMAI-GmbH/AI-Expert-Roadmap) + +在具体地进入人工智能的学习前,我们先来看看人工智能的发展历程,这对了解人工智能的发展脉络和其中的一些重要概念有很大帮助。 + +!!! note "知识库方法 Knowledge Base" + + 将关于世界的知识用形式化的语言进行硬编码。计算机使用逻辑推理规则来自动理解这些形式化语言中的声明。 + +人工智能早期解决对人类智力来说非常困难,但对计算机来说相对简单的问题,比如抽象和形式化的任务。例子有:IBM 的深蓝国际象棋系统。 + +知识库方法遇到了困难,因为难以设计出足够复杂的形式化规则来精确地描述世界。最著名的知识库项目 Cyc 不能理解人在早上剃胡须:它知道人体的构成不含有电器零件,但由于人拿着剃须刀,它认为实体含有电器部件。因此它产生疑问:人在刮胡子时是否仍是一个人? + +!!! note "机器学习 Machine Learning" + + 系统具备自己获取知识的能力,能够从原始数据中提取模式。 + + 主要使用数理统计方法。 + +由人从数据中提取特征,将数据处理成结构化的形式,然后让机器学习算法从中提取模式。 + +但是,有很多任务我们很难知道如何提取特征。比如检测照片中的车,使用轮子作为特征吗?但图像可能因场景而异,轮子可能被遮挡,或者车可能是在水中。 + +!!! note "表示学习 Representation Learning" + + 用机器学习来发掘表示本身,学习到的表示往往比手动设计的好。 + + !!! note "自编码器 Autoencoder" + + 由编码器函数和解码器函数组成,编码器将输入数据映射到表示空间,解码器将表示空间映射回原始数据空间。期望是输入数据经过编解码器后尽可能多地保留信息,同时希望新的表示有各种好的特性。 + +!!! note "深度学习 Deep Learning" + + 一种机器学习技术,它使用神经网络来学习数据的表示形式。 + + !!! note "前馈深度网络/多层感知机 Multilayer Perceptron" + + 一种最简单的神经网络,由多个神经元组成的多层结构。 diff --git "a/docs/\344\272\272\345\267\245\346\231\272\350\203\275\344\270\216\346\234\272\345\231\250\345\255\246\344\271\240/pytorch.md" "b/docs/\344\272\272\345\267\245\346\231\272\350\203\275/pytorch.md" similarity index 100% rename from "docs/\344\272\272\345\267\245\346\231\272\350\203\275\344\270\216\346\234\272\345\231\250\345\255\246\344\271\240/pytorch.md" rename to "docs/\344\272\272\345\267\245\346\231\272\350\203\275/pytorch.md" diff --git "a/docs/\344\272\272\345\267\245\346\231\272\350\203\275\344\270\216\346\234\272\345\231\250\345\255\246\344\271\240/\347\245\236\347\273\217\347\275\221\347\273\234.md" "b/docs/\344\272\272\345\267\245\346\231\272\350\203\275/\347\245\236\347\273\217\347\275\221\347\273\234.md" similarity index 100% rename from "docs/\344\272\272\345\267\245\346\231\272\350\203\275\344\270\216\346\234\272\345\231\250\345\255\246\344\271\240/\347\245\236\347\273\217\347\275\221\347\273\234.md" rename to "docs/\344\272\272\345\267\245\346\231\272\350\203\275/\347\245\236\347\273\217\347\275\221\347\273\234.md" diff --git "a/docs/\347\247\221\347\240\224/\350\215\211\347\250\277.md" "b/docs/\347\247\221\347\240\224/\350\215\211\347\250\277.md" new file mode 100644 index 00000000..095e9b98 --- /dev/null +++ "b/docs/\347\247\221\347\240\224/\350\215\211\347\250\277.md" @@ -0,0 +1,25 @@ +# 草稿 + +## 文献综述 + +!!! info "[东南大学图书馆:如何写好文献综述](http://www.lib.seu.edu.cn/upload_files/file/20220523/_20220523153114.pdf)" + +### 内容 + +文献综述的内容一般包括该研究领域的: + +- **研究现状**:包括主要学术观点、前人研究成果和研究水平、争论焦点、存在的问题及可能的原因等。 +- **发展趋势**:新水平、新动态、新技术、新发现、发展前景等。 + +文献综述需要对以上内容进行**行综合分析、归纳整理和评论**,并提出**自己的见解和研究思路**。 + +文献综述的目的是帮助读者确认该论文所研究的问题**与以往同类或同领域论文相比较所具有的价值**及在选题或研究内容与方法上**是否具有创新性或新的进展**。 + +### 结构 + +按时间顺序、研究主题、研究方法、学术流派等。 + +- 时间顺序:最早研究该主题的文献是什么?这个研究领域随着时间的推移是如何变化的(以及为什么)?最新的发现是什么? +- 研究主题:研究人员使用的中心主题和类别是什么?有哪些证据来证明这些主题? +- 研究方法:哪些方法在这个领域已经被利用?哪种方法是最受欢迎的(以及为什么)?各种方法的优缺点是什么?现有方法如何为我的研究提供参考? +- 学术流派:已有研究的主要学术流派和观点是什么?观点之间存在怎样的逻辑关系? diff --git "a/docs/\350\215\211\347\250\277/\347\241\254\344\273\266\345\222\214\346\216\245\345\217\243.md" "b/docs/\350\215\211\347\250\277/\347\241\254\344\273\266\345\222\214\346\216\245\345\217\243.md" index be2925a1..b6536eff 100644 --- "a/docs/\350\215\211\347\250\277/\347\241\254\344\273\266\345\222\214\346\216\245\345\217\243.md" +++ "b/docs/\350\215\211\347\250\277/\347\241\254\344\273\266\345\222\214\346\216\245\345\217\243.md" @@ -2,5 +2,5 @@ ## VGA -- 8x16 ASCII 字体数据是这样存放的:![digital_logic_vga_font_data](.\digital_logic_vga_font_data.png) +- 8x16 ASCII 字体数据是这样存放的:![digital_logic_vga_font_data](digital_logic_vga_font_data.png) - 更多字体显示:[MultiFont](https://newhavendisplay.com/content/app_notes/MultiFont.pdf) \ No newline at end of file diff --git "a/docs/\350\215\211\347\250\277/\351\207\217\345\255\220\344\277\241\346\201\257\345\237\272\347\241\200/lec4.md" "b/docs/\350\215\211\347\250\277/\351\207\217\345\255\220\344\277\241\346\201\257\345\237\272\347\241\200/lec4.md" new file mode 100644 index 00000000..4e06d565 --- /dev/null +++ "b/docs/\350\215\211\347\250\277/\351\207\217\345\255\220\344\277\241\346\201\257\345\237\272\347\241\200/lec4.md" @@ -0,0 +1,31 @@ +# 多量子比特和量子纠缠 + +## 张量积 + +## 纠缠态和 EPR 佯谬 + +## Bell 态中的信息 + +- PPT:信息分布在两个量子比特之间(not local),任意单个量子比特不提供任何信息。 + +要理解上面这一描述,课上采用计算期望值 $\braket{L}$ 的方法。 + +1. $L$ 的特征值 $\lambda$,特征向量 $\ket{\lambda}$ +2. 把量子态分解到特征向量上 $\ket{\psi} = \sum_\lambda \ket{\lambda}\braket{\lambda|\psi}$,再应用 $L$ +3. 再测量,得到期待值 $\braket{L} = \sum_\lambda \lambda \mathrm{P}(\lambda)$ + +!!! note "牢记:$\mathrm{P}(\lambda) = \braket{\psi|\lambda}\braket{\lambda|\psi}$" + +本质上就是带权(概率)的特征值求和。 + +测量 Bell 态 $\ket{\psi} = \frac1{\sqrt{2}}(\ket{01}+\ket{10})$ 的第一个比特,我们对第一个比特应用由泡利矩阵生成的任意酉矩阵: + +$$ +(\vec{\sigma}^{(1)} \cdot \vec{n}) \otimes I +$$ + +计算它的期望值: + + + +## 密度矩阵 diff --git "a/docs/\350\215\211\347\250\277/\351\207\217\345\255\220\344\277\241\346\201\257\345\237\272\347\241\200/lec5.md" "b/docs/\350\215\211\347\250\277/\351\207\217\345\255\220\344\277\241\346\201\257\345\237\272\347\241\200/lec5.md" new file mode 100644 index 00000000..1d268635 --- /dev/null +++ "b/docs/\350\215\211\347\250\277/\351\207\217\345\255\220\344\277\241\346\201\257\345\237\272\347\241\200/lec5.md" @@ -0,0 +1,19 @@ +# 量子系统随时间的演化 + +本节课在线性代数上加强了难度。让我们再次复习相关概念。 + +???+ note "Hermitian Operators" + + 定义: + + - 自伴(共轭转置等于本身):$A^\dagger = A$。 + - 伴随矩阵 $A^\dagger$ 定义为:$\braket{A^\dagger|g}= \braket{f|Ag}$。 + + 性质: + + - 本征值都是实数。 + - 位置、动量和能量等物理量是实数,因为它们都是 Hermitian 算子的本征值。 + - 因此期待值也是实数。 + - 结合内积的共轭对称性质,可以得到:$\braket{A} = \braket{\psi|A\psi} = \braket{A\psi|\psi} = \braket{\psi|A\psi}^* = \braket{A}^*$。 + - 本征向量正交。 + diff --git "a/docs/\350\215\211\347\250\277/\351\207\217\345\255\220\344\277\241\346\201\257\345\237\272\347\241\200/lec6.md" "b/docs/\350\215\211\347\250\277/\351\207\217\345\255\220\344\277\241\346\201\257\345\237\272\347\241\200/lec6.md" new file mode 100644 index 00000000..08560b1a --- /dev/null +++ "b/docs/\350\215\211\347\250\277/\351\207\217\345\255\220\344\277\241\346\201\257\345\237\272\347\241\200/lec6.md" @@ -0,0 +1,5 @@ +# 量子电路 + +!!! note "不可克隆定理" + + 无法完美复制一个未知的量子态。 \ No newline at end of file diff --git "a/docs/\350\215\211\347\250\277/\351\253\230\347\272\247\346\225\260\346\215\256\347\273\223\346\236\204/temp.md" "b/docs/\350\215\211\347\250\277/\351\253\230\347\272\247\346\225\260\346\215\256\347\273\223\346\236\204/temp.md" new file mode 100644 index 00000000..ffb16d29 --- /dev/null +++ "b/docs/\350\215\211\347\250\277/\351\253\230\347\272\247\346\225\260\346\215\256\347\273\223\346\236\204/temp.md" @@ -0,0 +1,4 @@ +# temp + +## 倒排索引 Inverted Index + diff --git "a/docs/\350\215\211\347\250\277/\351\253\230\347\272\247\346\225\260\346\215\256\347\273\223\346\236\204/\346\240\221.md" "b/docs/\350\215\211\347\250\277/\351\253\230\347\272\247\346\225\260\346\215\256\347\273\223\346\236\204/\346\240\221\344\270\216\345\240\206.md" similarity index 76% rename from "docs/\350\215\211\347\250\277/\351\253\230\347\272\247\346\225\260\346\215\256\347\273\223\346\236\204/\346\240\221.md" rename to "docs/\350\215\211\347\250\277/\351\253\230\347\272\247\346\225\260\346\215\256\347\273\223\346\236\204/\346\240\221\344\270\216\345\240\206.md" index 71972ff2..a000480c 100644 --- "a/docs/\350\215\211\347\250\277/\351\253\230\347\272\247\346\225\260\346\215\256\347\273\223\346\236\204/\346\240\221.md" +++ "b/docs/\350\215\211\347\250\277/\351\253\230\347\272\247\346\225\260\346\215\256\347\273\223\346\236\204/\346\240\221\344\270\216\345\240\206.md" @@ -1,4 +1,4 @@ -# 树 +# 树与堆 Tree and Heap 该部分的内容围绕二叉搜索树及其优化展开。 @@ -8,7 +8,21 @@ - 操作:树形结构的操作是相似的,最重要的三个是查找、插入、删除。为了实现这些操作,具体的结构会有一些辅助操作。很多操作是递归的,想清楚终止情况和递归条件。 - 结构:加上平衡条件后,这些树展现出不同的结构,也对它们的操作复杂度产生影响。 -## 二叉搜索树 +!!! note "复杂度总结" + + 堆: + + | 操作 | 二叉堆 | 左式堆 | 斜堆 | 二项队列 | 斐波那契堆 | + | --- | --- | --- | --- | --- | --- | + | `Insert` | $O(\log N)$ | $O(\log N)$ | $O(\log N)$ | $O(1)$ | $O(1)$ | + | `Merge` | $O(N)$ | $O(\log N)$ | $O(\log N)$ | $O(\log N)$ | $O(1)$ | + | `DeleteMin` | $O(\log N)$ | $O(\log N)$ | $O(\log N)$ | $O(\log N)$ | $O(\log N)$ | + | `Delete` | $O(\log N)$ | $O(\log N)$ | | $O(\log N)$ | $O(\log N)$ | + | `DecreaseKey` | $O(\log N)$ | $O(\log N)$ | | $O(\log N)$ | $O(1)$ | + + 树: + +## 二叉搜索树 Binary Search Tree === "成员" @@ -42,7 +56,7 @@ - 平均深度为 $O(\log N)$。这里的平均指的是对所有可能的插入序列而言。 - 删除算法偏好某一侧节点,容易使另一侧树相比之下更深。 -## AVL 树 +## AVL 树 AVL Tree === "成员" @@ -97,7 +111,7 @@ 对上面高度与节点数的关系求解,容易得到 AVL 树的最大高度为 $1.44\log(N+2) - 1.328$,一般情况下只比 $\log N$ 高一些。 -## 伸展树 +## 伸展树 Splay Tree === "成员" @@ -131,7 +145,7 @@ 使用势函数法。==todo== -## 红黑树 +## 红黑树 Red-Black Tree === "成员" @@ -330,6 +344,18 @@ B 树一般用于 DBMS 等大量数据的存储,性能指标一般是对磁盘 如果允许自由实现,可以使用哨兵,并允许键值在内部节点重复出现。这样可以将 `key` 和 `child` 合并为 `map`,简化操作。 +=== "结构" + + B+ 树中,所有数据都在叶子节点上,非叶子节点只存储索引。这样的设计使得 B+ 树既方便索引又方便遍历。 + + 定义 $M$ 为 B+ 树的 order。 + + - 根节点:$2\sim M$ 个孩子,即 $1\sim M-1$ 个 Key + - 非叶子节点:$\lceil M/2 \rceil \sim M$ 个孩子,即 $\lceil M/2 \rceil - 1 \sim M-1$ 个 Key + - (非根)叶子节点:$\lceil M/2 \rceil \sim M$ 个孩子,也是 Key + + 设一个内部节点有 $N$ 个孩子,那么它有 $N-1$ 个 Key,是除第一个子树外的其他子树的最小值。注意这里是子树而不是孩子。 + === "操作" - Find @@ -346,19 +372,107 @@ B 树一般用于 DBMS 等大量数据的存储,性能指标一般是对磁盘 - 分裂叶子节点时,作为索引的值**复制**到父节点中 - 分裂内部节点时,作为索引的值**上移**到父节点中 -=== "结构" +## 二叉堆 Binary Heap - B+ 树中,所有数据都在叶子节点上,非叶子节点只存储索引。这样的设计使得 B+ 树既方便索引又方便遍历。 +二叉堆是完全二叉树。它有两个性质: - 定义 $M$ 为 B+ 树的 order。 +- 结构性质:完全二叉树 +- 堆序性质:任意节点的关键字不大于(或不小于)其孩子节点的关键字 - - 根节点:$2\sim M$ 个孩子,即 $1\sim M-1$ 个 Key - - 非叶子节点:$\lceil M/2 \rceil \sim M$ 个孩子,即 $\lceil M/2 \rceil - 1 \sim M-1$ 个 Key - - (非根)叶子节点:$\lceil M/2 \rceil \sim M$ 个孩子,也是 Key +==todo== - 设一个内部节点有 $N$ 个孩子,那么它有 $N-1$ 个 Key,是除第一个子树外的其他子树的最小值。注意这里是子树而不是孩子。 +## 左式树/堆 Leftist Tree/Heap + +!!! info "[Youtube 讲解视频](https://www.youtube.com/watch?v=dgMuWmm-aVA)" + +??? note "回顾:二叉堆合并" + + 合并二叉堆: + + - 拷贝所有元素 + - 构建堆:插入或线性时间建堆(Heapify) -## 二叉堆 + 复杂度为 $O(N\log N)$ 或 $O(N)$。 + +??? note "概念:S 值/零路径长(Null Path Length)" + + 和红黑树中一样,我们把空指针视为外部节点。 + + S 值:从一个节点到外部节点的最短路径长度。 + + - $S(null) = 0$ + - $S(x) = 1 + \min(S(x.left), S(x.right))$ + +??? note "左式树/堆的性质" + + $S(x.left) \geq S(x.right)$ + + 结合 $S(x) = 1 + \min(S(x.left), S(x.right))$ 可以马上知道,S 值是通向最右侧外部节点的路径长度。 + + 从该性质,利用数学归纳法,可以得到: + + - 以 $x$ 为根的子树至少有 $2^{S(x)}-1$ 个节点 + - 以 $x$ 为根的子树 $S(x) \leq \log(N+1)$ + + 满足堆序性质的左式树就是左式堆。显然:左式堆不需要是完全二叉树。 + +??? note "左式堆:合并" + + 1. 前向步骤:比较两个根节点,取出较小根节点的右孩子和另一个堆合并,直到有一个待合并的堆为空。 + 2. 反向步骤:用合并结果替换掉较小根节点的右孩子。如果会违背左式树的性质,交换左右孩子。 + + 复杂度分析:每次合并操作都是 $O(1)$,持续向右进行。向右最长路径为 S 值,因此合并操作的复杂度为 $O(\log N)$。 + +## 二项队列 Binomial Queue + +二项队列是二项树组成的森林,每个树是堆有序的。 + +与上面的堆相比,二项堆能够实现摊还常数时间的**插入建堆**操作。 + +=== "成员" + + - BinNode + - Key + - Left + - Right + - BinQueue + - Size:节点总数 + - Trees:指向树根的指针数组 + +=== "结构" + + 高度: + + - 单节点树 $B_0$ 高度为 $0$。 + - 高度 $k$ 的树 $B_k$ 由两个高度 $k-1$ 的树 $B_{k-1}$ 合并而来,合并的方式是把一个树连到另一个树的根部。 + - 每次高度增加都会往根部连一个相同的树的根,因此高度为 $k$ 的树根 $B_k$ 有 $k$ 个孩子,这些孩子分别是 $B_0, B_1, \cdots, B_{k-1}$。 + - 递归很容易得到高度为 $k$ 的树 $B_k$ 有 $2^k$ 个节点。 + - 第 $d$ 层的节点数为 $\binom{k}{d}$,这同样可以根据归纳法和组合数的性质 $C_k^i + C_k^{i-1} = C_{k+1}^i$ 得到。 + +=== "操作" + + - 辅助: + - CombineTrees:合并两棵树 + - FindMin: + - 最小的节点一定在根部。 + - 森林中最多有 $\lceil \log N \rceil$ 棵树。 + - 复杂度为 $O(\log N)$。 + - Merge: + - 类似数字逻辑电路中的进位加法器。 + - 合并高度相同的两棵树时,必须保证堆序性质,即将较大树的根作为较小树的孩子。 + - 根据所合并两个队列当前高度上的树和进位的树,分 $2^3=8$ 种情况讨论。 + - Insert: + - 合并一个只有一个节点的树和原队列。 + - DeleteMin: + - 找到最小根所在的树,移出森林。 + - 删除它,它的孩子们组成一个新的森林。 + - 合并这个森林和原森林。 + +!!! note "将任意大小的优先队列表示为二项队列" + + 把队列大小表示为二进制,为 $1$ 的位对应一个二项树。这样的表示方法是唯一的。 + +## 斐波那契堆 Fibonacci Heap ## 树的遍历 @@ -403,3 +517,10 @@ std::ostream &operator<<(std::ostream &os, BinaryTree &tree){ 如果要求按行输出树的每一层,需要怎么做呢? ## 左孩子右兄弟表示法 + +## 其他 + +- ART 树:这是我在《高级数据结构与算法》课程作业中实践的数据结构,来自高效全文本搜索引擎 TypeSense。具体内容请查阅论文。 + - 与各类二叉搜索树相比,它能极大地节省空间 + - 它针对体系结构做了优化,精巧设计节点,在主存上表现很好 + - 访问速度趋近哈希表,同时还支持模糊搜索和范围查找 diff --git "a/docs/\350\257\276\347\250\213\347\254\224\350\256\260/\350\256\241\347\256\227\346\234\272\347\273\204\346\210\220.md" "b/docs/\350\257\276\347\250\213\347\254\224\350\256\260/\350\256\241\347\256\227\346\234\272\347\273\204\346\210\220.md" new file mode 100644 index 00000000..3ac51f58 --- /dev/null +++ "b/docs/\350\257\276\347\250\213\347\254\224\350\256\260/\350\256\241\347\256\227\346\234\272\347\273\204\346\210\220.md" @@ -0,0 +1,36 @@ +# 计算机组成 + +## 杂项知识 + +??? note "Amdahl 定律" + +??? note "思想" + + 摩尔定律、抽象、普遍情况、并行、流水线、预测、存储器层次、冗余 + +??? note "指令速度计算" + +## 算术 + +??? note "乘法器" + +??? note "除法器" + +??? note "浮点数" + +??? note "浮点加法器" + +## 汇编 + +??? note "RISC-V 指令及格式" + +??? note "寄存器标识" + + 除了 `x0-x31`,还会用其他标识标记寄存器的用途,常见的有: + + - `a0-a7`(`x10-x17`):函数参数 + - `ra`(`x1`):返回地址 + - `sp`(`x2`):栈指针 + - `t0-t6`(`x5-x11`):临时寄存器,被调不保存 + - `s0-s11`(`x8-x18`):保存寄存器,如果使用了则需要保存 + - \ No newline at end of file diff --git "a/docs/\350\275\257\344\273\266/\347\250\213\345\272\217\350\256\276\350\256\241\350\257\255\350\250\200/C++.md" "b/docs/\350\275\257\344\273\266/\347\250\213\345\272\217\350\256\276\350\256\241\350\257\255\350\250\200/C++.md" index 3099ed10..b47d33c4 100644 --- "a/docs/\350\275\257\344\273\266/\347\250\213\345\272\217\350\256\276\350\256\241\350\257\255\350\250\200/C++.md" +++ "b/docs/\350\275\257\344\273\266/\347\250\213\345\272\217\350\256\276\350\256\241\350\257\255\350\250\200/C++.md" @@ -1023,7 +1023,7 @@ r = ac2->rate(); // through a pointer to an Account object They are not initialized by the class’ constructors. We may not initialize a `static` member inside the class. We must define and initialize each `static` data member **outside the class body**. -```cpp +```cpp double Account::interestRate = initRate(); ``` @@ -1551,7 +1551,7 @@ Two primary types: - `map` key-value pairs (array) - `set` keys -Eight associative containers: +Eight associative containers: - `map` or `set` - unique or `multi` @@ -1768,6 +1768,38 @@ Two operators: `new`, `delete`. ### Chapter 13 Copy Control +Five special member functions: copy +constructor, copy-assignment operator, move constructor, move-assignment op- +erator, and destructor. + +- copy and move constructor: initialize new object from another object of the same type +- copy and move assignment: assign an object of a class type to another object of that same class type + +#### Copy Constructor + +its first parameter is a reference to the class type and any additional parameters have default values. + +```cpp +Foo(const Foo&); +``` + +#### Copy initialization + +```cpp +string dots(10, ’.’); // direct initialization +string s(dots); // direct initialization +string s2 = dots; // copy initialization +string null_book = "9-999-99999-9"; // copy initialization +string nines = string(100, ’9’); // copy initialization +``` + +When copy initialization happens and that copy initialization requires either the copy constructor **or the move constructor**. + +- Pass an object as an argument +- Return +- Brace initialize +- library containers allocate objects + ### Chapter 14 Overloaded Operations and Conversions ### Chapter 15 Object-Oriented Programming @@ -1780,8 +1812,59 @@ Two operators: `new`, `delete`. ### Chapter 18 Tools for Large Programs -### Chapter 19 Specialized Tools and Techniques +#### Exception Handling + +- `throw` expression +- `try` block +- `catch` clause +- `exception` class + - `what` member function: return C-style string +!!! note "Functions Are Exited during the Search for a Handler" + + If no appropriate catch is found, execution is transferred to a library function named `terminate`. The behavior of that function is system dependent but is guaranteed to stop further execution of the program. + +!!! note "Standard Exception Classes" + + Default initialization: + + - `exception` + - `bad_alloc` + - `bad_cast` + - `bad_typeid` + - `bad_exception` + + Cannot be default initialized: + + - `runtime_error` + - `range_error` + - `overflow_error` + - `underflow_error` + - `logic_error` + - `domain_error` + - `invalid_argument` + - `length_error` + - `out_of_range` + +!!! note "Stack Unwind" + + Because destructors may be invoked during stack unwinding, they should **never throw exceptions that the destructor itself does not handle**. + + All of the standard library types guarantee that their destructors will not raise an exception. + +!!! note "Function `try` Blocks and Constructors" + + An exception might occur while processing a constructor initializer. + + ```cpp + template + Blob::Blob(std::initializer_list il) try : + data(std::make_shared>(il)) { + /*empty body*/ + } catch(const std::bad_alloc &e) { handle_out_of_memory(e); } + ``` + +### Chapter 19 Specialized Tools and Techniques ### 零碎技巧 diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/index.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/index.md" index 0e879454..e11f18d2 100644 --- "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/index.md" +++ "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/index.md" @@ -1,16 +1,10 @@ # MPI -MPI 知识主要分两块内容:MPI 编程技术和各类 MPI 实现的使用方法。 - -- [MPI 标准研读](standard.md) - -对于每个实现,需要了解安装(编译、处理依赖)、测试和使用。 - -- [OpenMPI](openmpi.md) -- [oneAPI](oneapi.md) -- [HPCX-MPI](hpcx.md) - -Profile 也是重要的一环。常用的 Profiler 和相关技术也单独介绍: - -- [oneAPI Profilers](oneapi_profilers.md) -- [ScoreP](scorep.md) +MPI 知识主要分两块内容: + +- MPI 编程技术 + - [MPI 标准](standard.md) +- 各类 MPI 实现的使用和调优:现有 OpenMPI、Intel MPI + - [MPI 使用](usage.md) + - [MPI 调优](optimization.md) + - [MPI 性能测试](profiling.md) diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/oneapi.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/oneapi.md" deleted file mode 100644 index ebe1c768..00000000 --- "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/oneapi.md" +++ /dev/null @@ -1,29 +0,0 @@ -# oneAPI - -> - -## 安装 - -### Spack - -oneAPI 的包在 Spack 中均以 `intel-oneapi-` 开头,选择需要的安装即可。有些包名相同但中间没有 `oneapi`,大概率是废弃的包。 - -### 从官网下载安装 - -通过官网下载安装的需要执行脚本 `oneapi/setvars.sh` 加载环境变量,会列出加载了的组件,`vtune`、`itac` 等分析工具也会被加载。 - -## 运行 - -对 Intel MPI 来说,`mpirun` 是 `mpiexec.hydra` 的包装。其选项有全局选项和局部选项之分,在一次运行多个 MPI 程序时可以分别指定,但我们平时不会这样做,因此不做区分。可以编写文件保存选项,使用 `-configfile` 指定配置文件,`#` 注释。`./mpiexec.conf` 会自动加载。 - -- 环境变量 - - `-genv ` 指定运行时环境变量,常用的有:`OMP_` - - `-genvall, -genvnone` 控制是否传递环境变量 -- profiling: - - `-trace` `-aps` `-mps` -- 设备: - - `iface` -- 运行参数: - - `-n, -np` 进程数 - - `-env` 环境变量 - - `-path` 可执行文件 diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/openmpi.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/openmpi.md" deleted file mode 100644 index 189b9be0..00000000 --- "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/openmpi.md" +++ /dev/null @@ -1,39 +0,0 @@ -# Open MPI - -!!! info "参考资料" - - [Open MPI: Videos: General information](https://www.open-mpi.org/video/?category=general) - - 该系列视频介绍了 Open MPI 内部的整体框架。 - -## Open MPI 的编译和构建 - -参考上面的 EasyBuild Tech Talk I - Part 1 的后半部分内容。 - -!!! warning "If you think you understand linkers you don't understand anything about linkers." - -## Process Management Interface (PMI) - -!!! info "参考资料" - - [Slurm: PMIx - Exascale Process Management Interface](https://slurm.schedmd.com/SLUG15/PMIx.pdf) - -> PMI enables Resource Managers (RMs) to use their infrastructure to implement advanced support for MPI application acting like RTE daemons. - -我们已经知道,集群一般都会有一个像 `slurm` 这样的 Resource Manager(RM)来管理集群资源。PMI 使得 RM 可以使用自己的基础设施来实现对 MPI 应用的高级支持,就像 RTE 守护进程一样。 - -一般不需要在意 PMI 版本的选择,直到进程数达到 10k 级别才会产生明显影响。 - -## Tip - -!!! tip "框架的兼容性问题" - - 各个环境中内嵌的模块版本可能不同,因此常常会引发如下的 Warning: - - ```text - [1698908851.361644] [GPU01:22592:0] ucp_context.c:1470 UCX WARN UCP version is incompatible, required: 1.15, actual: 1.8 (release 0 /lib/libucp.so.0) - ``` - - 这通常是无关紧要的。这些模块的设计都是 version compatible 的,即使版本不同,大部分情况下也可以正常工作。如果版本差异过大,可能会出现问题。 - -Open MPI 支持多种网络模块,最常用的是 [Unified Communication X (UCX) communication library](https://www.openucx.org/)。如果发现了可用的 InfiniBand 设备,Open MPI 会自动使用 UCX PML。 diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/optimization.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/optimization.md" new file mode 100644 index 00000000..4a6bb62e --- /dev/null +++ "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/optimization.md" @@ -0,0 +1,49 @@ +# MPI 调优 + +## 通信算法 + +MPI 实现一般都会为集合通信提供不同的算法,以适应不同的通信模式。这些算法在特定场景下可能会有不同的性能表现,因此需要根据实际情况进行调优。 + +一篇经典的例子是:[GitHub: OpenMPI Bcast and Allreduce much slower than Intel-MPI (unrelated to EFA)](https://github.com/aws/aws-parallelcluster/issues/1436)。这位作者在 AWS 集群上测试了 OpenMPI 和 IntelMPI 各种算法的性能,给出了详细的测试结果。 + +![Bcast algorithm comparison](https://user-images.githubusercontent.com/25473287/68506534-d4827e00-0237-11ea-8d04-e6b1836d96b8.png) + +可以看出性能差距还是比较明显的,因此算法调优是非常重要的。 + +=== "OpenMPI" + + - 列出可用的集合通信算法: + + ```bash + ompi_info --param coll tuned --level 9 + MCA coll tuned: parameter "coll_tuned_allreduce_algorithm" (current + value: "ignore", data source: default, level: 5 + tuner/detail, type: int) + Which allreduce algorithm is used. Can be locked + down to any of: 0 ignore, 1 basic linear, 2 + nonoverlapping (tuned reduce + tuned bcast), 3 + recursive doubling, 4 ring, 5 segmented ring. Only + relevant if coll_tuned_use_dynamic_rules is true. + Valid values: 0:"ignore", 1:"basic_linear", + 2:"nonoverlapping", 3:"recursive_doubling", + 4:"ring", 5:"segmented_ring", 6:"rabenseifner" + ``` + + - 通过 MCA 参数设置算法,以 recursive doubling 为例: + + ```bash + --mca coll_tuned_use_dynamic_rules 1 \ + --mca coll_tuned_allreduce_algorithm 3 \ + --mca coll_tuned_allreduce_algorithm_segmentsize 4096 \ + --mca coll_tuned_allreduce_algorithm_tree_fanout 4 + ``` + + - 设置 Bcast 算法: + + ```bash + orterun \ + --mca coll_tuned_use_dynamic_rules 1 \ + --mca coll_tuned_bcast_algorithm $algo \ + ``` + +=== "Intel MPI" diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/profiling.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/profiling.md" new file mode 100644 index 00000000..b6a595a9 --- /dev/null +++ "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/profiling.md" @@ -0,0 +1 @@ +# MPI 性能测试 diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/usage.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/usage.md" new file mode 100644 index 00000000..1081f553 --- /dev/null +++ "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/usage.md" @@ -0,0 +1,166 @@ +# MPI 使用 + +## 介绍 + +=== "OpenMPI" + + !!! info "参考资料" + + [Open MPI: Videos: General information](https://www.open-mpi.org/video/?category=general) + + 该系列视频介绍了 Open MPI 内部的整体框架。 + + - 编译和构建 + + 参考上面的 EasyBuild Tech Talk I - Part 1 的后半部分内容。 + + !!! warning "If you think you understand linkers you don't understand anything about linkers." + + ## Process Management Interface (PMI) + + !!! info "参考资料" + + [Slurm: PMIx - Exascale Process Management Interface](https://slurm.schedmd.com/SLUG15/PMIx.pdf) + + > PMI enables Resource Managers (RMs) to use their infrastructure to implement advanced support for MPI application acting like RTE daemons. + + 我们已经知道,集群一般都会有一个像 `slurm` 这样的 Resource Manager(RM)来管理集群资源。PMI 使得 RM 可以使用自己的基础设施来实现对 MPI 应用的高级支持,就像 RTE 守护进程一样。 + + 一般不需要在意 PMI 版本的选择,直到进程数达到 10k 级别才会产生明显影响。 + + !!! tip "框架的兼容性问题" + + 各个环境中内嵌的模块版本可能不同,因此常常会引发如下的 Warning: + + ```text + [1698908851.361644] [GPU01:22592:0] ucp_context.c:1470 UCX WARN UCP version is incompatible, required: 1.15, actual: 1.8 (release 0 /lib/libucp.so.0) + ``` + + 这通常是无关紧要的。这些模块的设计都是 version compatible 的,即使版本不同,大部分情况下也可以正常工作。如果版本差异过大,可能会出现问题。 + + Open MPI 支持多种网络模块,最常用的是 [Unified Communication X (UCX) communication library](https://www.openucx.org/)。如果发现了可用的 InfiniBand 设备,Open MPI 会自动使用 UCX PML。 + +=== "oneAPI" + + > + + - Spack + + oneAPI 的包在 Spack 中均以 `intel-oneapi-` 开头,选择需要的安装即可。有些包名相同但中间没有 `oneapi`,大概率是废弃的包。 + + - 从官网下载安装 + + 通过官网下载安装的需要执行脚本 `oneapi/setvars.sh` 加载环境变量,会列出加载了的组件,`vtune`、`itac` 等分析工具也会被加载。 + +## 概念 + +### 调度算法 + +- Round-Robin 时间片轮转:将相等长度的时间片按照不变的顺序依次分配给每个进程,且在处理所有进程时不考虑任何优先级。 + +==todo== + +### 绑定 + +==todo== + +## 运行 + +=== "OpenMPI" + + `mpirun` `mpiexec` `orterun` 是同一个命令。 + + `mpirun` 也可以运行多个程序,指定全局、局部选项,这里不作介绍。 + + OpenMPI 使用 Slot 作为资源分配单位,有多少个 Slot 就可以运行多少个进程。 + + - 默认:处理器核数。 + - 使用超线程核心数:用 `--use-hwthread-cpus` 开启,常见为 2 倍处理器核数。可以在 `lscpu` 中的 `Thread(s) per core` 查看。 + - 资源管理器调度:从资源管理器获取 Slot 数。 + - 需要注意:Slot 数和硬件没有关系,可能比硬件核数多,也可能比硬件核数少。 + +=== "Intel MPI" + + 对 Intel MPI 来说,`mpirun` 是 `mpiexec.hydra` 的包装。其选项有全局选项和局部选项之分,一般以 `g` 开头的参数是全局选项,下文不对全局和局部选项分别介绍。 + + 可以编写文件保存选项,使用 `-configfile` 指定配置文件,`#` 注释。`./mpiexec.conf` 会自动加载。 + + - 环境变量 + - `-genv ` 指定运行时环境变量,常用的有:`OMP_` + - `-genvall, -genvnone` 控制是否传递环境变量 + - profiling: + - `-trace` `-aps` `-mps` + - 设备: + - `iface` + - 运行参数: + - `-n, -np` 进程数 + - `-env` 环境变量 + - `-path` 可执行文件 + +### 资源管理器 + +下文以 Slurm 为例。 + +#### 角色 + +#### 与 MPI 的交互 + +MPI 与资源管理器可以通过三种方式交互: + +- Slurm 启动 MPI 并行程序,并通过 PMI API(Process Management Interface)调用执行初始化。 +- Slurm 分配资源,然后由 `mpirun` 基于 Slurm 的基础设施启动并行程序。`srun` 就是这种方式。 +- Slurm 分配资源,然后由 `mpirun` 通过 SSH 等其他机制启动并行程序。这种方式下,Slurm 无法进行资源管控和追踪。 + +#### 命令行与脚本运行 + +命令行使用 `srun` 执行,脚本使用 `sbatch` 提交。脚本内可以含有 `#SBATCH` 开头的指令,附带任意命令行参数。遇到第一个非注释行后停止解析参数。 + +我个人习惯在脚本中定义所有参数以便于管理,下面是一般模板: + +```bash +#!/bin/bash +#SBATCH --job-name=mpi_test --output=%x.%j.out +#SBATCH --time=04:00:00 --partition=RM +#SBATCH --nodes=2 --ntasks-per-node=1 --cpus-per-task=40 +export OMP_NUM_THREADS=${SLURM_CPUS_PER_TASK} +set -x +date +time mpirun -np $SLURM_NTASKS +``` + +其中 `--cpus-per-task` 在 OpenMP 时使用,`--ntasks-per-node` 一般设置为 1。注意上面使用环境变量传递参数,避免手动修改多处。 + +有时为了提高效率,还会将文件拷贝到计算节点上: + +```bash +sourcedir=$PROJECT/regcm/ompi +RC=1 +n=0 +while [[ $RC -ne 0 && $n -lt 20 ]]; do + rsync -aP $sourcedir $LOCAL/ + RC=$? + let n=n+1 + sleep 10 +done + +destdir=$PROJECT/regcm/results/ompi64.4p +mkdir -p $destdir +RC=1 +n=0 +while [[ $RC -ne 0 && $n -lt 20 ]]; do + rsync -aP $LOCAL/ $destdir + RC=$? + let n=n+1 + sleep 10 +done +``` + +#### 其他工具 + +- `sinfo` +- `squeue` + - `-u ` +- `scontrol` +- `sacct -j `:查看任务的详细信息 + - `--json` 按 JSON 格式输出所有信息 + - `--long` 输出所有信息,但一般乱成一团看不了 diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/Profiler/POP.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/Profiler/POP.md" new file mode 100644 index 00000000..98bcb231 --- /dev/null +++ "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/Profiler/POP.md" @@ -0,0 +1,28 @@ +# POP Tools Profiler + +## 安装 Profiler 工具 + +远程环境中,安装 Score-P 和 Scalasca 即可。如果是本地集群(具有可视化环境)可以配置 Cube。 + +安装过程基本都是: + +1. 下载解压 +2. `./configure --prefix=/path/to/install` +3. `make -j` +4. `make install` + +需要注意,在 `./configure` 阶段,可能需要添加各种依赖项(如果没有自动检测到的话)。 + +## 编译项目 + +在所有编译命令前面加上 `scorep` 即可。 + +## 运行和结果分析 + +- `scan` 运行。这里还有一些具体的选项。 + +运行后会输出简短的信息,并给出 trace 信息的文件名。 + +- `square -s` 分析文件,并给出 `.score` 等文件。 +- 使用 Cube 可视化分析 + diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/oneapi_profilers.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/Profiler/oneapi_profilers.md" similarity index 100% rename from "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/MPI/oneapi_profilers.md" rename to "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/Profiler/oneapi_profilers.md" diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/index.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/index.md" index 29a48749..505b65ff 100644 --- "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/index.md" +++ "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/index.md" @@ -4,6 +4,31 @@ ## 这本笔记的组织架构 +```mermaid +mindmap + root((高性能计算
HPC)) + 编译系统 + 文件格式 + 构建工具 + 包管理器 + 并行编程 + 进程级并行
MPI + 线程级并行 + OpenMP + Pthreads + C++11 Threads + CUDA 编程 + 性能分析 + 体系结构 + 性能优化 + 竞赛 + 功耗控制 + 运维 + 硬件 + 集群管理 + 虚拟化 +``` + 在我个人看来,HPC 的学习(和实际比赛)所需的知识点和技能可以构建和优化两个部分: ### 构建 diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/hardware.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/hardware.md" new file mode 100644 index 00000000..fb45a533 --- /dev/null +++ "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/hardware.md" @@ -0,0 +1 @@ +# 硬件:设备 \ No newline at end of file diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/hardware_port.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/hardware_port.md" index 5df8a624..c6533cff 100644 --- "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/hardware_port.md" +++ "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/hardware_port.md" @@ -108,16 +108,3 @@ SFF-8643 ## PCI/PCIe ### PCIe - -::cards:: - -[ - { - "title": "", - "content": "", - "image": "" - }, - -] - -::/cards:: diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/index.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/index.md" index c1694f5d..4970a153 100644 --- "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/index.md" +++ "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/index.md" @@ -4,7 +4,4 @@ - [硬件:设备](hardware.md) - [硬件:接口](hardware_port.md) -- [软件:基础配置](basic_config.md) -- [软件:操作系统](os.md) -- [软件:网络](network.md) -- [软件:服务](service.md) +- [软件:系统配置](system_config.md) diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/basic_config.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/system_config.md" similarity index 92% rename from "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/basic_config.md" rename to "docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/system_config.md" index 0a7f3209..da154ab5 100644 --- "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/basic_config.md" +++ "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\346\235\202\351\241\271/\350\277\220\347\273\264/system_config.md" @@ -1,6 +1,6 @@ -# 基础服务配置 +# 软件:系统 -这里介绍即使不是超算的 Linux 服务器也常用的基础服务的配置。 +这里介绍 Linux 服务器系统最最基础的配置。 ## 前置工具 diff --git "a/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\347\274\226\350\257\221\347\263\273\347\273\237/\350\215\211\347\250\277.md" "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\347\274\226\350\257\221\347\263\273\347\273\237/\350\215\211\347\250\277.md" new file mode 100644 index 00000000..3351daa2 --- /dev/null +++ "b/docs/\351\253\230\346\200\247\350\203\275\350\256\241\347\256\227/\347\274\226\350\257\221\347\263\273\347\273\237/\350\215\211\347\250\277.md" @@ -0,0 +1,166 @@ +# 编译系统 + +## 编译过程 + +## 自动化构建工具 + +在不同平台上编译项目,需要根据平台修改编译器、编译选项等。为了简化这个过程,可以使用自动化构建工具。 + +### GNU Autotools + +!!! info "" + + - [Tutorial](https://www.lrde.epita.fr/~adl/autotools.html) + - [Doc](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html) + +历史较为悠久的项目都会使用 GNU Autotools 来构建项目,标准流程为: + +```bash +./configure && make && make install +``` + +需要熟悉的工具是 Autoconf 和 `autoreconf`,其他工具一般不需要直接操作。 + +#### 文件结构 + +在 `./configure` 阶段可以使用 `--prefix=/path/to/dir` 参数指定安装路径,默认为 `/usr/local`。 + +构建工具将在该目录下生成文件,标准架构如下: + +```text +prefix +├── bin +├── include +├── lib +├── share +│ ├── man +│ ├── info +│ ... +... +``` + +#### Autoconf + +`./configure` 自动检测系统中的环境变量、库、头文件等,基于 `configure.ac` 等文件生成 `Makefile` 等文件。 + +可以指定的变量: + +```text +CC +CFLAGS +CXX +CXXFLAGS +LDFLAGS +CPPFLAGS (for both C and C++) +``` + +使用 `./configure --help` 查看帮助。 + +??? note "觉得在命令行中指定参数不方便?" + + 如果觉得写命令行参数太长,可以把变量指定到 `config.site` 文件中: + + ```text title="config.site" + test -z "$CC" && CC=gcc-3 + test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include + test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib + ``` + + 运行 `./configure` 时应当会提示如 `configure: loading site script /home/adl/usr/share/config.site`。 + +??? note "不需要在源文件目录中构建" + + `./configure` 在哪里运行,程序、目标文件和库文件就在哪里生成。因此,可以任何你希望的地方开始构建项目。 + + ```bash + mkdir build && cd build + /nfs/src/amhello-1.0/configure + make + ``` + + 这样可以方便地使用一份源代码为多个平台构建项目。 + +??? note "交叉编译" + + 使用 `--host` 参数指定目标体系结构。 + + ```bash + ./configure --host=i586-mingw32msvc + ``` + + `--target` 参数用于构建编译工具,指定编译工具的目标体系结构。 + +#### Automake + +`automake` 接受 `Makefile.am` 文件,生成 `Makefile.in` 文件。 + +可以指定的变量: + +```text +DESTDIR +``` + +一些通用的 target: + +```text +all +install +clean +distclean +``` + +#### Libtool + +`libtool` 用于处理库文件,可以生成 `.la` (libtool archive)文件。和它有关的操作都会被翻译为真实的库文件。 + +!!! warning "库文件是可移植性的地狱" + + 在不同平台上,库文件类型不同、编译选项不同。 + + 在 Linux 上,静态库为 `.a` 文件,动态库为 `.so` 文件。编译选项 `-fPIC` 用于生成位置无关代码,`-shared` 用于生成动态库。 + +在安装时可以使用下面的参数控制库文件生成: + +```text +--enable-shared +--disable-shared +--enable-static +--disable-static +``` + +#### 附:编写模板文件 + +为了使用 GNU Autotools 构建项目,至少需要编写下面的文件: + +- `configure.ac` +- `Makefile.am` +- `src/Makefile.am` + +`autoconf` 会按合适的顺序执行所有自动化工具。 + +```bash +autoreconf --install +``` + +### CMake + +## 问题记录 + +### 动态链接库 + +=== "错误表现" + + ```text + error while loading shared libraries: libpthread_rt.so.1: cannot open shared object file: No such file or directory + ``` + +=== "解释" + + `.so` 文件在运行时需要被加载,应当告诉系统在哪里找到它。 + + - `LD_LIBRARY_PATH` 用于指定动态链接库的搜索路径。 + - `ldconfig` 用于更新动态链接库缓存。 + - `ldd` 用于查看动态链接库依赖。 + - `rpath` 用于指定运行时搜索路径。 + +=== "解决办法" diff --git a/mkdocs.yml b/mkdocs.yml index 52f6ce68..bc9d640c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -13,7 +13,12 @@ markdown_extensions: # Admonition - admonition - pymdownx.details - - pymdownx.superfences + - pymdownx.superfences: + # Mermaid + custom_fences: + - name: mermaid + class: mermaid + format: !!python/name:pymdownx.superfences.fence_code_format # Code Block - pymdownx.highlight: anchor_linenums: true @@ -103,4 +108,4 @@ plugins: tags_file: index.md - search - glightbox - - git-revision-date-localized + - git-revision-date-localized \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 355978c2..2df4cc3b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ mkdocs mkdocs-material neoteroi-mkdocs mkdocs-glightbox -mkdocs-git-revision-date-localized-plugin +mkdocs-git-revision-date-localized-plugin \ No newline at end of file