import torch
import torch.multiprocessing as mp
import time
import math
def stress_task(gpu_id):
try:
device = torch.device(f"cuda:{gpu_id}")
torch.cuda.set_device(device) # 确保上下文正确
free_mem, total_mem = torch.cuda.mem_get_info(device)
# 3. 动态计算矩阵大小
# 设定占用目标为剩余显存的 65% (留 35% 给 PyTorch内核开销,防止 OOM)
# 此时需要存储 X, Y 以及结果 Z,共 3 个矩阵。每个 float32 占 4 字节。
# 公式: (N * N * 4 bytes) * 3 matrices <= free_mem * 0.65
target_mem = free_mem * 0.65
matrix_size = int(math.sqrt(target_mem / 12))
free_gb = free_mem / (1024**3)
total_gb = total_mem / (1024**3)
print(f"[GPU {gpu_id}] Total: {total_gb:.2f}GB | Free: {free_gb:.2f}GB")
print(f"[GPU {gpu_id}] Calculated Matrix Size: {matrix_size}x{matrix_size} (Target utilization: ~85%)")
print(f"[GPU {gpu_id}] Allocating memory...")
x = torch.randn(matrix_size, matrix_size, device=device)
y = torch.randn(matrix_size, matrix_size, device=device)
print(f"[GPU {gpu_id}] Starting loop...")
while True:
z = torch.mm(x, y)
except RuntimeError as e:
print(f"[GPU {gpu_id}] Error: {e}")
if "out of memory" in str(e):
print(f"[GPU {gpu_id}] Auto-size was too aggressive. Try lowering the 0.85 factor in code.")
except KeyboardInterrupt:
pass
if __name__ == '__main__':
if not torch.cuda.is_available():
print("CUDA is not available!")
exit()
num_gpus = torch.cuda.device_count()
print(f"Found {num_gpus} GPUs. Auto-calculating load for each...")
processes = []
mp.set_start_method('spawn', force=True)
print("Starting processes... (Press Ctrl+C to stop)")
start_time = time.time()
try:
for i in range(num_gpus):
p = mp.Process(target=stress_task, args=(i,))
p.start()
processes.append(p)
for p in processes:
p.join()
except KeyboardInterrupt:
print(f"\nStop signal received. Terminating all processes...")
for p in processes:
if p.is_alive():
p.terminate()
print(f"All stopped. Duration: {time.time() - start_time:.2f} seconds")
Cluade Code使用国产平台(如MiniMax,GLM)的配置流程
首先安装node.js: https://nodejs.org/zh-cn/download
安装后通过npm安装pnpm:npm install -g pnpm@latest-10
然后用pnpm安装Cluade Code: pnpm install -g @anthropic-ai/claude-code
网络问题请换源: pnpm config set registry https://registry.npmmirror.com/
然后编辑~/.claude/settings.json,内容国产平台的教程上应该有
由于Cluade Code禁止了一些国家和地区,直接运行会有如下的提示:

,所以需要绕过其验证,编辑~/.claude.json,在json的根目录(也就是{}内)增加一行: “hasCompletedOnboarding”: true,如:

然后保存退出来,运行:
node --eval "
const homeDir = os.homedir();
const filePath = path.join(homeDir, '.claude.json');
if (fs.existsSync(filePath)) {
const content = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
fs.writeFileSync(filePath,JSON.stringify({ …content, hasCompletedOnboarding: true }, 2), 'utf-8');
} else {
fs.writeFileSync(filePath,JSON.stringify({ hasCompletedOnboarding: true }), 'utf-8');
}"
之后进入项目根目录输入claude即可正常使用:

MiKTex找不到某个宏包,但是CTAN上有的安装方法
比如`sttools`这个宏包目前就无法在MiKTex的Console里安装
解决方法为先去CTAN上下载得到源代码的安装包,解压后用命令行编译压缩包里的dtx文件,如
tex .\stfloats.dtx
然后将编译后得到的.sty移动到需要编译的项目tex的同目录(如Menuscript.tex)即可
Latex在Windows下的安装部署[MiKTex+Cursor(VS Code)]
为什么选择MiKTex而不是Tex Live?
Tex Live的安装包大概在6GB左右,里面包含了很多的Package但是实际上相当一部分并不会用上,安装时间方面也不乏吐槽,而MiKTex提供了最小化的安装包,大概100M+就可以
继续阅读“Latex在Windows下的安装部署[MiKTex+Cursor(VS Code)]”