0

Can anyone help me set the environmental variables for configuring the software SLEPc (a library for the solution of large sparse eigenproblems on parallel computers). I am using in Ubuntu 16.04 LTS.

I have used petsc-3.2 Docs: Installation and PETSc Documentation: Installation pages as a guideline, where it states:

specify enviornment variable for csh/tcsh [can be specified in ~/.cshrc]

setenv PETSC_DIR /home/balay/petsc-3.7.0
setenv PETSC_ARCH linux-gnu-c-debug

specify enviornment variable for bash [can be specified in ~/.bashrc]

export PETSC_DIR=/home/balay/petsc-3.7.0
export PETSC_ARCH=linux-gnu-c-debug

I get error message:

$ ./configure
Checking environment...
ERROR: PETSC_DIR enviroment variable is not set

I have added to the end of my ~/.bashrc file the following:

export SLEPC_DIR=/home/brendan/Documents/slepc/slepc
export PETSC_DIR=/home/brendan/Documents/petsc_2/petsc
export PETSC_ARCH=/home/brendan/Documents/petsc_2/petsc/arch-linux2-c-debug

and to my ~/.cshrc file:

setenv SLEPC_DIR=/home/brendan/Documents/slepc/slepc
setenv PETSC_DIR=/home/brendan/Documents/petsc_2/petsc
setenv PETSC_ARCH=/home/brendan/Documents/petsc_2/petsc/arch-linux2-c-debug
  • If the './configure' is a bash can you run 'bash -x ./configure' and show us the output. Also please show us the outpout of 'env|egrep PETSC_DIR ' – Aleksandar Mar 13 '17 at 12:35
  • ...that said, testing would indeed be useful. `declare -p PETSC_DIR` will show both the value for the variable *and* whether it's exported (`declare -x PETSC_DIR=...` indicates that it's exported; `declare -- PETSC_DIR=...` indicates otherwise). – Charles Duffy Mar 13 '17 at 12:45
  • @Aleks, this particular `configure` script isn't written in a shell language at all, so `bash -x configure` won't be helpful. See https://bitbucket.org/petsc/petsc/src/dcd36c237939d4bae4c670048cc3c33706a8123f/configure?at=master&fileviewer=file-view-default – Charles Duffy Mar 13 '17 at 12:47
  • I have the following outputs: `$ bash -x ./configure + import sys ./configure: line 4: syntax error near unexpected token (' ./configure: line 4: `if not type(sys.version_info) is tuple and sys.version_info.major > 2:' $ env|egrep PETSC_DIR` PETSC_DIR=/home/brendan/Documents/petsc_2/petsc` – Brendan Darrer Mar 13 '17 at 12:50
  • 'import sys' looks to a python script for me. what'st the shebang line, that's the first lines of the script. What's the ouput of 'egrep PETSC_DIR ./configure'. It looks to me that the python script './configure' does not recognize that env var. What does the SLEPc guys mean to your problem? – Aleksandar Mar 13 '17 at 13:51
  • I'm working on setting up MIT image reconstruction software, using the forward and inverse solvers @ [MIT_Inverse](https://github.com/rosskynch/MIT_Inverse) . It requires [finite element meshing code - dealii](http://www.dealii.org/8.4.1/readme.html) to run; that includes most of the 'Optional interfaces to other software packages' on this page. I contacted the author and he said most of them are straight forward to install but some of them are difficult such as PETSc, I think he meant SLEPc. – Brendan Darrer Mar 13 '17 at 22:44

2 Answers2

2

~/.bashrc is the wrong place to configure environment variables -- it's sourced for non-login interactive shells. However, if your platform is MacOS, each Terminal instance starts a login shell, so it sources ~/.bash_profile, not ~/.bashrc. (You might want to create a ~/.bash_profile that sources ~/.bashrc when done, if on such a platform).

Even on more conventional Unix desktops, using ~/.bash_profile is preferable for environment variables -- it's run only once when you log in there, vs on every new interactive shell's creation (every new tab/window, etc). Because environment variables are inherited by child processes (through the process environment), there's no need to export them more than once per process tree.


By the way -- reading through the relevant configure script, it appears to actually be reading PETSC_DIR and PETSC_ARCH off the configure script's command line, not from the environment. Running ./configure PETSC_DIR="$PETSC_DIR" PETSC_ARCH="$PETSC_ARCH" is thus liable to be helpful.

Passing a fully-qualified path, when that's what you've used successfully in the past, is likewise liable to be helpful.

Charles Duffy
  • 235,655
  • 34
  • 305
  • 356
  • I have removed the code from ~/.bashrc and ~/.cshrc and exported the directories to ~/.bash_profile, with the new output:...... `$ ./configure PETSC_DIR=/home/brendan/Documents/petsc_2/petsc PETSC_ARCH=/home/brendan/Documents/petsc_2/petsc/arch-linux2-c-debug ERROR: Invalid arguments PETSC_DIR=/home/brendan/Documents/petsc_2/petsc PETSC_ARCH=/home/brendan/Documents/petsc_2/petsc/arch-linux2-c-debug Use -h for help` – Brendan Darrer Mar 13 '17 at 13:22
  • the vars should be before the script. 'PETSC_DIR=/home/brendan/Documents/petsc_2/petsc PETSC_ARCH=/home/brendan/Documents/petsc_2/petsc/arch-linux2‌​-c-debug ./configure' – Aleksandar Mar 13 '17 at 13:52
  • @Aleks, actually, no, the advice to put them on the command line rather than in the environment was deliberate. See the code at https://bitbucket.org/petsc/petsc/src/ae618e6989482e576d696b8985b6d772300e3607/config/configure.py?at=v3.7&fileviewer=file-view-default#configure.py-48, which is looking for `PETSC_ARCH=` **on `sys.argv`**, not in the environment. (Both autoconf-generated configure scripts and traditional Makefiles accept overrides this way, so it's not a huge surprise to see it implemented here). – Charles Duffy Mar 13 '17 at 14:05
  • ...the error message referencing the environment is thus surprising, but... well, this doesn't give the appearance of being particularly well-engineered software. – Charles Duffy Mar 13 '17 at 14:08
  • 1
    Ah I see what you mean. PETSC_DIR should be on env https://bitbucket.org/petsc/petsc/src/ae618e6989482e576d696b8985b6d772300e3607/config/configure.py?at=v3.7&fileviewer=file-view-default#configure.py-340 how about to run something like this 'PETSC_DIR=/home/brendan/Documents/petsc_2/petsc ./configure PETSC_ARCH=/home/brendan/Documents/petsc_2/petsc/arch-linux2‌​-c-debug' – Aleksandar Mar 13 '17 at 14:25
0

I have deleted the setenv code in ~/.cshrc and added to the end of ~/.bashrc file the following:

export SLEPC_DIR=/home/brendan/Documents/slepc/slepc
export PETSC_DIR=/home/brendan/Documents/petsc_2/petsc
export PETSC_ARCH=arch-linux2-c-debug

I then entered source ~/.bashrc to reload .bashrc and:

$ ./configure PETSC_DIR=/home/brendan/Documents/petsc_2/petsc PETSC_ARCH=/home/brendan/Documents/petsc_2/petsc/arch-linux2-c-debug

gives:

ERROR: Invalid arguments PETSC_DIR=/home/brendan/Documents/petsc_2/petsc PETSC_ARCH=/home/brendan/Documents/petsc_2/petsc/arch-linux2-c-debug
Use -h for help

So then I tried ./configure only. It gives:

$ ./configure
Checking environment... done
Checking PETSc installation... done
Checking LAPACK library... done
Writing various configuration files... done
Generating Fortran stubs... done

===============================================================================
SLEPc Configuration
===============================================================================

SLEPc directory:
 /home/brendan/Documents/slepc/slepc
  It is a git repository on branch: master
PETSc directory:
 /home/brendan/Documents/petsc_2/petsc
  It is a git repository on branch: master
Architecture "arch-linux2-c-debug" with double precision real numbers

xxx=========================================================================xxx
 Configure stage complete. Now build the SLEPc library with (gnumake build):
   make SLEPC_DIR=$PWD PETSC_DIR=/home/brendan/Documents/petsc_2/petsc PETSC_ARCH=arch-linux2-c-debug
xxx=========================================================================xxx

I think the source ~/.bashrc worked with ./configure !

Community
  • 1
  • 1