
# environment_variables -- settings for running Quantum ESPRESSO examples

######## YOU MAY NEED TO EDIT THIS FILE TO MATCH YOUR CONFIGURATION ########

# To run the examples, you should follow this procedure:

# 1) Optionally, edit the following variables:

#      BIN_DIR = directory where ESPRESSO executables reside
#      PSEUDO_DIR = directory where pseudopotential files reside
#                   if needed pseudopotentials are not found there,
#                   they will be downloaded from NETWORK_PSEUDO
#      TMP_DIR = directory to be used as temporary storage area
#                Make sure that it is writable by you, that it has
#                enough available space to host the temporary files,
#                preferably offering high I/O performance (i.e.,
#                don't use an NFS-mounted directory), and that
#                it doesn't contain any valuable data:
#                EVERYTHING THERE WILL BE DESTROYED

# The default values set below should be good for most cases 

# 2) For parallel execution, edit the following variables:

#      PARA_PREFIX: prepended to the executable name, typically contains
#                   the launcher program and the number of processors
#      PARA_PREFIX: appended to the executable name, typically contains
#                   parallelization options

#  Example: if you need to run the code as 
#     mpirun -np 4 pw.x -nk 1 < file.in > file.out
#  then PARA_PREFIX="mpirun -np 4", PARA_POSTFIX="-nk 1"

#  For execution with OpenMP or mixed MPI/OpenMP, you may also need to set
#      OMP_NUM_THREADS: number of threads for OpenMP parallelization.

#  For serial execution it should not be needed to specify anything.

#  See section "Running on parallel machines" of the user guide
#  for more details

#  BEWARE: most tests and examples are devised to be run serially or on
#  a small number of processors; do not use tests and examples to benchmark
#  parallelism, do not run on too many processors

# 3) To run a single example, go to the corresponding directory (for
#  instance, "example/example01") and execute:

#    ./run_example

#  This will create a subdirectory "results", containing the input and
#  output files generated by the calculation.
#  If your machine does not support interactive use, you must execute 
#  "run_example" throught the batch queueing system running on that machine.
#  Ask your system administrator for instructions.

#   Some examples take only a few seconds to run, while others may
#   require several minutes depending on your system.

# 4) In each example's directory, the "reference" subdirectory contains
#  verified output files, that you can check your results against.

#  Your results might be slightly different from reference results,
#  in particular if different FFT dimensions are automatically selected.
#  For this reason, a plain "diff" of your results against the reference
#  data may not work and human inspection of the results may be needed.

PREFIX=`cd ../../.. ; pwd`
# $PREFIX is the root of the Quantum ESPRESSO source tree.
BIN_DIR=$PREFIX/bin
PSEUDO_DIR=$PREFIX/pseudo
# Beware: everything in $TMP_DIR will be destroyed !
TMP_DIR=$PREFIX/tempdir

PARA_PREFIX=" "
# PARA_PREFIX="mpirun -np 4"

# available flags: 
#                  -ni n        number of images        (or -nimage)
#                               (only for NEB; for PHonon, see below)
#                  -nk n        number of pools         (or -npool, -npools)
#                  -nb n        number of band groups   (or -nbgrp,-nband_group)
#                  -nt n        number of task groups   (or -ntg, -ntask_groups)
#                  -nd n        number of processors for linear algebra 
#                                            (or -ndiag, -northo) 

PARA_POSTFIX=" -nk 1 -nd 1 -nb 1 -nt 1 "

# The following variables are used for image parallelization of PHonon 
# (see example in PHonon/examples/Image_example) 
# NB: the number of processors in PARA_IMAGE_PREFIX is the product of the
# number of processors in PARA_PREFIX and the number of images in
# PARA_IMAGE_POSTFIX

PARA_IMAGE_POSTFIX="-ni 2 $PARA_POSTFIX"
PARA_IMAGE_PREFIX="mpirun -np 4"

# In case of mixed MPI / OpenMP parallelization you may want to limit
# the maximum number to OpenMP threads so that the number of threads
# per MPI process times the number of MPI processes equals the number
# of available cores to avoid hyperthreading

export OMP_NUM_THREADS=1

# There should be no need to change anything below this line

LC_ALL=C
export LC_ALL

NETWORK_PSEUDO=https://pseudopotentials.quantum-espresso.org/upf_files/

# wget or curl needed if some PP has to be downloaded from web site
# script wizard will surely find a better way to find what is available
if test "`which curl`" = "" ; then
   if test "`which wget`" = "" ; then
      echo "wget or curl not found: will not be able to download missing PP"
   else
      WGET="wget -O"
      # echo "wget found"
   fi
else
   WGET="curl -o"
   # echo "curl found"
fi

# function to test the exit status of a job
check_failure () {
    # usage: check_failure $?
    if test $1 != 0
    then
        echo "Error condition encountered during test: exit status = $1"
        echo "Aborting"
        exit 1
    fi
}

