ocramz / petsc-hs

Haskell bindings for PETSc and SLEPc
GNU General Public License v3.0
20 stars 4 forks source link

Example fails #20

Closed idontgetoutmuch closed 8 years ago

idontgetoutmuch commented 8 years ago

Spoke too soon :(

~/petsc-hs $ stack exec petsc-example
stack exec petsc-example
======
petsc-hs : Haskell bindings for PETSc
petsc-example: Prelude.!!: index too large
ocramz commented 8 years ago

this is strange, it's the same example that runs at the end of th Travis install. Will look into it in the afternoon, thank you

idontgetoutmuch commented 8 years ago

I don't know if this helps

~/petsc-hs/src $ ghci -L/Users/dom/petsc/arch-darwin-c-debug/lib -L/Users/dom/slepc/arch-darwin-c-debug/lib -lpetsc -lslepc
ghci -L/Users/dom/petsc/arch-darwin-c-debug/lib -L/Users/dom/slepc/arch-darwin-c-debug/lib -lpetsc -lslepc
GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
<command line>: user specified .o/.so/.DLL could not be loaded (dlopen(/Users/dom/slepc/arch-darwin-c-debug/lib/libslepc.dylib, 5): Symbol not found: _KSPConvergedReasons
  Referenced from: /Users/dom/slepc/arch-darwin-c-debug/lib/libslepc.dylib
  Expected in: flat namespace
 in /Users/dom/slepc/arch-darwin-c-debug/lib/libslepc.dylib)
Whilst trying to load:  (dynamic) /Users/dom/slepc/arch-darwin-c-debug/lib/libslepc.dylib
Additional directories searched:   /Users/dom/petsc/arch-darwin-c-debug/lib
   /Users/dom/slepc/arch-darwin-c-debug/lib

It seems that ghci is still lying

~/petsc-hs/src $ nm -g /Users/dom/slepc/arch-darwin-c-debug/lib/libslepc.dylib | grep KSPConvergedReasons
nm -g /Users/dom/slepc/arch-darwin-c-debug/lib/libslepc.dylib | grep KSPConvergedReasons
                 U _KSPConvergedReasons
idontgetoutmuch commented 8 years ago

I don't know if this helps but if I try to compile your Black Scholes example

executable bs
  build-depends:       base >=4.7,
                       petsc-hs,
                       containers,
                       transformers,
                       ad,
                       vector,
                       inline-c,
                       bytestring,
                       template-haskell,
                       split,
                       mtl,
                       storable-complex,
                       managed
  default-language:    Haskell2010
  main-is:             Numerical/PETSc/Apps/TaoBlackScholes.hs
  hs-source-dirs:      src
  ghc-options:         -j2 -O2 -Wall
  c-sources:           src/Numerical/PETSc/Internal/InlineC.c
  extra-libraries:     petsc, mpich, slepc

I get

/Users/dom/Library/Haskell/ghc-7.10.3/lib/cabal-install-1.25.0.0/bin/cabal install  --extra-lib-dirs=/Users/dom/petsc/arch-darwin-c-debug/lib --extra-lib-dirs=/Users/dom/slepc/arch-darwin-c-debug/lib --extra-include-dirs=/Users/dom/petsc/include --extra-include-dirs=/Users/dom/slepc/include --extra-include-dirs=/Users/dom/petsc/arch-darwin-c-debug/include --extra-include-dirs=/Users/dom/slepc/arch-darwin-c-debug/include
Warning: The package list for 'hackage.haskell.org' is 25 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
In order, the following will be installed:
petsc-hs-0.1.0.0 (reinstall)
Warning: Note that reinstalls are always dangerous. Continuing anyway...
cabal: Entering directory '.'
Configuring petsc-hs-0.1.0.0...
Building petsc-hs-0.1.0.0...
Preprocessing library petsc-hs-0.1.0.0...
Preprocessing executable 'petsc-example' for petsc-hs-0.1.0.0...
Preprocessing executable 'bs' for petsc-hs-0.1.0.0...
[11 of 27] Compiling Numerical.PETSc.Internal.InlineC ( src/Numerical/PETSc/Internal/InlineC.hs, dist/build/bs/bs-tmp/Numerical/PETSc/Internal/InlineC.o )

<no location info>:
    <command line>: can't load .so/.DLL for: /Users/dom/petsc-hs/dist/build/libHSpetsc-hs-0.1.0.0-CHaQ7GmhWztDLZjIBe9U1K-ghc7.10.3.dylib (dlopen(/Users/dom/petsc-hs/dist/build/libHSpetsc-hs-0.1.0.0-CHaQ7GmhWztDLZjIBe9U1K-ghc7.10.3.dylib, 5): Symbol not found: _CHaQ7GmhWzztDLZZjIBe9U1K_NumericalziPETScziInternalziSparse_zdwvvToCSR_closure
  Referenced from: /Users/dom/petsc-hs/dist/build/libHSpetsc-hs-0.1.0.0-CHaQ7GmhWztDLZjIBe9U1K-ghc7.10.3.dylib
  Expected in: flat namespace
 in /Users/dom/petsc-hs/dist/build/libHSpetsc-hs-0.1.0.0-CHaQ7GmhWztDLZjIBe9U1K-ghc7.10.3.dylib)
cabal: Leaving directory '.'
Failed to install petsc-hs-0.1.0.0
cabal: Error: some packages failed to install:
petsc-hs-0.1.0.0 failed during the building phase. The exception was:
ExitFailure 1
idontgetoutmuch commented 8 years ago

lol and this is why I hate computers - you have to put the libraries in the right order

extra-libraries:     slepc, mpich, petsc

Now I get further with compilation of the Black Scholes example

/Users/dom/Library/Haskell/ghc-7.10.3/lib/cabal-install-1.25.0.0/bin/cabal install  --extra-lib-dirs=/Users/dom/petsc/arch-darwin-c-debug/lib --extra-lib-dirs=/Users/dom/slepc/arch-darwin-c-debug/lib --extra-include-dirs=/Users/dom/petsc/include --extra-include-dirs=/Users/dom/slepc/include --extra-include-dirs=/Users/dom/petsc/arch-darwin-c-debug/include --extra-include-dirs=/Users/dom/slepc/arch-darwin-c-debug/include
Resolving dependencies...
In order, the following will be installed:
petsc-hs-0.1.0.0 (reinstall)
Warning: Note that reinstalls are always dangerous. Continuing anyway...
cabal: Entering directory '.'
Configuring petsc-hs-0.1.0.0...
Building petsc-hs-0.1.0.0...
Preprocessing library petsc-hs-0.1.0.0...
Preprocessing executable 'petsc-example' for petsc-hs-0.1.0.0...
Preprocessing executable 'bs' for petsc-hs-0.1.0.0...
[11 of 27] Compiling Numerical.PETSc.Internal.InlineC ( src/Numerical/PETSc/Internal/InlineC.hs, dist/build/bs/bs-tmp/Numerical/PETSc/Internal/InlineC.o )

<no location info>:
    <command line>: can't load .so/.DLL for: /Users/dom/petsc-hs/dist/build/libHSpetsc-hs-0.1.0.0-CHaQ7GmhWztDLZjIBe9U1K-ghc7.10.3.dylib (dlopen(/Users/dom/petsc-hs/dist/build/libHSpetsc-hs-0.1.0.0-CHaQ7GmhWztDLZjIBe9U1K-ghc7.10.3.dylib, 5): Symbol not found: _CHaQ7GmhWzztDLZZjIBe9U1K_NumericalziPETScziInternalziSparse_zdwvvToCSR_closure
  Referenced from: /Users/dom/petsc-hs/dist/build/libHSpetsc-hs-0.1.0.0-CHaQ7GmhWztDLZjIBe9U1K-ghc7.10.3.dylib
  Expected in: flat namespace
 in /Users/dom/petsc-hs/dist/build/libHSpetsc-hs-0.1.0.0-CHaQ7GmhWztDLZjIBe9U1K-ghc7.10.3.dylib)
cabal: Leaving directory '.'
Failed to install petsc-hs-0.1.0.0
cabal: Error: some packages failed to install:
petsc-hs-0.1.0.0 failed during the building phase. The exception was:
ExitFailure 1
ocramz commented 8 years ago

@idontgetoutmuch The order of the library imports really shouldn't matter, or so I thought until now .. Re. the Black-Scholes example, it's incomplete .It's meant to reproduce https://www.mcs.anl.gov/petsc/petsc-current/src/tao/complementarity/examples/tutorials/blackscholes.c.html , but I haven't gotten around to binding all the necessary library functions.

ocramz commented 8 years ago

@idontgetoutmuch , re. splitting out the B-S example into a separate binary:

It seems like you're not linking the petsc-hs object files (made by inline-c from Internal.hs and InlineC.hs ). stack does it implicitly it seems.

can't load .so/.DLL for: /Users/dom/petsc-hs/dist/build/libHSpetsc-hs-0.1.0.0-CHaQ7GmhWztDLZjIBe9U1K-ghc7.10.3.dylib (dlopen(/Users/dom/petsc-hs/dist/build/libHSpetsc-hs-0.1.0.0-CHaQ7GmhWztDLZjIBe9U1K-ghc7.10.3.dylib, 5): Symbol not found: _CHaQ7GmhWzztDLZZjIBe9U1K_NumericalziPETScziInternalziSparse_zdwvvToCSR_closure
  Referenced from: /Users/dom/petsc-hs/dist/build/libHSpetsc-hs-0.1.0.0-CHaQ7GmhWztDLZjIBe9U1K-ghc7.10.3.dylib

Have a look at the included makefile for the explicit build+link sequence: (step1 : ghc inline-c pass, step2 : CC pass, step3 : ghci pass)

ocramz commented 8 years ago

@idontgetoutmuch I don't understand why you get that error when running petsc-example . Could you be more specific about how you built+linked it? Thank you

idontgetoutmuch commented 8 years ago

I built like this

/Users/dom/Library/Haskell/ghc-7.10.3/lib/cabal-install-1.25.0.0/bin/cabal
install --extra-lib-dirs=/Users/dom/petsc/arch-darwin-c-debug/lib
--extra-lib-dirs=/Users/dom/slepc/arch-darwin-c-debug/lib
--extra-include-dirs=/Users/dom/petsc/include
--extra-include-dirs=/Users/dom/slepc/include
--extra-include-dirs=/Users/dom/petsc/arch-darwin-c-debug/include
--extra-include-dirs=/Users/dom/slepc/arch-darwin-c-debug/include

And then ran it like this.

~/Library/Haskell/ghc-7.10.3/lib/petsc-hs-0.1.0.0/bin/petsc-example 
======
petsc-hs : Haskell bindings for PETSc
petsc-example: Prelude.!!: index too large

Maybe I should just start over. That way I can keep an exact log of what happens. Can you tell me exactly which petsc commit to use and which slepc commit to use? Or tarballs. I guess I should use HEAD for petsc-hs?

I am particularly interested in the Black Scholes example as I want to solve some diffusions.

I am not clear why there is a makefile. Shouldn't stack do everything?

One thing I might try is the Black Scholes example in C. If that fails then we know my installation of petsc and slepc are borked.

idontgetoutmuch commented 8 years ago

The first petsc example in C I tried works https://www.mcs.anl.gov/petsc/documentation/tutorials/HandsOnExercise.html

~/petsc/src/ksp/ksp/examples/tutorials $ /Users/dom/petsc/arch-darwin-c-debug/bin/mpiexec -n 1 ./ex50  -da_grid_x 4 -da_grid_y 4 -mat_view 
/Users/dom/petsc/arch-darwin-c-debug/bin/mpiexec -n 1 ./ex50  -da_grid_x 4 -da_grid_y 4 -mat_view 
Mat Object: 1 MPI processes
  type: seqaij
row 0: (0, 0)  (1, 0)  (4, 0) 
row 1: (0, 0)  (1, 0)  (2, 0)  (5, 0) 
row 2: (1, 0)  (2, 0)  (3, 0)  (6, 0) 
row 3: (2, 0)  (3, 0)  (7, 0) 
row 4: (0, 0)  (4, 0)  (5, 0)  (8, 0) 
row 5: (1, 0)  (4, 0)  (5, 0)  (6, 0)  (9, 0) 
row 6: (2, 0)  (5, 0)  (6, 0)  (7, 0)  (10, 0) 
row 7: (3, 0)  (6, 0)  (7, 0)  (11, 0) 
row 8: (4, 0)  (8, 0)  (9, 0)  (12, 0) 
row 9: (5, 0)  (8, 0)  (9, 0)  (10, 0)  (13, 0) 
row 10: (6, 0)  (9, 0)  (10, 0)  (11, 0)  (14, 0) 
row 11: (7, 0)  (10, 0)  (11, 0)  (15, 0) 
row 12: (8, 0)  (12, 0)  (13, 0) 
row 13: (9, 0)  (12, 0)  (13, 0)  (14, 0) 
row 14: (10, 0)  (13, 0)  (14, 0)  (15, 0) 
row 15: (11, 0)  (14, 0)  (15, 0) 
Mat Object: 1 MPI processes
  type: seqaij
row 0: (0, 2)  (1, -1)  (4, -1) 
row 1: (0, -1)  (1, 3)  (2, -1)  (5, -1) 
row 2: (1, -1)  (2, 3)  (3, -1)  (6, -1) 
row 3: (2, -1)  (3, 2)  (7, -1) 
row 4: (0, -1)  (4, 3)  (5, -1)  (8, -1) 
row 5: (1, -1)  (4, -1)  (5, 4)  (6, -1)  (9, -1) 
row 6: (2, -1)  (5, -1)  (6, 4)  (7, -1)  (10, -1) 
row 7: (3, -1)  (6, -1)  (7, 3)  (11, -1) 
row 8: (4, -1)  (8, 3)  (9, -1)  (12, -1) 
row 9: (5, -1)  (8, -1)  (9, 4)  (10, -1)  (13, -1) 
row 10: (6, -1)  (9, -1)  (10, 4)  (11, -1)  (14, -1) 
row 11: (7, -1)  (10, -1)  (11, 3)  (15, -1) 
row 12: (8, -1)  (12, 2)  (13, -1) 
row 13: (9, -1)  (12, -1)  (13, 3)  (14, -1) 
row 14: (10, -1)  (13, -1)  (14, 3)  (15, -1) 
row 15: (11, -1)  (14, -1)  (15, 2) 
ocramz commented 8 years ago

I'm currently testing against PETSc 3.6.3 and SLEPc 3.6.1 ; please use HEAD for petsc-hs (what version were you using so far? I'm positive the latest petsc-example binary or its internals don't use lists .. ) . Yes, currently stack coordinates all the compilation+linking, the makefile is just there for experimentation.

idontgetoutmuch commented 8 years ago

I seem to be using PETSc 3.6.3 and SLEPc 3.6.3. I am using HEAD for petsc-hs. There must be a list hiding somewhere to give that error message. Maybe in a library?

-----------------------------------------
SLEPC_VERSION_RELEASE    1
SLEPC_VERSION_MAJOR      3
SLEPC_VERSION_MINOR      6
SLEPC_VERSION_SUBMINOR   3
SLEPC_VERSION_PATCH      0
SLEPC_VERSION_DATE       "unknown"
SLEPC_VERSION_GIT        "unknown"
SLEPC_VERSION_DATE_GIT   "unknown"
SLEPC_VERSION_(MAJOR,MINOR,SUBMINOR) \
SLEPC_VERSION_LT(MAJOR,MINOR,SUBMINOR)          \
SLEPC_VERSION_LE(MAJOR,MINOR,SUBMINOR) \
SLEPC_VERSION_GT(MAJOR,MINOR,SUBMINOR) \
SLEPC_VERSION_GE(MAJOR,MINOR,SUBMINOR) \
-----------------------------------------
PETSC_VERSION_RELEASE    1
PETSC_VERSION_MAJOR      3
PETSC_VERSION_MINOR      6
PETSC_VERSION_SUBMINOR   3
PETSC_VERSION_PATCH      0
PETSC_VERSION_DATE       "unknown"
PETSC_VERSION_GIT        "unknown"
PETSC_VERSION_DATE_GIT   "unknown"
PETSC_VERSION_(MAJOR,MINOR,SUBMINOR) \
PETSC_VERSION_LT(MAJOR,MINOR,SUBMINOR)          \
PETSC_VERSION_LE(MAJOR,MINOR,SUBMINOR) \
PETSC_VERSION_GT(MAJOR,MINOR,SUBMINOR) \
PETSC_VERSION_GE(MAJOR,MINOR,SUBMINOR) \
ocramz commented 8 years ago

@idontgetoutmuch I'm not sure; at any rate, I don't see this error :/ completely stumped. Is there a way of getting a stack trace from ghc?

idontgetoutmuch commented 8 years ago

I am going to have to give up for now. Maybe we should try again in a few weeks with PETSc 3.7 and SLEPc 3.7 when they are released? Alternatively I have signed up for the beta docker for Mac. If docker accept me then we could try via docker assuming your docker image is up to date.

ocramz commented 8 years ago

Hi again, there's nothing wrong with 3.6.*, nor do you need docker beta account to run. It must be a bug in my code. Ill investigate

ocramz commented 8 years ago

@idontgetoutmuch Apologies if I sounded rude, I was typing from my phone and had to give a presentation in 5 minutes. What I wanted to say is that there's nothing wrong with PETSc 3.6.* for how I'm using it at this stage; the functions I've tested so far all work. 3.7 introduces changes in some rather specialized parts of the API. Re. the Docker side, you can use it perfectly well today via the https://www.docker.com/products/docker-toolbox ; it's free and works out of the box on OSX. After you've got it running you can try out a pre-compiledpetsc-hs by running

$ docker pull ocramz/petsc-hs-docker
idontgetoutmuch commented 8 years ago
Dominics-MacBook-Pro:petsc-hs dom$ docker run ocramz/petsc-hs-docker stack exec petsc-example
======
petsc-hs : Haskell bindings for PETSc
PETSc 3.6.2, rel. Oct 02 2015: initialized with default options

t7'
  computes the inner product of two orthogonal vectors in R2

Finished in 0.0521 seconds
1 example, 0 failures

PETSc : finalized
======
ocramz commented 8 years ago

Yay! Now I'd just like to understand why it doesn't run on your own box. The Docker image you've just run contains the same code as the one you were trying to build and run the other day.

idontgetoutmuch commented 8 years ago

I am not going to try to debug that any time soon. I can now get on and solve some diffusions from Haskell. I don't need anything as good as their BS example though. My boundary conditions are much simpler. It would be nice to be able price American Options though :-)

What do you want to do about this ticket? My suggestion would be to close it. Maybe when SLEPc 3.7 is released and you have updated petsc-hs to run against PETSc and SLEPc 3.7 we can try again. One thing we ought to check is my set up. I think I have been jumping between cabal and stack and I also have multiple versions of ghc lying around. But I don't have time to investigate at the moment. Oh we should be able to move to ghc 8 at that point also.