Search code examples
fortrangfortranhpcpbs

running parallel code on PC


I have fortran code that has been parallelized with OpenMP. I want to test my code on my PC before running on HPC. My PC has double core CPU and I work on Linux-mint. I installed gfortranmultilib and this is my script:

#!/bin/bash
### Job name
#PBS -N pme
### Keep Output and Error
#PBS -j eo
### Specify the number of nodes and thread (ppn) for your job.
#PBS -l nodes=1:ppn=2
### Switch to the working directory;
cd $PBS_O_WORKDIR
### Run:
OMP_NUM_THREADS=$PBS_NUM_PPN
export  OMP_NUM_THREADS
ulimit -s unlimited
./a.out

echo 'done'

What should I do more to run my code?

OK, I changed script as suggested in answers:

#!/bin/bash
### Switch to the working directory;
cd Desktop/test
### Run:
OMP_NUM_THREADS=2
export  OMP_NUM_THREADS
ulimit -s unlimited
./a.out

echo 'done'

my code and its executable file are in folder test on Desktop, so:

cd Desktop/test

is this correct?

then I compile my simple code:

  implicit none
  !$OMP PARALLEL
  write(6,*)'hi'
  !$OMP END PARALLEL
  end

by command:

gfortran -fopenmp test.f

and then run by:

./a.out

but only one "hi" is printed as output. What should I do? (and a question about this site: in situation like this I should edit my post or just add a comment?)


Solution

  • You don't need and probably don't want to use the script on your PC. Not even to learn how to use such a script, because these scripts are too much connected to the specifics of each supercomputer.

    I use several supercomputers/clusters and I cannot just reuse the script from one at the other, because they are so much different.

    On your PC you should just do:

    1. optional, it is probably the default

      export OMP_NUM_THREADS=2
      

    to set the number of OpenMP threads to 2. Adjust if you need some other number.

    1. cd to the working directory

      cd my_working_directory
      

    Your working directory is the directory where you have the required data or where the executable resides. In your case it seems to be the directory where a.out is.

    1. run the damn thing

      ulimit -s unlimited
      ./a.out
      

    That's it.

    You can also store the standard output and error output to a file

        ./out > out.txt 2> err.txt
    

    to mimic the supercomputer behaviour.


    The PBS variables are only set when you run the script using qsub. You probably don't have that on your PC and you probably don't want to have it either.

    $PBS_O_WORKDIR is the directory where you run the qsub command, unless you set it differently by other means.

    $PBS_NUM_PPN is the number you indicated in #PBS -l nodes=1:ppn=2. The queue system reads that and sets this variable for you.