Question

After reading through numerous bash script threads and help sites, I cannot find a solution that works.

I want to pass a variable argument 'i' from a script to another script $i, then qsub this to a program "$1". In the program I read the variable from the argument vector (**argv) and then use this variable to modify the name of output files as *_0, *_1, *_2, ..., *_n.

The idea is so I can have a unique output file for each instance of a program. The program is parallel but due to limitations of the computing resources, I need to submit one job for a maximum of four computing nodes - or it will never pass through the que. So, I'd like to spin off 64 4-node jobs.

So far I have read topic on:

After reading these, I feel comfortable with the concept but still it is confusing how exactly the -C and -S command are used, or if they are used at all; most examples exclude these.

This is my spinoff pre-script

#
#$ -cwd
#$ -S /bin/bash
#$ -pe fah 1
for((i=0; i < 2; i++)); do qsub test_S17_script.sh $i; done

side info: what is qsub

And this is my script

#
#$ -M duser@acme_u.edu
#$ -m bae
#$ -cwd
#$ -S /bin/bash
#$ -pe fah 1

./daedalus_linux_1.3_64 1 "$1"

So, the spinoff works fine, and generates the files. And, the script works fine passing a constant ./daedalus_linux_1.3_64 1 1 but passing the variable does not work. I do not know if the prescript correctly passes variable i to the script. I don't know how to write to a error file from a script - or if this is even how I want to check if the variable is passed. The computing has no user interface so once it is in the queue I must rely on error file outputs.

Thank you in advance for your help.

Was it helpful?

Solution

If you're looking to pass standard output from your prescript to the script, you could do something like:

./daedalus_linux_1.3_64 1 `<prescript>`

If the prescript prints output from each iteration of the for loop (i=0, i=1) on separate lines, you could probably pipe the output generated by your prescript to the xargs command.

In the prescript, you could change the output formatting to display all output generated by each iteration of qsub on a single line as follows:

for((i=0; i < 2; i++)); do qsub test_S17_script.sh $i; done | xargs

or you can use xargs as follows:

./daedalus_linux_1.3_64 1 `<prescript> | xargs`

Hope that helps.

OTHER TIPS

Consider using PBS Job Arrays. A single pbs script will submit multiple jobs and each job will have a different value for the environment variable $PBS_ARRAY_INDEX.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top