Skip to content

Commit

Permalink
Merge pull request #591 from carterbox/separate-libtomo
Browse files Browse the repository at this point in the history
BUG: Don't require absolute path for shared libraries
  • Loading branch information
carterbox committed Sep 27, 2022
2 parents a1e402d + a969ea2 commit c10a63e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion envs/win-37.yml
Expand Up @@ -22,5 +22,5 @@ dependencies:
- mkl
- mkl-devel
- mkl_fft
- opencv>=3.4
- opencv>=3.4,<4.2
- pytest
10 changes: 8 additions & 2 deletions source/tomopy/recon/algorithm.py
Expand Up @@ -439,9 +439,15 @@ def _dist_recon(tomo, center, recon, algorithm, args, kwargs, ncore, nchunk):
else:
# execute recon on ncore threads
with cf.ThreadPoolExecutor(ncore) as e:
for slc in use_slcs:
futures = [
e.submit(algorithm, tomo[slc], center[slc], recon[slc],
*args, **kwargs)
*args, **kwargs) for slc in use_slcs
]
done, _ = cf.wait(futures, return_when=cf.ALL_COMPLETED)
for f in done:
if f.exception() is not None:
raise f.exception()


if pythreads is not None:
# reset to default
Expand Down
22 changes: 14 additions & 8 deletions source/tomopy/util/extern/__init__.py
Expand Up @@ -58,16 +58,21 @@ def c_shared_lib(lib_name, error=True):
The ctypes.util.find_library function preprends "lib" to the name.
"""
load_dll = ctypes.cdll.LoadLibrary
ext = '.so'
if sys.platform == 'darwin':
ext = '.dylib'
if os.name == 'nt':
ext = '.dll'
load_dll = ctypes.windll.LoadLibrary
else:
load_dll = ctypes.cdll.LoadLibrary

# Returns None or a library name
sharedlib = ctypes.util.find_library(lib_name)
if sharedlib and os.path.exists(sharedlib):
return load_dll(sharedlib)

if sharedlib is not None:
try:
# No error if sharedlib is None; error if library name wrong
return load_dll(sharedlib)
except OSError:
pass

explanation = (
'TomoPy links to compiled components which are installed separately'
' and loaded using ctypes.util.find_library().'
Expand All @@ -79,7 +84,8 @@ def c_shared_lib(lib_name, error=True):
warnings.warn(
explanation +
'Some functionality is unavailable because an optional shared'
f' library, {sharedlib}, is missing.', ImportWarning)
f' library, {lib_name}, is missing.', ImportWarning)
return None


def _missing_library(function):
Expand Down
6 changes: 3 additions & 3 deletions source/tomopy/util/mproc.py
Expand Up @@ -87,7 +87,7 @@ def get_rank():
from mpi4py import MPI
comm_w = MPI.COMM_WORLD
return comm_w.Get_rank()
except:
except ModuleNotFoundError:
return 0


Expand All @@ -97,7 +97,7 @@ def get_nproc():
from mpi4py import MPI
comm_w = MPI.COMM_WORLD
return comm_w.Get_size()
except:
except ModuleNotFoundError:
return 1

def barrier():
Expand All @@ -106,7 +106,7 @@ def barrier():
from mpi4py import MPI
comm_w = MPI.COMM_WORLD
comm_w.Barrier()
except:
except ModuleNotFoundError:
pass


Expand Down

0 comments on commit c10a63e

Please sign in to comment.