Using PETSc under Cygwin

1

I'm trying to get PETSc running under Cygwin on my Windows machine to test parallel code. Unfortunately there's a problem where Cygwin is importing elements from my Windows path of the form:

C:\Program Files (x86)\...

And the problem is that the PETSc and MPI compilers are falling on their faces because they don't invoke cygpath to fix the " " characters. So, I need help with one of three things:

  1. How to get Cygwin to not load the Windows path

    • I put it on its own partition and am trying to use only native Cygwin compilers so it could, hopefully, live without knowing much about Windows.
  2. Rewrite my PATH variable to escape all the " " characters by replacing them with "\ "

I know this:

       echo $PATH | sed 's/ /\\ /g'

Does exactly what I need, but I can't get it to execute as an "export PATH=" command in .bashrc. I've tried:

export PATH='echo $PATH | sed '"'"'s/ /\\ /g'"'"' '

Which just breaks my Cygwin session to the point that I need to repair .bashrc in Notepad++ to boot again

export PATH="echo $PATH | sed 's/ /\\ /g'"

Which just prepends "echo " and appends " | sed 's/\ /g" to PATH.

export PATH='echo $PATH | sed "s/ /\\ /g"'

Which replaces my entire path with just "echo $PATH | sed "/\ /g"

  1. Something I haven't thought of at all.

Any help would be greatly appreciated.

Thulkos

Posted 2016-09-14T03:28:09.987

Reputation: 13

you can redefine PATH on you startup scripts. Usually that is already available , which shell are you using ? – matzeri – 2016-09-14T06:19:45.983

To set a variable to output from a command, called 'command substitution', use backquotes (which I can't easily show because stack markdown uses them, but on US keyboard the key at the top left not the one next to Enter) or usually better dollar-parentheses PATH=$( echo $PATH | sed ... ). But you don't need to run any command for this, bash can do it: PATH=${PATH// /\\ } And personally when I have a choice I just use the shortname e.g. C:\Progra~2\Whatever and avoid the problem. – dave_thompson_085 – 2016-09-14T06:49:01.120

Answers

0

How to get Cygwin to not load the Windows path

For the bash shell this can be done by making some small changes to ~/.bash_profile.

I like to have complete control over the PATH in Cygwin bash, so I added the following code to my ~/.bash_profile

# Build up the path using the directories in ~/.path_elements
unset PATH
while read line; do 
  PATH="${PATH}$line"; 
done < ~/.path_elements

# Add current directory to path
export PATH=".:${PATH}"

Notes:

  • unset PATH removes any PATH already configured by the Cygwin startup code.

  • The while loop reads in path elements from a file in my home directory (~/.path_elements) to build up my preferred PATH

  • Finally we add the current directory . to the PATH and export it.

  • Adding the current directory to the PATH could be considered as a security risk since built in commands could be replaced by commands located in the current directory. Please bear that in mind if you choose to use my code.

The contents of my ~/.path_elements are as follows. Modify and season to your taste to add extra elements to the path.

/home/DavidPostill/bin:
/usr/local/bin:
/usr/bin:
/c/Windows/system32:
/c/Windows

Result:

DavidPostill@Hal /f/test
$ echo $PATH
.:/home/DavidPostill/bin:/usr/local/bin:/usr/bin:/c/Windows/system32:/c/Windows

DavidPostill

Posted 2016-09-14T03:28:09.987

Reputation: 118 938

As PETSC is like connected to other math library, "usr/lib/lapack" could also be need for Lapack – matzeri – 2016-09-14T12:16:48.567

@matzeri Libraries are not normally added to PATH... – DavidPostill – 2016-09-14T12:18:24.147

shared lib yes. It is the reason why major cyg*dll's are in "/usr/bin" and not in "/usr/lib". Lapack as package has an exception to avoid collision with other optimized BLAS. https://cygwin.com/packages/x86_64/liblapack0/liblapack0-3.6.1-1 It was like that from the origin: https://cygwin.com/ml/cygwin-apps/2005-06/msg00198.html

– matzeri – 2016-09-14T12:28:42.370

@matzeri Fair enough. I did say "Modify and season to your taste to add extra elements to the path." in the answer ;p – DavidPostill – 2016-09-14T12:29:59.673

@DavidPostill Works like a dream. The installer for PETSc still doesn't behave super well under Cygwin so I had to add the petsc/.../lib and petsc/.../bin directories to PATH as well. – Thulkos – 2016-09-15T00:43:14.460