The number of nodes within k-hops in a n-D Torus

本文介绍了一种计算n维环形网络中从任意节点出发,在k步内能够到达的节点总数的方法,并提供了递归算法实现。适用于高性能计算系统中的节点可达性分析。

Torus is a widely used interconnection in high-performance computing systems. Torus can be built as 1D, 2D, 3D, 4D, 5D, 6D, and even higher dimensional topology, and they can be both server-centric and switch-centric.

For a n-D Torus with the same number of nodes in each dimension, starting from a certain node A how many nodes it can be reached within k hops?  Our research shows that it can be formulated mathematically as follows:

  • 1-D (n=1):  N = 2*(k+1);
  • 2-D or 3-D (n=2 or n=3):  N = f(n-1, k) + 2*[f(n-1, k-1) + 1] + ... + 2*[f(n-1, 0) +1] +2;
  • 4-D or higher D (n >= 4) :  N = f(n-1, k) + 2[f(n-1, k-1) + 1]

,where n indicates the dimension of Torus, k denotes the number of hops starting from 0, N gives the total number of nodes that can be reached within k-hops, and the function f(n,k) computes the N for the case of k-hops in a n-D Torus.

This can be easily implemented in a recursive way. The codes are attached as follows for your reference:

#include <iostream>

using namespace std;

int nodes_num (int dimension, int hops)
{
	int nodes;

//	if (dimension <= 0 || hops < 0)
//	{
//		cerr << "Wrong parameter! Please try again!" << endl;
//		return -1;
//	}

	if(dimension == 1)
	{
		return 2 * (hops + 1);
	}

	if(dimension == 2 || dimension == 3)
	{
		nodes = nodes_num(dimension - 1, hops);
		for (int k = hops - 1; k >= 0; k--)
		{
			nodes += 2 * (nodes_num(dimension - 1, k) + 1);
		}
		return nodes + 2;
	}

	if(dimension >= 4)
	{
		if (hops == 0)
		{
			return nodes_num(dimension - 1, hops) + 2;
		}
		else
		{
			return nodes_num(dimension - 1, hops) + 2 * (nodes_num(dimension - 1, hops - 1) + 1);
		}
	}
}

int main()
{	
	while(!cin.fail() && !cin.bad())
	{
		int dimension, hops, nodes;

		cout << "Please input the dimension and the hops: " << endl;

		cout << "Dimension = ";
		cin >> dimension;

		cout << "Hops = ";
		cin >> hops;
		
		if (dimension <= 0 || hops < 0)
		{
			cerr << "Wrong parameter! Please check it and try again!" << endl;
			return -1;
		}
		else
		{
			nodes = nodes_num(dimension, hops);
			
			cout << "The total number of nodes that can be reached within " << hops << " hops is: " << nodes << endl << endl;

			cout << "The total number of nodes that can be reached at the " << hops << " hop is: " 
				 << nodes_num(dimension, hops) - nodes_num(dimension, hops - 1) << endl << endl;
		}
	}
	
	return 0;
}


<think>我们正在解决一个具体的错误:使用xshell登录超算提交作业指定多个节点时出现'sbatch: error: invalid number of nodes (-N 6-1)'错误。 根据错误信息,问题出在节点数量的指定上(-N 6-1)。在Slurm中,-N选项用于指定节点数,但格式应该是一个数字或者一个范围(如2-4),而这里出现了“6-1”,这显然是不合法的。 分析可能的原因: 1. 用户在运行文件(提交脚本)中使用了错误的节点数格式。 2. 用户在命令行参数中直接指定节点数时格式错误。 回顾用户之前的问题:用户想要指定多个节点,可能尝试了某种范围表示,但写成了“6-1”,而正确的范围表示应该是“起始节点数-结束节点数”,且起始节点数必须小于或等于结束节点数(例如1-6表示1到6个节点)。但是,这里的“6-1”显然不符合要求。 因此,我们需要检查用户提交作业时使用的命令或脚本中的节点数指定部分。 解决方案: 1. 检查提交脚本中是否包含类似`#SBATCH -N 6-1`的指令,如果有,将其改为正确的格式,例如`#SBATCH -N 6`(表示6个节点)或者`#SBATCH -N 1-6`(表示1到6个节点,但通常我们不这样写,因为这样会允许调度系统分配1到6个节点中的任意数量)。如果用户明确需要6个节点,应该写`#SBATCH -N 6`。 2. 如果用户是在命令行中提交作业时指定节点数(例如:sbatch -N 6-1 script.slurm),那么需要修改命令为正确格式,比如`sbatch -N 6 script.slurm`。 另外,注意在Slurm中,节点数量的指定还可以使用其他选项,例如: - `--nodes=<min_nodes>-<max_nodes>` 表示节点数的范围(最小和最大) - `--nodes=<node_count>` 表示确切的节点数 所以,用户应该根据实际需求选择: - 如果只需要固定数量的节点,使用`-N <number>`或`--nodes=<number>` - 如果需要一个范围,确保最小节点数小于等于最大节点数,例如`--nodes=1-6` 错误示例:`-N 6-1` 会被解析为最小节点6,最大节点1,这是无效的。 因此,请用户按照以下步骤操作: 步骤1:打开提交脚本(例如job.slurm) 步骤2:查找包含`#SBATCH -N`或`#SBATCH --nodes=`的行 步骤3:修改该行,确保节点数指定正确: - 固定节点数:例如 `#SBATCH -N 6` - 节点数范围:例如 `#SBATCH --nodes=1-6` (注意:最小节点数在前,最大在后) 步骤4:保存并重新提交作业:`sbatch job.slurm` 如果用户没有在脚本中指定节点数,而是在命令行中指定,那么请修改提交命令。 另外,引用[1]中提到了集群槽的指派信息,虽然与问题无关,但提醒我们Slurm调度系统内部管理节点资源的方式。引用[2]中设置Slurm相关目录的权限,如果权限设置不正确也可能导致提交问题,但当前错误信息直接指向节点数无效,所以先解决节点数格式问题。 如果问题仍然存在,可能需要检查Slurm配置或联系超算管理员,因为可能是其他原因(如节点数超过可用节点数)导致,但首先确保格式正确。 总结:这个错误是由于节点数指定格式无效导致的,修改为正确的格式即可。 注意:在编写运行文件时,确保所有`#SBATCH`指令的语法正确。 生成相关问题: 1. 在Slurm中如何正确指定节点范围? 2. Slurm提交作业时常见参数错误有哪些? 3. 如何查看超算集群的可用节点数? 4. Slurm作业提交失败的其他常见原因及解决方法? </think>### 解决 `sbatch: error: invalid number of nodes (-N 6-1)` 错误 该错误是由于 Slurm 调度系统中节点数量格式无效导致的。以下是具体原因和解决方案: #### 错误原因 1. **格式语法错误** Slurm 要求节点数量格式为: - 固定数量:`-N 4`(请求4个节点) - 范围格式:`-N 2-5`(请求2~5个节点) 您的 `-N 6-1` 不符合范围格式要求(起始值6 > 结束值1)。 2. **常见触发场景** - 脚本中直接使用 `#SBATCH -N 6-1` - 命令行提交时输入 `sbatch -N 6-1 script.slurm` - 动态生成节点数时逻辑错误(如变量计算失误) --- #### 解决方案 ##### 1. 修正运行文件中的节点格式(首选方案) 在您的提交脚本(如 `job.slurm`)中修改节点指定格式: ```bash #!/bin/bash # 正确示例1:固定数量(需要6个节点) #SBATCH -N 6 # 正确示例2:范围格式(最少2个,最多6个节点) #SBATCH -N 2-6 # 其他必要参数 #SBATCH --ntasks-per-node=8 #SBATCH --output=job.log srun ./your_program ``` ##### 2. 命令行提交时的修正 直接提交时使用正确语法: ```bash # 请求6个节点 sbatch -N 6 your_script.slurm # 请求2~6个节点(调度器灵活分配) sbatch -N 2-6 your_script.slurm ``` ##### 3. 检查动态参数生成逻辑 若节点数通过变量生成: ```bash #!/bin/bash min_nodes=2 max_nodes=6 # 确保 min_nodes <= max_nodes #SBATCH -N ${min_nodes}-${max_nodes} # 正确格式 ``` --- #### 验证步骤 1. **检查脚本语法** 使用 `slurm-syntax-check`(若支持)或人工核查 `-N` 参数格式。 2. **测试提交** ```bash # 测试性提交(不实际运行) sbatch --test-only -N 2-6 job.slurm ``` 3. **查看可用节点** 确认节点数量未超集群上限: ```bash sinfo -o "%N %C" # 显示节点名和可用核心数 ``` 4. **检查配置文件** 确保 `/etc/slurm/slurm.conf` 中无冲突限制(需管理员权限)[^2]。 --- #### 预防措施 - **格式规范**:始终确保范围格式满足 $ \text{min\_nodes} \leq \text{max\_nodes} $ - **参数验证**:在脚本开头添加格式检查: ```bash if [ $MIN_NODES -gt $MAX_NODES ]; then echo "错误:最小节点数不能大于最大节点数" exit 1 fi ``` - **使用别名**:在 `~/.bashrc` 定义常用提交命令: ```bash alias slurm6="sbatch -N 6 script.slurm" ``` > **关键提示**:节点分配还需配合 `--ntasks-per-node`、`--cpus-per-task` 等参数确保资源合理性[^1]。若问题持续,请联系超算管理员检查集群配置[^2]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值