0

I am batch processing in C++ and want to know whether it is possible to define a .cpp file name in the PBS script file (see below). For example, for one of my .cpp files I have two versions: a parallel OpenMP version (func_parallel.cpp) and a serial version (func_serial.cpp). I would like to be able to have two script files (both resembling the file below): one that specifies that I would like to use func_parallel.cpp and the other that specifies that I would like to use func_serial.cpp, without having to manually do this in the code.

Is this possible?

Script file:

#!/bin/bash

#PBS -S /bin/bash
#PBS -l walltime=00:10:00
#PBS -l select=1:ncpus=4:mem=2gb
#PBS -q QName 
#PBS -N Name
#PBS -o Results/output.txt
#PBS -e Results/error.txt
#PBS -m abe -M email@address

module purge
module load intel-compiler/11.1.073

export OMP_NUM_THREADS=4

cd $WORKDIR

./myprog
krylov
  • 79
  • 1
  • 4
  • 1
    You can use normal bash scripts in this PBS file. Defining a variable for your file name is fine. It's better to explain what to achieve in your script. – Yuan Jul 24 '14 at 15:56

1 Answers1

0

You can pass an environment variable to your script that indicates whether or not the job is parallel. For example:

qsub script.sh -v parallel=true or qsub script.sh

to indicate that the job is parallel or serial respectively. Then you could have some lines in the script like:

if -z $parallel
  file=func_parallel.cpp
else
  file=func_serial.cpp

# compile and run the binary

However, it seems like it'd be easier to just have two copies of the binary available, one that is serial and another that is parallel and instead of selecting the .cpp and rebuilding each time maybe you should just select which binary and run that each time.

dbeer
  • 6,963
  • 3
  • 31
  • 47
  • Thanks for your response @dbeer. How do I read in the variable "file" into my code? – krylov Jul 24 '14 at 16:49
  • You would have to recompile. That's why I'm suggesting that you simply compile twice and select the binary in the job script. – dbeer Jul 24 '14 at 16:56