2014-09-12 318 views
0

我想从文件夹中选取多个模型,并在sge脚本中将它们用于阵列作业。所以,我中SGE脚本如下:在qsub脚本中使用变量作为参数参数

MODELS=/home/sahil/Codes/bistable/models 
numModels=(`ls $MODELS|wc -l`) 
echo $numModels 

#$ -S /bin/bash 
#$ -cwd 
#$ -V 
#$ -t 1-$[numModels] # Running array job over all files in the models directory. 

model=(`ls $MODELS`) 
echo "Starting ${model[$SGE_TASK_ID-1]}..." 

,但我得到了以下错误:

Unable to read script file because of error: Numerical value invalid! 
The initial portion of string "$numModels" contains no decimal number 

我也曾尝试使用

#$ -t 1-${numModels} 

#$ -t 1-(`$numModels`) 

但这些都没有工作。任何建议/替代方法都是受欢迎的,但它们必须使用qsub的阵列作业功能。

回答

2

当心Bash,#$ -t 1-$[numModels]只不过是一个评论;因此它不会将可变扩展应用于numModels。

一种选择是通过-t参数在命令行:如果您希望有一个自我

#$ -S /bin/bash 
#$ -cwd 
#$ -V 

model=(`ls $MODELS`) 
echo "Starting ${model[$SGE_TASK_ID-1]}..." 

MODELS=/home/sahil/Codes/bistable/models qsub -t 1-$(ls $MODELS|wc -l) submit.sh 

,并提交脚本:从脚本中删除包含提交脚本,另一种选择是通过标准输入框传递整个脚本的内容,如下所示:

#!/bin/bash 
qsub <<EOT 
MODELS=/home/sahil/Codes/bistable/models 
numModels=(`ls $MODELS|wc -l`) 
echo $numModels 

#$ -S /bin/bash 
#$ -cwd 
#$ -V 
#$ -t 1-$[numModels] # Running array job over all files in the models directory. 

model=(`ls $MODELS`) 
echo "Starting ${model[$SGE_TASK_ID-1]}..." 
EOT 

然后,您直接输入或执行该脚本以提交作业数组(./submit.sh而不是qsub submit.sh,因为qsub命令在此处是脚本的一部分。

+0

这是有效的,但如果解决方案是在sge脚本本身内部,不包含在shell脚本中,或者将参数放在命令行中,我真的很喜欢。 – 2014-09-12 13:17:12

+0

@Sahil,这可能是不可能的。 SGE脚本将每个任务执行一次,从1到计算的总任务数。因此,在执行SGE脚本之前,确定任务总数需要发生。这就是达米恩所避免的。 – Vince 2014-09-19 13:26:54

+0

@Vince,我遵循这一点,但-t无论如何都需要在SGE脚本中使用静态数字参数。我所说的是用变量替换上限,它不会随着数组作业的每个任务而改变。如果没有这方面的规定,我可能只是每次手工编写数字,以避免由sh包装qsub,这有其自己的一套问题。 – 2014-09-21 13:36:19