def main(): comm = MPI.COMM_WORLD id= comm.Get_rank() wsize= comm.Get_size() tstart = MPI.Wtime() fsky = open("skymap.png","r") reader = Reader(fsky) skypixelwidth, skypixelheight, skypixels, metadata=reader.read_flat() pixelwidth = int(argv[1]) pixelheight = int(argv[2]) tskymapstart = MPI.Wtime() telepixels = np.zeros((pixelwidth*pixelheight*3),dtype=np.uint8) colorpixels = np.zeros((pixelwidth*pixelheight),dtype=np.uint8) skystartall = np.zeros((pixelwidth*pixelheight),dtype=np.uint32) telestartall = np.zeros((pixelwidth*pixelheight),dtype=np.uint32) colorall = np.zeros((pixelwidth*pixelheight),dtype=np.uint8) totnstepsall=np.zeros((wsize),dtype=np.uint32) tskymapend = MPI.Wtime() tskymap = tskymapend-tskymapstart tmin = 1.e6 tpercparmin=1.e6 hinit=1.e-1 #h=1.e-4 Router = 1000. Rplane = 700. Rs = 2. every = 1 deltalamb = 1.e-1 imagewidth = 50; imageheight = 50; tiny = 1.e-30 epsilon=1.e-8 eccentricity = 0.2 Rfac = 1.+1.e-10 heps = 1.e-14 semilatusr = 10.0 tstartpp=MPI.Wtime() #percent parallelized numperprocess = pixelheight*pixelwidth/wsize skystart=np.zeros((numperprocess),dtype=np.int32) telestart=np.zeros((numperprocess),dtype=np.int32) color = np.zeros((numperprocess),dtype=np.int8) totnsteps=np.zeros((numperprocess),dtype=np.int32) trk4all=np.zeros((numperprocess),dtype=np.float) ttelestop = MPI.Wtime() ttele = ttelestop-tstartpp trk4=float("inf") for index in range(numperprocess): ypix = int((id*numperprocess+index)/pixelwidth) xpix = (id*numperprocess+index)%pixelwidth tstartrk4=MPI.Wtime() totnsteps[index],skystart[index],telestart[index],color[index]=integrateNullGeodesic(xpix, ypix, pixelheight,pixelwidth, skypixelheight,skypixelwidth,imagewidth,imageheight,Rs,Router,Rplane,eccentricity, semilatusr, epsilon, tiny, hinit,Rfac,heps) tendrk4=MPI.Wtime() trk4=min(trk4,(tendrk4-tstartrk4)/float(totnsteps[index])) totnstepsmax=max(totnsteps) tstoppp = MPI.Wtime() tpercpar=tstoppp-tstartpp comm.Barrier() if id==0: totnstepsmaxall=0 else: totnstepsmaxall=None comm.Barrier() totnstepsmaxall=comm.reduce(totnstepsmax,op=MPI.MAX,root=0) tskymapall = comm.reduce(tskymap, op=MPI.MAX, root=0) tteleall = comm.reduce(ttele,op=MPI.MAX,root=0) comm.Gatherv(skystart,skystartall,root=0) comm.Gatherv(telestart, telestartall, root=0) comm.Gatherv(color,colorall, root=0) trk4min=comm.reduce(trk4,op=MPI.MIN,root=0) comm.Barrier() tend = MPI.Wtime() tall = tend-tstart if id==0: tindexstart = MPI.Wtime() for index in range(pixelheight*pixelwidth): if(colorall[index]==1): telepixels[telestartall[index]:telestartall[index]+3]=skypixels[skystartall[index]:skystartall[index]+3] else: telepixels[telestartall[index]]=255 #leave other two indices zero,red tindexend = MPI.Wtime() tindex = tindexend-tindexstart if id==0: twritestart = MPI.Wtime() ftele = open('teleview_{pw}_{ph}_{ws}.png'.format(pw=pixelwidth,ph=pixelheight,ws=wsize), "w") telewrite=Writer(width=pixelwidth,height=pixelheight,greyscale=False,alpha=False) telewrite.write_array(ftele,telepixels) ftele.close() twriteend=MPI.Wtime() twrite = twriteend-twritestart fsky.close() comm.Barrier() tmax = comm.reduce(tall,MPI.MAX,root=0) tpercparmin = comm.reduce(tpercpar/tall,op=MPI.MIN,root=0) comm.Barrier() if (id==0): # print("Telescope dimensions in M", 2.*imagewidth, 2.*imageheight) # print("Telescope resolution", pixelwidth, pixelheight) # print("Skymap resolution", skypixelwidth, skypixelheight) # print("Schwarzschild radius in M", 2.*Rs) # print("Outer radius in M", 2.*Router) # print("Telescope radius in M", 2.*Rplane) # print("Number of processes = ",wsize) # print("Maximum number of integration steps taken is",totnstepsmaxall) # print("The time for a single step of the RK4 is",trk4min) # print("Total runtime = ",tmax) # print("Fraction parallel = ", tpercparmin) print pixelwidth,pixelheight,wsize,totnstepsmaxall,trk4min,tmax,tpercparmin, tindex, twrite, tskymapall, tteleall MPI.Finalize()