[gpaw-users] broadcasting H_skMM and S_skMM yields Typeerror
Alex Eftimiades
alexeftimiades at gmail.com
Sun Nov 20 02:39:22 CET 2011
Sorry, there were a few typos. This will work--again for future reference:
from gpaw.mpi import world
#code goes here
H_scatter, S_scatter = get_lcao_hamiltonian(scatter_region.calc)
if world.rank == 0:
h=len(shape(H_scatter))
s=len(shape(S_scatter))
else:
h=empty(array([]))
s=empty(array([]))
world.barrier()
world.broadcast(h,0)
world.broadcast(s,0)
if world.rank == 0:
h=shape(H_scatter)
s=shape(S_scatter)
else:
h=empty(array([h]))
s=empty(array([s]))
world.barrier()
world.broadcast(h,0)
world.broadcast(s,0)
if rank != 0:
H_scatter=empty(h)
S_scatter=empty(s)
world.barrier()
world.broadcast(H,0)
world.broadcast(S,0)
On Fri, Nov 18, 2011 at 5:24 PM, Alex Eftimiades
<alexeftimiades at gmail.com>wrote:
> Thank you. I did not know I had to cast them into the correct shape.
>
> For future reference the following procedure seems to work as a way to
> broadcast ndarrays of arbitrary shapes and sizes:
>
>
> ibz2d_k, weight2d_k, H, S = get_lead_lcao_hamiltonian(lead_copy.calc,
> direction='z')
>
> if rank == 0:
> h=len(H.shape())
> s=len(S.shape())
> else:
> h=empty(array([]))
> s=empty(array([]))
> world.barrier()
> world.broadcast(h,0)
> world.broadcast(s,0)
> if rank == 0:
> h=H.shape()
> s=H.shape()
> else:
> h=empty(array([h]))
> s=empty(array([s]))
> world.barrier()
> world.broadcast(h,0)
> world.broadcast(s,0)
> if rank != 0:
> H=empty(h)
> S=empty(s)
> world.barrier()
> world.broadcast(H,0)
> world.broadcast(S,0)
>
>
>
> On Fri, Nov 18, 2011 at 1:05 PM, Ask Hjorth Larsen <askhl at fysik.dtu.dk>wrote:
>
>> Hi
>>
>>
>> On Fri, 18 Nov 2011, Nichols A. Romero wrote:
>>
>> The problem is that this broadcast method only works on NumPy arrays and
>>> H is not a NumPy array.
>>>
>>> Nichols A. Romero, Ph.D.
>>> Argonne Leadership Computing Facility
>>> Argonne National Laboratory
>>> Building 240 Room 2-127
>>> 9700 South Cass Avenue
>>> Argonne, IL 60490
>>> (630) 252-3441
>>>
>>>
>>> ----- Original Message -----
>>> From: "Alex Eftimiades" <alexeftimiades at gmail.com>
>>> To: gpaw-users at listserv.fysik.dtu.**dk<gpaw-users at listserv.fysik.dtu.dk>
>>> Sent: Thursday, November 17, 2011 11:12:59 PM
>>> Subject: [gpaw-users] broadcasting H_skMM and S_skMM yields Typeerror
>>>
>>>
>>> When I try to broadcast
>>> ibz2d_k, weight2d_k, H, S = get_lead_lcao_hamiltonian(**lead_copy.calc,
>>> direction='z')
>>> world.broadcast(H,0)
>>>
>>> I get:
>>> TypeError: Not a proper NumPy array for MPI communication.
>>>
>>> I have checked all sorts of combinations of barriers, and I have tried
>>> declaring the variables H and S at the top of the code, I have tried
>>> checking that H and S are None for all other ranks (they are) I have tried
>>> printing H and S for rank 0 (typical complex ndarray), I have tried
>>> explicitly casting H and S into arrays both before and after setting them
>>> equal to H_skMM and S_kMM respctively, and I have tried just broadcasting
>>> the real parts of H and S.
>>>
>>> Please tell me what I am doing wrong here.
>>> Alex
>>>
>>
>> Actually the get_lcao_hamiltonian function creates H and S_skMM as
>> contiguous numpy arrays (although they are normally not stored as such, and
>> performance-wise this is subject to some performance issues if the arrays
>> are very large).
>>
>> The problem here is that H_skMM is None on all ranks except the global
>> master. You must create an empty array of the correct shape on all CPUs
>> that participate in the broadcast - if you want to actually broadcast it
>> (this is a bit annoying, but it's consistent with how MPI works).
>>
>> Regards
>> Ask
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserv.fysik.dtu.dk/pipermail/gpaw-users/attachments/20111119/4595be1f/attachment.html
More information about the gpaw-users
mailing list