Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add freethreading build and tests #226

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ add_project_arguments(
language : 'cython'
)

# Enable free-threading if Cython is new enough:
#cy = meson.get_compiler('cython')
#if cy.version().version_compare('>=3.1.0')
# add_project_arguments('-Xfreethreading_compatible=true', language : 'cython')
#endif

if get_option('coverage')
add_project_arguments('-X', 'linetrace=True', language : 'cython')
add_project_arguments('-DCYTHON_TRACE=1', language : 'c')
Expand Down
32 changes: 32 additions & 0 deletions src/flint/test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import pickle
import doctest
import platform
import random
from threading import Thread

from flint.utils.flint_exceptions import DomainError, IncompatibleContextError

Expand Down Expand Up @@ -1615,6 +1617,35 @@ def test_pickling():
obj2 = pickle.loads(s)
assert obj == obj2

def test_python_threads():
iterations = 10**5
threads = 3 + 1
size = 3
M = flint.fmpz_mat([[0]*size for _ in range(size)])

def set_values():
for i in range(iterations // 5):
i = random.randrange(M.nrows())
j = random.randrange(M.ncols())
if random.uniform(0, 1) > 0.5:
# Bigger than 2**62:
M[i,j] = 10**128
else:
# Smaller than 2**62:
M[i,j] = 0

def get_dets():
for i in range(iterations):
M.det()

threads = [Thread(target=set_values) for _ in range(threads-1)]
threads.append(Thread(target=get_dets))

for t in threads:
t.start()
for t in threads:
t.join()

def test_fmpz_mod():
from flint import fmpz_mod_ctx, fmpz, fmpz_mod

Expand Down Expand Up @@ -4586,6 +4617,7 @@ def test_all_tests():
test_arb,

test_pickling,
test_python_threads,

test_all_tests,
]
Loading