precice / PreCICE.jl

Julia language bindings for preCICE
GNU Lesser General Public License v3.0
11 stars 1 forks source link

Problem finding preCICE binary #16

Closed BenjaminRodenberg closed 2 years ago

BenjaminRodenberg commented 2 years ago

I tried to install the julia bindings, but in the end the preCICE binary could not be found:

$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.7.2 (2022-02-06)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using PreCICE
ERROR: ArgumentError: Package PreCICE not found in current path:
- Run `import Pkg; Pkg.add("PreCICE")` to install the PreCICE package.

Stacktrace:
 [1] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:967

(@v1.7) pkg> add https://github.com/precice/julia-bindings.git
    Updating git-repo `https://github.com/precice/julia-bindings.git`
    Updating registry at `~/.julia/registries/General`
    Updating git-repo `https://github.com/JuliaRegistries/General.git`
   Resolving package versions...
    Updating `~/.julia/environments/v1.7/Project.toml`
  [57fbd4af] + PreCICE v0.1.0 `https://github.com/precice/julia-bindings.git#main`
    Updating `~/.julia/environments/v1.7/Manifest.toml`
  [57fbd4af] + PreCICE v0.1.0 `https://github.com/precice/julia-bindings.git#main`

julia> using PreCICE

julia> PreCICE.createSolverInterface("a","b",0,1)
ERROR: could not load library "/usr/local/lib/libprecice.a"
/usr/local/lib/libprecice.a.so: cannot open shared object file: No such file or directory
Stacktrace:
 [1] createSolverInterface(participantName::String, configFilename::String, solverProcessIndex::Int64, solverProcessSize::Int64)
   @ PreCICE ~/.julia/packages/PreCICE/oRAOP/src/PreCICE.jl:82
 [2] top-level scope
   @ REPL[4]:1

I think it is strange that julia seems to be looking for a .a.so file: /usr/local/lib/libprecice.a.so.

If I look into the folder, I find a libprecice.a and a libprecice.so but, of course no libprecice.a.so:

$ ls /usr/local/lib/
...    libprecice.a   libprecice.so.2      libprecice.so.2.2.1  libprecice.so  libprecice.so.2.2.0  libprecice.so.2.3.0 ...

I also tried removing the libprecice.a and also the other unrelated .so files, but with the same problems.

erikscheurer commented 2 years ago

I suspect, that this is because julia looks for a shared object library but finds a static library. Loading the library automatically adds the .so when not already given. What is the result of whereis libprecice on your machine? What also could work is following the instructions for a custom precice path. Here the path (in your case /usr/local/lib/) gets concatenated with a hard-coded libprecice.so. This hardcoded method should probably also be modified to allow for custom precice versions and shared libraries, right?

IshaanDesai commented 2 years ago

I suspect, that this is because julia looks for a shared object library but finds a static library. Loading the library automatically adds the .so when not already given.

Do we know why Julia behaves like this? Ideally we would like if Julia only looks for the shared library file and not the static library file. Is there perhaps a default option in Julia which we could set?

What also could work is following the instructions for a custom precice path. Here the path (in your case /usr/local/lib/) gets concatenated with a hard-coded libprecice.so. This hardcoded method should probably also be modified to allow for custom precice versions and shared libraries, right?

I think the hard-coding of /libprecice.so at the end of this path is alright, because we expect the file to be present irrespective of where the installation is done.

erikscheurer commented 2 years ago

At the moment, the location of the shared library is determined through the terminal command whereis libprecice. However, this command also returns the libprecice.a file. Julia only works with shared libraries as far as I know. One possible fix for this would be to change the whereis command to the julia command Libc.Libdl.find_library("libprecice"). This only returns a library if julia is able to open it. Also, this could make the installation with a custom library path easier. find_library searches in the System library paths. If the user has precice in LD_LIBRARY_PATH as stated in the precice installation guide, Julia should probably be able to find it? Its hard for me to make sure all I'm saying is true, because I'm not sure how to recreate this error.

erikscheurer commented 2 years ago

@BenjaminRodenberg, Could you try whether the bindings work on the find_binary branch? There the ccall is reverted to a previous state, where the library is not given by a path but lets julia search in the system library path for "libprecice".

erikscheurer commented 2 years ago

My own tests conclude that the branch above should work, as it doesn't rely on the whereis command. I'm going to open a pull request. This way, I'm not even sure if the build installations for a custom PreCICE path are correct. As long as the PreCICE Library is in the system library path, julia finds it.

BenjaminRodenberg commented 2 years ago

@erikscheurer I just tried it out and I cannot see any more problems:

$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.7.2 (2022-02-06)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(@v1.7) pkg> add https://github.com/precice/julia-bindings.git#find_binary
    Updating git-repo `https://github.com/precice/julia-bindings.git`
    Updating registry at `~/.julia/registries/General`
    Updating git-repo `https://github.com/JuliaRegistries/General.git`
   Resolving package versions...
    Updating `~/.julia/environments/v1.7/Project.toml`
  [57fbd4af] ~ PreCICE v0.1.0 `https://github.com/precice/julia-bindings.git#main` ⇒ v0.1.0 `https://github.com/precice/julia-bindings.git#find_binary`
    Updating `~/.julia/environments/v1.7/Manifest.toml`
  [57fbd4af] ~ PreCICE v0.1.0 `https://github.com/precice/julia-bindings.git#main` ⇒ v0.1.0 `https://github.com/precice/julia-bindings.git#find_binary`
    Building PreCICE → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/5594eecf798bc9fea0d7b263858f37d0d1b20286/build.log`
Precompiling project...
  1 dependency successfully precompiled in 1 seconds (4 already precompiled)

julia> using Pr
PreCICE Printf   Profile
julia> using Pr
PreCICE Printf   Profile
julia> using PreCICE

julia> PreCICE.createSolverInterface("a", "b", 0,1)
(0) 16:12:08 [xml::XMLParser]:152 in readXmlFile: ERROR: XML parser was unable to open configuration file "b"

If I use the branch find_binary, preCICE explodes in the expected way.

However, I also tried using main and got the same (correct) output:

$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.7.2 (2022-02-06)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(@v1.7) pkg> add https://github.com/precice/julia-bindings.git
    Updating git-repo `https://github.com/precice/julia-bindings.git`
    Updating registry at `~/.julia/registries/General`
    Updating git-repo `https://github.com/JuliaRegistries/General.git`
   Resolving package versions...
    Updating `~/.julia/environments/v1.7/Project.toml`
  [57fbd4af] ~ PreCICE v0.1.0 `https://github.com/precice/julia-bindings.git#find_binary` ⇒ v0.1.0 `https://github.com/precice/julia-bindings.git#main`
    Updating `~/.julia/environments/v1.7/Manifest.toml`
  [57fbd4af] ~ PreCICE v0.1.0 `https://github.com/precice/julia-bindings.git#find_binary` ⇒ v0.1.0 `https://github.com/precice/julia-bindings.git#main`
    Building PreCICE → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/869eed779b0876ea91fabdc9945c337416a08dac/build.log`
Precompiling project...
  1 dependency successfully precompiled in 1 seconds (4 already precompiled)

julia> using PreCICE

julia> PreCICE.createSolverInterface("a", "b", 0,1)
(0) 16:16:46 [xml::XMLParser]:152 in readXmlFile: ERROR: XML parser was unable to open configuration file "b"

I also checked 81199ced9975e582492de04b14046f7068d40396, 3a242075444de9d096739ce152df6266674efba0 and 46869316f076fcb1e05f203ea7a9a903d8bacc14, but also got the correct output. This means: I cannot really reproduce the issue anymore on my system anymore.

IshaanDesai commented 2 years ago

This problem cannot be reproduced at the moment so I am closing this issue. If this problem is encountered in the future, we can reopen this issue and continue the discussion.