【发布时间】:2021-03-18 14:02:24
【问题描述】:
我有一个 numpy 数组,其中包含各种数据类型(字符串、整数等)
我正在尝试将 numpy 数组分散到 20 个节点:
样本数据从 CSV 文件中提取,然后放入一个名为“data”的 numpy 数组中。
data = numpy.array(sample_data)
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
name = MPI.Get_processor_name()
N = data.size
if rank == 0:
print ("Application Will be Scattering: \n\n", data)
print ("---------------------------------------------------------------------------\n")
sendbuf = numpy.array(data)
ave, res = divmod(sendbuf.size, size)
count = [ave + 1 if p < res else ave for p in range(size)]
count = numpy.array(count)
displ = [sum(count[:p]) for p in range (size)]
displ = numpy.array(displ)
else:
sendbuf = None
count = numpy.zeros(size, dtype=numpy.int)
displ = None
comm.Bcast(count, root=0)
recvbuf = numpy.zeros(count[rank])
comm.Scatterv([sendbuf, count, displ, MPI.DOUBLE], recvbuf, root=0)
print("Process %d At Node %s Recieved: " % (rank, name), recvbuf)
输出总是整数?
Process 17 At Node KPie01 Received: [0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
1.01855798e-312 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000]
【问题讨论】:
标签: python-3.x mpi4py