anntzer / redeal

A reimplementation of Thomas Andrews' Deal in Python.
Other
63 stars 41 forks source link

Problems in Ubuntu #15

Closed ivannp closed 5 years ago

ivannp commented 5 years ago

Great idea to get away from the tcl deal!!

I was able to install and run it in windows.

In ubuntu 18.04, the run succeeds but there is a segmentation fault at the end:

♠65♡J63♢KT98♣6432 ♠J72♡T75♢AJ2♣AQT9 ♠AKT943♡82♢43♣K85 ♠Q8♡AKQ94♢Q765♣J7

Tries: 10
Segmentation fault (core dumped)

In ubuntu 16.04, it fails without generating any hands:

Memory::GetPtr: 0 vs. 0
Memory::GetPtr: 0 vs. 0

Any idea what's going on? Or how to debug it?

In all cases I am running it from anaconda environment.

anntzer commented 5 years ago

I know about the segfault at exit, but am not sure about how to fix it. Looks like something with threading setup/teardown in dds code. Can you try applying the following patch

diff --git i/redeal/dds.py w/redeal/dds.py
index 0543db6..e2dfb65 100644
--- i/redeal/dds.py
+++ w/redeal/dds.py
@@ -170,8 +170,7 @@ if dll_name and os.path.exists(dll_path):
         Deal, c_int, c_int, c_int, POINTER(FutureTricks), c_int]
     dll.SolveBoardPBN.argtypes = [
         DealPBN, c_int, c_int, c_int, POINTER(FutureTricks), c_int]
-    if os.name == "posix":
-        dll.SetMaxThreads(0)
+    dll.SetThreading(0)
 else:
     def solve(deal, strain, declarer):
         raise Exception("Unable to load DDS.  `solve` is unavailable.")

or alternatively call dll.SetMaxThreads(1) instead of SetMaxThreads(0)?

Another option would be to remove the args "THREADING=", "CC_BOOST_LINK=" in setup.py (which disable multithreading) in setup.py, although I'd rather avoid that as that would mean requiring additional headers at build time.

Let me know if any of these work for you.

ivannp commented 5 years ago

On 18.04 I tracked the segfault down to a problem with tracking the number of threads and allocated structures.

At the moment I don't need the dds portion of redeal, I am trying to see how feasible is to move my old deal scripts (a lot) to python. If things still don't work, I will deal with it once I get to the dds functionality.

anntzer commented 5 years ago

Thanks for opening the PR on the dds repo, feel free to ping me when they merge it so that I update the version here as well.

gkby79 commented 2 years ago

I think the threading checks go wrong when several copies of the library are loaded and SetMaxThreads is called more than once - in particular, I had them loaded once from ddstable and once from redeal, and it didn't work, which may or may not be your use-case. If I explicitly load each of the libraries one by one and call SetMaxThreads twice it fails

DLL = ctypes.CDLL

Fails:

dll_path1 = "[snip]/ddstable/libdds.so" dll_path2 = "[snip]/redeal/libdds.so" dll1 = DLL(dll_path1) dll2 = DLL(dll_path2) dll1.SetMaxThreads(0) dll2.SetMaxThreads(0)

Also fails:

dll_path1 = "[snip]/ddstable/libdds.so" dll_path2 = "[snip]/ddstable/libdds.so" dll1 = DLL(dll_path1) dll2 = DLL(dll_path2) dll1.SetMaxThreads(0) dll2.SetMaxThreads(0)

Works:

dll_path1 = "[snip]/ddstable/libdds.so" dll_path2 = "[snip]/ddstable/libdds.so" dll1 = DLL(dll_path1) dll2 = DLL(dll_path2) dll1.SetMaxThreads(0)

anntzer commented 2 years ago

This looks like a bug in dds itself, and unrelated to redeal itself? You should probably report this to https://github.com/dds-bridge/dds.

gkby79 commented 2 years ago

Yes I think so, I reported it to the DDS list