Commit fee7b4d2 authored by Martin Reinecke's avatar Martin Reinecke


parent 1be2685f
......@@ -348,6 +348,12 @@ def np_allreduce_min(arr):
return res
def np_allreduce_max(arr):
res = np.empty_like(arr)
_comm.Allreduce(arr, res, MPI.MAX)
return res
def distaxis(arr):
return arr._distaxis
......@@ -75,6 +75,10 @@ def np_allreduce_min(arr):
return arr
def np_allreduce_max(arr):
return arr
def distaxis(arr):
return -1
......@@ -33,6 +33,7 @@ __all__ = ["ntask", "rank", "master", "local_shape", "data_object", "full",
"empty", "zeros", "ones", "empty_like", "vdot", "exp",
"log", "tanh", "sqrt", "from_object", "from_random",
"local_data", "ibegin", "ibegin_from_shape", "np_allreduce_sum",
"np_allreduce_min", "np_allreduce_max",
"distaxis", "from_local_data", "from_global_data", "to_global_data",
"redistribute", "default_distaxis", "is_numpy",
"lock", "locked"]
......@@ -41,9 +41,9 @@ class DOFDistributor(LinearOperator):
dofdex: Field of integers
An integer Field on exactly one Space establishing the association
between the locations in the operators target and the underlying
between the locations in the operator's target and the underlying
degrees of freedom in its domain.
It has to start at 0 and it increases monotonicly, no empty bins are
It has to start at 0 and it increases monotonically, no empty bins are
target: Domain, tuple of Domain, or DomainTuple, optional
The target of the operator. If not specified, the domain of the dofdex
......@@ -70,12 +70,17 @@ class DOFDistributor(LinearOperator):
if partner != dofdex.domain[0]:
raise ValueError("incorrect dofdex domain")
nbin = dofdex.max()
ldat = dofdex.local_data
if ldat.size==0: # can happen for weird configurations
nbin = 0
nbin = ldat.max()
nbin = dobj.np_allreduce_max(np.array(nbin))[()] + 1
if partner.scalar_dvol is not None:
wgt = np.bincount(dofdex.local_data.ravel(), minlength=nbin)
wgt = wgt*partner.scalar_dvol
dvol = dobj.local_data(partner.dvol)
dvol = Field.from_global_data(partner, partner.dvol).local_data
wgt = np.bincount(dofdex.local_data.ravel(),
minlength=nbin, weights=dvol)
# The explicit conversion to float64 is necessary because bincount
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment