Skip to content

Commit

Permalink
init again
Browse files Browse the repository at this point in the history
  • Loading branch information
bowling233 committed Feb 2, 2024
1 parent 53ffb46 commit 5eb448c
Show file tree
Hide file tree
Showing 190 changed files with 692 additions and 1,313 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,26 @@ $$
- 连续统假设
1. $|\mathbf{P}(\mathbf{Z^+})|=|\mathbf{R}|=c$

## 关系

- 关系:$n$ 元集合上有 $2^n^2$ 个二元关系。
- 怎么数的?数笛卡尔积的幂集即可。笛卡尔积的基数为 $n^2$,幂集的基数为 $2^{n^2}$。
- 关系也有定义域和值域。关系也可以像函数那样复合,可以有幂。关系也有逆。
- $n$ 元关系是 $n$ 元笛卡尔积的子集。
- Identity relation:$I_A = \{(a, a) \mid a \in A\}$,是 $A$ 上的恒等关系。
- 自反性:$\forall a \in A(aRa)$;非自反性:$\forall a \in A(\neg aRa)$
- 例子:$\leq$
- $n$ 元集合上有 $2^{n(n-1)}$ 个自反关系:共计 $n^2$ 个关系中,有 $n$ 个关系确定,接下来的 $n^2-n$ 个可以属于该关系或不属于该关系。
- 显然,$R_= \subseteq R$。
- 对称性:$\forall a, b \in A(aRb \rightarrow bRa)$;反对称性:$\forall a, b \in A(aRb \wedge bRa \rightarrow a=b)$
- 例子:$=$
- 反对称性有:$R\cap R^{-1} \subseteq R_=$
- 传递性:$\forall a, b, c \in A(aRb \wedge bRc \rightarrow aRc)$;非传递性:$\forall a, b, c \in A(aRb \wedge bRc \rightarrow \neg aRc)$
- 例子:$\leq$
- 充要条件:$R^n \subseteq R$。
-


##

| Eng | 中文 |
Expand Down Expand Up @@ -246,7 +266,7 @@ $$
$$
\begin{align}
\mathrm{deg}(v_k) \text{is even}\\
n\geq 3, \mathrm{deg}(v_k) \geq n/2
n\geq 3, \mathrm{deg}(u) + \mathrm{deg}(v) \geq n \text{ for all } u, v \in V\\
\end{align}
$$
<!-- prettier-ignore-end -->
Expand All @@ -257,7 +277,9 @@ $$
- 欧拉回路充要条件:图连通且所有顶点的度都是偶数(even)。
- 哈密顿路径:经过每个顶点一次且仅一次的路径。
- 哈密顿回路:经过每个顶点一次且仅一次的回路。
- 哈密顿回路存在性:Dirac 定理:如果 $n \geq 3$ 且每个顶点的度都大于等于 $n/2$,则图存在哈密顿回路。
- 哈密顿回路存在性:
- Dirac 定理:如果 $n \geq 3$ 且每个顶点的度都大于等于 $n/2$,则图存在哈密顿回路。
- Ore 定理:如果 $n \geq 3$ 且对于所有不相邻的顶点 $u$ 和 $v$,$\mathrm{deg}(u) + \mathrm{deg}(v) \geq n$,则图存在哈密顿回路。

<!-- prettier-ignore-start -->
!!! note "Dijkstra 算法"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
104 changes: 104 additions & 0 deletions backup/misc/comp_hpcgame1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# 1st PKU HPCGame

## B. 流量席卷土豆

<!-- prettier-ignore-start -->
!!! info "题目省流"

使用 Slurm 提交任务,在 4 个节点上,每个节点运行 4 个进程,同时读取 16 个文件。
<!-- prettier-ignore-end -->

步骤如下:

- Slurm 并行运行 `tshark` 过滤 SSH 数据,`mergecap` 合并为单 PCAP 文件。前者需要保留 Slurm JobID。
- 将合并后的 PCAP 文件输入 `quantum-cracker` 得到结果。

```bash
srun -p C064M0256G -N4 --ntasks-per-node=4 bash -c 'tshark -r /lustre/shared_data/potato_kingdom_univ_trad_cluster/pcaps/${SLURM_PROCID}.pcap -Y ssh -w ${SLURM_PROCID}.ssh.pcap'
sacct -u $(whoami) --format JobID | tail
mergecap -w merged.pcap *.ssh.pcap
quantum-cracker merged.pcap
```


## D. 小北问答 Classic

1. 65.396
2. 105.26 107.14
3. iv. GCC
4. 进程、线程、线程
5. 8 i ii
6. xi. OpenACC
7. 未找到正确选项。
8. iv. HBM
9. ii. Slurm
10. i. 缓存未命中

## F. 高性能数据校验

<!-- prettier-ignore-start -->
!!! info "题目省流"

输入一个文件,使用 SHA512 进行分块文件校验,输出校验码。校验过程如下:

- 分块,`M=1MB`,不足补 0。
- 每块末尾连接前一块的校验码,得到的数据进行校验,得到本块校验码。
- 最后一块的校验码为文件校验码。

需要了解一下 `libcrypto` 库,运用拆分出的各个函数安排并行任务。

环境:OpenMPI,并行节点 2 个,每个节点 4 个进程。
<!-- prettier-ignore-end -->

### 简单了解一下 `libcrypto`

![Libcrypto API](https://wiki.openssl.org/index.php/Libcrypto_API).

Libcrypto 提供高级和低级接口,其中高级接口称为 EVP interface,直接提供加密解密、校验码等功能,也是我们在基准代码中看到的。低级接口则需要直接与各种算法打交道。

![EVP](https://wiki.openssl.org/index.php/EVP).

EVP 提供一些对象:

- `EVP_PKEY`s:用于存储密钥,支持 RSA、EC 等等。
- `EVP_CIPHER`s:用于存储
- `EVP_MD`s:Message Digest,消息摘要,正是本题关注的。

一点密码学概念:消息完整性。

> 有些场合我们不需要保密,但需要完整性。这是与加密不同的安全服务。
>
> 这里我们需要用到**密码散列函数**,建立消息的压缩影像。这些散列函数从长度不一的消息中创建**长度固定**的消息摘要,一般都采用**迭代**完成。
>
> MD(Message Digest)消息摘要算法由罗恩·李维斯设计,最新的 MD5 版本将消息分为长度为 512 位的分组,创建大小为 128 位的摘要,但摘要太小了无法阻挡攻击。
>
> SHA(Secure Hash Algorithm)安全散列算法由 NIST 设计,有许多版本。本题基于 SHA 512。
![EVP Message Digests](https://wiki.openssl.org/index.php/EVP_Message_Digests)

使用 OpenSSL 消息摘要/散列函数的步骤如下:

- Create a Message Digest context
- Initialise the context by identifying the algorithm to be used (built-in algorithms are defined in evp.h)
- Provide the message whose digest needs to be calculated. Messages can be divided into sections and provided over a number of calls to the library if necessary
- Caclulate the digest
- Clean up the context if no longer required

### 程序结构

了解了上面的这些背景,程序的基本结构也就一目了然了。

`main` 中调用 `checksum`,消息读入 `buffer`,摘要输出到 `obuf`

注意一下消息的数据格式,都是用 `uint8_t` 即以字节为单位,之后计算数据结构大小需要用到。`BLOCK_SIZE` 已定为 1MB。

`checksum` 中:

- `prev_md` 存储上一次的摘要。
- `EVP_DigestUpdate(ctx, d, cnt)` Hashes `cnt` bytes of data at `d` into the digest context `ctx`. This function can be called several times on the same `ctx` to **hash additional data**.
- `EVP_DigestFinal_ex(ctx, md, s)` Retrieves the digest value from `ctx` and places it in `md`. If the `s` parameter is not NULL then the number of bytes of data written (i.e. the length of the digest) will be written to the integer at `s`, at most EVP_MAX_MD_SIZE bytes will be written unless the digest implementation allows changing the digest size and it is set to a larger value by the application. **After calling `EVP_DigestFinal_ex()` no additional calls to `EVP_DigestUpdate()` can be made**, but `EVP_DigestInit_ex2()` can be called to initialize a new digest operation.

### 思路与探索

一眼看过去,各个数据块之间有联系,前一个没计算完无法计算下一个,似乎不能并行。但 `EVP_DigestUpdate` 函数可以被多次调用,给任务提供了分阶段进行的可能。

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions docs/misc/scripts.md → backup/misc/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,18 @@ $(objects): %.o: %.c
```

## Bash

## CMake

<!-- prettier-ignore-start -->
!!! info "[CMake Tutorial](https://cmake.org/cmake/help/latest/guide/tutorial/index.html)"
<!-- prettier-ignore-end -->

基本结构:

```cmake
cmake_minimum_required()
project()
add_executable()
```

File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions docs/misc/tu_vscode.md → backup/misc/tu_vscode.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,4 @@ VSCode 利用语言对应的扩展来支持调试。不同的调试器支持的
```
<!-- prettier-ignore-end -->

## VSCode 的背后

了解这些内容,你将能够为 VSCode 的开发做出贡献。

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion docs/books/Algorithm/.gitignore

This file was deleted.

87 changes: 0 additions & 87 deletions docs/books/Algorithm/ds/10.1.4_queue_overflow.c

This file was deleted.

115 changes: 0 additions & 115 deletions docs/books/Algorithm/ds/10.1.5_dequeue.c

This file was deleted.

Loading

0 comments on commit 5eb448c

Please sign in to comment.