Hi, everyone! I updated my fenicsx
on Ubuntu 24.04 LTS
from v0.7.0
to v0.8.0
. And when I run the following paralell test case:
import numpy as np
from scipy.spatial.distance import cdist
from multiprocessing import Pool, Manager
import dolfinx
from mpi4py import MPI
def calculate_distance_batch(args):
"""
Compute euclidean distance of a batch of points.
Args:
args (tuple): Tuple of batch points, all points, and a shared list to store results.
Returns:
None
"""
try:
batch_points, all_points, shared_list = args
distances = cdist(batch_points, all_points, metric='euclidean')
shared_list.append(distances.tolist())
except Exception as e:
print(f"Error in calculate_distance_batch: {e}")
def calculate_distances(radius, points, batch_size, num_processes) -> tuple:
"""
Compute euclidean distance of all points using multiprocessing.
Args:
radius (float): filter radius
points (Sequence): coordinates of points
batch_size (int): number of batch sizes
num_processes (int): number of processes
Returns:
(ndarray, ndarray), shape1=(elem_num, elem_num), shape2=(elem_num, )
"""
num_points = len(points)
num_batches = int(np.ceil(num_points / batch_size))
# Create a list of process pools
with Pool(processes=num_processes) as pool, Manager() as manager:
shared_list = manager.list()
# Batch calculation of Euler distance
pool.map(calculate_distance_batch,
[(points[i * batch_size:min((i + 1) * batch_size, num_points)], points, shared_list) for i in
range(num_batches)])
# Merge result matrix
distance_matrix = np.concatenate(shared_list)
distance_matrix = np.maximum(radius - distance_matrix, 0)
distance_sum = distance_matrix.sum(1)
return distance_matrix, distance_sum
# the test case
mesh = dolfinx.mesh.create_unit_cube(MPI.COMM_WORLD, 2,2,2, cell_type=dolfinx.mesh.CellType.hexahedron)
mid_points = dolfinx.mesh.compute_midpoints(mesh=mesh, dim=3, entities=np.arange(8, dtype=np.int32))
H, H_sum =calculate_distances(radius=0.75, points=mid_points, batch_size=int( mid_points.shape[0] / 2),
num_processes=2)
it output the errors:
[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 13 Broken Pipe: Likely while reading or writing to a socket
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see https://petsc.org/release/faq/#valgrind and https://petsc.org/release/faq/
[0]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run
[0]PETSC ERROR: to get more information on the crash.
However, the same case runs well on fenicsx0.7.0
without the above errors.