是否有可能该程序中的某些流程比其他流程更快完成?

时间:2016-04-07 19:52:09

标签: python mpi hpc mpi4py multiple-processes

我有一个旨在高度并行化的程序。我怀疑某些处理器比其他处理器更快地完成这个Python脚本,这将解释我在此代码上游观察到的行为。这段代码是否有可能允许某些mpi进程比其他进程更快完成?

dacout = 'output_file.out'
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
nam ='lcoe.coe'
csize = 10000
with open(dacout) as f:
    for i,l in enumerate(f):
        pass
numlines = i
dakchunks = pd.read_csv(dacout,  skiprows=0, chunksize = csize, sep='there_are_no_seperators')
linespassed = 0
vals = {}
for dchunk in dakchunks:
    for line in dchunk.values:
        linespassed += 1
        if linespassed < 49 or linespassed > numlines - 50: continue
        else:
            split_line = ''.join(str(s) for s in line).split()
        if len(split_line)==2:
              if split_line[0] == 'nan' or split_line[0] == '-nan': continue

              if split_line[1] != nam: continue
              if split_line[1] not in vals:
                  try: vals[split_line[1]] = [float(split_line[0])]
                  except NameError: continue
              else:vals[split_line[1]].append(float(split_line[0]))
# Calculate mean and x s.t. Percentile_x(coe_dat)<threshold_coe
self.coe_vals = sorted(vals[nam])
self.mean_coe = np.mean(self.coe_vals)
self.p90 = np.percentile(self.coe_vals, 90)
self.p95 = np.percentile(self.coe_vals, 95)

count_vals = 0.00
for i in self.coe_vals:
    count_vals += 1
    if i > coe_threshold: break
self.perc = 100 * (count_vals/len(self.coe_vals))
if rank==0:
    print>>logf, self.rp, self.rd, self.hh, self.mean_coe
    print self.rp, self.rd, self.hh, self.mean_coe, self.p90, self.perc

1 个答案:

答案 0 :(得分:1)

在您发布的代码中,所有进程都在读取同一个文件并计算相同的内容。但打印结果的唯一过程是过程0.这不是并行计算,这是多次做同样的事情!

某些进程可以在其他进程之前完成此脚本,因为脚本不是以障碍结束 。使用comm.barrier()同步通信器comm的所有进程。只有在必要时才这样做:障碍会伤害表演......