Skip to main content

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, BLACSGrid
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

grid = BLACSGrid(sl, name="main")
b = np.arange(n*n, dtype=dtype).reshape((n,n))
dist_b = NPScal(gl_array=b, grid=grid, lib=sl)

b_matmul = b @ b
dist_b_matmul = dist_b @ dist_b

Metadata

Release files for scalapack4py 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scalapack4py 1.0.0
File Size Uploaded
scalapack4py-1.0.0.tar.gz 83.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for scalapack4py 1.0.0
File Interpreter ABI Platform
scalapack4py-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 174.3 kB

Release files / scalapack4py-1.0.0.tar.gz

Download URL scalapack4py-1.0.0.tar.gz
Size 83.1 kB
Tags Source
SHA-256 checksum
How to use checksums
332839db7b694ee61baee82dec78c3e50d2c142de3983d91cc37288e41b37c60
BLAKE2b-256 checksum
How to use checksums
ff1cd47bf9835151b5b7f306dac6dfe50ceaa0ae1293d814a0c0e18199ecbe07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / scalapack4py-1.0.0-py3-none-any.whl

Download URL scalapack4py-1.0.0-py3-none-any.whl
Size 91.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac4b24f6bbdf7fbae6d670fd92ef28530591f933498184f66b811b5dfc6749d3
BLAKE2b-256 checksum
How to use checksums
5b0328d688b86ed5e46524c891c858c1608804c099fe66967463a7555e0e5c61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page