12

有没有办法在提交作业之前直接将参数传递给 .pbs 脚本?我需要遍历由不同数字表示的文件列表并应用脚本来分析每个文件。

我能想到的最好的方法如下:

#!/bin/sh 

for ((i= 1; i<= 10; i++))
do
        export FILENUM=$i
        qsub pass_test.pbs
done

其中 pass_test.pbs 是以下脚本:

#!/bin/sh

#PBS -V
#PBS -S /bin/sh
#PBS -N pass_test
#PBS -l nodes=1:ppn=1,walltime=00:02:00
#PBS -M XXXXXX@XXX.edu

cd /scratch/XXXXXX/pass_test

./run_test $FILENUM

但这感觉有点不靠谱。特别是,我想避免必须创建一个环境变量来处理这个问题。

4

3 回答 3

10

qsub实用程序可以从标准输入读取脚本,因此通过使用此处的文档,您可以动态创建脚本:

#!/bin/sh

for i in `seq 1 10`
do
    cat <<EOS | qsub -
#!/bin/sh

#PBS -V
#PBS -S /bin/sh
#PBS -N pass_test
#PBS -l nodes=1:ppn=1,walltime=00:02:00
#PBS -M XXXXXX@XXX.edu

cd /scratch/XXXXXX/pass_test

./run_test $i
EOS
done

就个人而言,我会使用更紧凑的版本:

#!/bin/sh

for i in `seq 1 10`
do
    cat <<EOS | qsub -V -S /bin/sh -N pass_test -l nodes=1:ppn=1,walltime=00:02:00 -M XXXXXX@XXX.edu -
cd /scratch/XXXXXX/pass_test
./run_test $i
EOS
done
于 2012-04-10T18:40:35.577 回答
4

You can use the -F option, as described here:

-F

Specifies the arguments that will be passed to the job script when the script is launched. The accepted syntax is:

qsub -F "myarg1 myarg2 myarg3=myarg3value" myscript2.sh

Note: Quotation marks are required. qsub will fail with an error message if the argument following -F is not a quoted value. The pbs_mom server will pass the quoted value as arguments to the job script when it launches the script.

See also this answer

于 2020-06-24T23:17:26.470 回答
0

If you just need to pass numbers and run a list of jobs with the same command except the input file number, it's better to use a job array instead of a for loop as job array would have less burden on the job scheduler.

To run, you specify the file number with PBS_ARRAYID like this in the pbs file:

./run_test ${PBS_ARRAYID}

And to invoke it, on command line, type:

qsub -t 1-10 pass_test.pbs

where you can specify what array id to use after -t option

于 2016-08-03T18:22:32.300 回答