The write_particles functions begins to gather all npart. Then depending if we will write in parallel (self.pio = 'yes') or not, we have to reduce or not the values of ngas and nstar. This is important to write a consistent header.
def write_particles(self,f):
npart_all = array(mpi.mpi_Allgather(self.npart))
if self.pio == 'yes':
ngas = self.ngas
nstar = self.nstar
else:
ngas = mpi.mpi_reduce(self.ngas)
nstar = mpi.mpi_reduce(self.nstar)
tpl = ((self.tnow,float32),(ngas,int32),(nstar,int32))
io.WriteBlock(f,tpl,byteorder=self.byteorder)
And finally, write the vectors, using the function io.WriteArray()
io.WriteArray(f,self.pos.astype(float32),byteorder=self.byteorder,pio=self.pio,nlocal=npart_all)
io.WriteArray(f,self.vel.astype(float32),byteorder=self.byteorder,pio=self.pio,nlocal=npart_all)
io.WriteArray(f,self.mass.astype(float32),byteorder=self.byteorder,pio=self.pio,nlocal=npart_all)
io.WriteArray(f,self.meta[:self.npart[0]].astype(float32),byteorder=self.byteorder,pio=self.pio,nlocal=npart_all)
See About this document... for information on suggesting changes.