setmooseenv.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #################################################
  2. # This scripts sets an environment to work with #
  3. # Python 2.7, Clang, OpenMPI and PETSc #
  4. # #
  5. # To use, run #
  6. # source <this_script> #
  7. #################################################
  8. # Compiler Variables
  9. # Set MPI with Clang
  10. export OMPI_CC=clang
  11. export OMPI_CXX=clang++
  12. # Use MPI
  13. export CC=mpicc
  14. export CXX=mpicxx
  15. export FC=mpif90
  16. export F77=mpif77
  17. export F90=mpif90
  18. # PETSc
  19. export PETSC_DIR=/opt/petsc/linux-c-opt
  20. # JOB Count (the number of cores available on this machine)
  21. export MOOSE_JOBS=4
  22. # Set the default language to English (useful when
  23. # communicating with moose-users and moose-devs)
  24. export LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8
  25. # Load the virtual environment (for installation, see
  26. # https://wiki.archlinux.org/index.php/Python/Virtual_environment)
  27. # * Get Python version (select only the second column, space
  28. # as separator)
  29. pyver=$(python --version |
  30. awk -F" " '{print $NF}')
  31. if [[ ! "$pyver" == 2.* ]]; then
  32. # MOOSE needs python2.7
  33. # Check if python2.7 is available
  34. # * Preset a value
  35. py2=python2.7;
  36. # * Erase preset, if there is no executable
  37. which "$py2" &>/dev/null || py2="";
  38. # * Check if the dummy variable was set (if there
  39. # * is python2.7)
  40. if [[ -z "$py2" ]]; then
  41. # Print warning and exit if there is no python2.7
  42. printf "MOOSE needs python2.7, ";
  43. printf "and it seems that it is not ";
  44. printf "available.\n";
  45. # * If python2.7 exists, check for virtualenv
  46. # * (send any error output to a hole)
  47. elif [[ $(which virtualenv 2>/dev/null) ]]; then
  48. # ** If python3 is default, there is virtualenv
  49. # ** and python2.7 is available, use or create virtual
  50. # ** environment for python2.7
  51. printf "MOOSE needs python2.7, checking for ";
  52. printf "virtualenv.\n";
  53. # TODO
  54. printf "(This code is dumb, ";
  55. if [ -f venv/bin/activate ] && \
  56. [ -f venv/bin/"$py2" ]; then
  57. printf "found venv/bin/$py2, ";
  58. printf "using venv/bin/activate).\n";
  59. else
  60. printf "it may be that you already ";
  61. printf "have a virtual environment, sorry).\n";
  62. virtualenv -p "$py2" venv || exit
  63. printf "Making the virtualenv relocatale (relative ";
  64. printf ".pth files)\n";
  65. virtualenv --relocatable -p "$py2" venv || exit;
  66. # Could not create virtual environment
  67. fi;
  68. printf "Activating the virtual environment\n"
  69. source venv/bin/activate || exit;
  70. # Exits here if virtual environment didn't run
  71. else
  72. printf "MOOSE needs python2.7, ";
  73. printf "and it seems that virtualenv is not ";
  74. printf "available.\n";
  75. fi;
  76. fi
  77. printf "Virtual environment ready\n";