Skip to main content

Python wrapper for dynamically loaded ScaLAPACK and BLACS libraries

Project description

Dynamic ScaLAPACK wrapper for Python

Python wrapper for dynamically loaded ScaLAPACK and BLACS libraries

from scalapack4py import ScaLAPACK4py, parprint, ordprint
from ctypes import cast, py_object, CDLL, RTLD_GLOBAL

scalapack_lib = CDLL('libscalapack-openmpi.so.2.0', mode=RTLD_GLOBAL)
sl = ScaLAPACK4py(scalapack_lib)


descr = sl.wrap_blacs_desc(descr)
locshape = (descr.locrow, descr.loccol)
data = np.ctypeslib.as_array(data, shape=locshape)
sl.scatter(data_src, descr, data)

Or

# run as:  mpiexec -n 2 python3 -u test_scatter_complex.py
import numpy as np, os
from mpi4py import MPI
from scalapack4py import ScaLAPACK4py
from ctypes import CDLL, RTLD_GLOBAL, POINTER, c_int, c_double

sl = ScaLAPACK4py(CDLL('libscalapack-openmpi.so.2.0', mode=RTLD_GLOBAL))

n = 5
dtype=np.complex128
a = np.arange(n*n, dtype=dtype).reshape((n,n), order='F') * (MPI.COMM_WORLD.rank+1) if MPI.COMM_WORLD.rank==0 else None

print (a)

MP, NP = 2,1

ctx = sl.make_blacs_context(sl.get_default_system_context(), MP, NP)
descr = sl.make_blacs_desc(ctx, n, n)
print("descr", descr, descr.locrow, descr.loccol)

b = np.zeros((descr.locrow, descr.loccol), dtype=dtype)

sl.scatter_numpy(a, POINTER(c_int)(descr), b.ctypes.data_as(POINTER(c_double)), b.dtype)
print (b)


c = sl.gather_numpy(POINTER(c_int)(descr), b, (n, n))
print (c)

A streamlined interface to scalapack4py is provided by NPScal, which replicates many of the arithmatic operators implemented for ndarrays

from numpy.random import RandomState
from scalapack4py.scalapack4py import ScaLAPACK4py
from scalapack4py.npscal import NPScal
from scalapack4py.npscal import CTXT_Register, DESCR_Register, BLACSDESCRManager, BLACSContextManager
from scalapack4py.npscal.index_utils.npscal_select import diag
from scalapack4py.npscal.utils import find_squarest_grid
from mpi4py import MPI

from ctypes import RTLD_GLOBAL, POINTER, c_int, c_double, CDLL
import numpy as np
import os

sl = ScaLAPACK4py(CDLL(scalapack_libpath, mode=RTLD_GLOBAL))

n = 16
dtype=np.float64

b = np.arange(n*n, dtype=dtype).reshape((n,n))
dist_b = NPScal(gl_array=b, ctxt_tag="main", descr_tag="default", lib=sl)

b_matmul = b @ b
dist_b_matmul = dist_b @ dist_b

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scalapack4py-0.2.0.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scalapack4py-0.2.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file scalapack4py-0.2.0.tar.gz.

File metadata

  • Download URL: scalapack4py-0.2.0.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for scalapack4py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 aa1af82ed206759e75f2fb61b9ebbf25fec694b33e4bcda5a85c020d3b825816
MD5 4bf4d5c0be978378c4b966599ae3d122
BLAKE2b-256 93a800871a7638523329ba4333a17a60e2f10dc006c54c8dda5a09542cf50f3c

See more details on using hashes here.

File details

Details for the file scalapack4py-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: scalapack4py-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for scalapack4py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f365bdccaaeea2c6cb2be0343ed3ed8c1347467b8460ca081ced05f5a89f7f59
MD5 53e8f7c781fb56aaa16975e2571d0d91
BLAKE2b-256 032d8c124b68e3303f933cf2db6ed965e3f467183a983631d47e92f77fe268b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page